python/samba/tests: Fix auth_log messaging problems in py3
authorNoel Power <noel.power@suse.com>
Fri, 16 Nov 2018 12:46:16 +0000 (12:46 +0000)
committerNoel Power <npower@samba.org>
Mon, 10 Dec 2018 09:38:22 +0000 (10:38 +0100)
Some tests (especially samba.tests.auth_log_netlogon_bad_creds) are
failing due to not receiving expected messages. There seems to be
some timing issue or race around the messaging bus being set up and
getting the expected events resulting from the failed netlogon.

Specifically the the order of destruction of the messaging.Messaging()
c-py objects is different under python2. Under python2 all of the
messaging.Messaging() objects are destructed *after* all the tests
are run. Note: each instance of the TestCase has it's own Messaging()
instance which is created by TestCaseXYZ.setUp, so it appears the unittest
destroys the test instances when all the tests have run whereas in
python3 we see each messaging.Messaging() instance destroyed after
each test runs.
Ok, what difference does that make ? well it seems in python3 because
each Messaging() instance is destructed after a test runs that the
associated messaging_dgm_destroy() also runs, this destroys the
global_dgm_context context which means when the next test runs the whole
messaging infrastructure needs to be built again when the next Messaging()
object is created. On the server-side this seems to result in attempts
to send messages to the listener failing first with

get_event_server: Failed to find 'auth_event' registered on the message bus to send JSON audit events to: NT_STATUS_CONNECTION_REFUSED

and subsequently with

get_event_server: Failed to find 'auth_event' registered on the message bus to send JSON audit events to: NT_STATUS_UNSUCCESSFUL

client doesn't get any more messages, test fails :-(

So, what's the difference in python2, well because the destructors for the
(4 in the case of netlogon_bad_creds) instances of Messagaging() don't run
till the end of the tests this doesn't happen and the global_dgm_context
never gets destroyed untill all the tests complete. There is some race
condition at play here, a simple sleep at the start of a failing test
fixes the problem. But... ok that isn't a possible solution here, instead
I have adjusted the base auth tests to store the Messaging() objects in a
global list forcing them to remain in scope until the tests are complete.
This ensure the behaviour is consistent across python2 & python3.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/auth_log_base.py

index 700871f9df5b65cea427bffb6502cc9f7098794a..374ee4586394342332c6b911eb4be6bc00d8e4db 100644 (file)
@@ -27,6 +27,7 @@ import json
 import os
 import re
 
+msg_ctxs = []
 
 class AuthLogTestBase(samba.tests.TestCase):
 
@@ -34,6 +35,8 @@ class AuthLogTestBase(samba.tests.TestCase):
         super(AuthLogTestBase, self).setUp()
         lp_ctx = self.get_loadparm()
         self.msg_ctx = Messaging((1,), lp_ctx=lp_ctx)
+        global msg_ctxs
+        msg_ctxs.append(self.msg_ctx)
         self.msg_ctx.irpc_add_name(AUTH_EVENT_NAME)
 
         def messageHandler(context, msgType, src, message):