From: Tim Beale Date: Mon, 18 Sep 2017 00:39:21 +0000 (+1200) Subject: selftest: replica_sync did not fully cleanup if test failed X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=1b395f488a94f2e2811622b61a8c750374d640ed;p=metze%2Fsamba%2Fwip.git selftest: replica_sync did not fully cleanup if test failed Normally the replica_sync tests do the cleanup at the end of the test case, rather than in the tearDown(). However, if the tests don't run to completion (because they fail), then the objects may not get cleaned up properly, which causes the tests to fail on the 2nd test-env. The problem is the object deletion only occurs on DC2 and it relies on replication to propagate the deletion to DC1. Presumably this propagation could be missed because the tests are repeatedly turning off inbound replication on both DCs. This patch changes the tearDown() so it tries to delete the objects off both DCs, which appears to fix the problem. Signed-off-by: Tim Beale Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/source4/torture/drs/python/replica_sync.py b/source4/torture/drs/python/replica_sync.py index dd9f2763cfbf..0886637c71d3 100644 --- a/source4/torture/drs/python/replica_sync.py +++ b/source4/torture/drs/python/replica_sync.py @@ -45,23 +45,27 @@ class DrsReplicaSyncTestCase(drs_base.DrsBaseTestCase): self.ou2 = None def tearDown(self): + self._cleanup_object(self.ou1) + self._cleanup_object(self.ou2) + # re-enable replication self._enable_inbound_repl(self.dnsname_dc1) self._enable_inbound_repl(self.dnsname_dc2) - if self.ldb_dc2 is not None: - if self.ou1 is not None: - try: - self.ldb_dc2.delete('' % self.ou1, ["tree_delete:1"]) - except LdbError, (num, _): - self.assertEquals(num, ERR_NO_SUCH_OBJECT) - if self.ou2 is not None: - try: - self.ldb_dc2.delete('' % self.ou2, ["tree_delete:1"]) - except LdbError, (num, _): - self.assertEquals(num, ERR_NO_SUCH_OBJECT) super(DrsReplicaSyncTestCase, self).tearDown() + def _cleanup_object(self, guid): + """Cleans up a test object, if it still exists""" + if guid is not None: + try: + self.ldb_dc2.delete('' % guid, ["tree_delete:1"]) + except LdbError, (num, _): + self.assertEquals(num, ERR_NO_SUCH_OBJECT) + try: + self.ldb_dc1.delete('' % guid, ["tree_delete:1"]) + except LdbError, (num, _): + self.assertEquals(num, ERR_NO_SUCH_OBJECT) + def test_ReplEnabled(self): """Tests we can replicate when replication is enabled""" self._enable_inbound_repl(self.dnsname_dc1)