selftest: replica_sync did not fully cleanup if test failed
authorTim Beale <timbeale@catalyst.net.nz>
Mon, 18 Sep 2017 00:39:21 +0000 (12:39 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 26 Sep 2017 03:33:17 +0000 (05:33 +0200)
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 <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source4/torture/drs/python/replica_sync.py

index dd9f2763cfbff52440b1ad231723d5f067d13df2..0886637c71d30dc8a4473c377039b13b8b4d4569 100644 (file)
@@ -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('<GUID=%s>' % 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('<GUID=%s>' % 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=%s>' % guid, ["tree_delete:1"])
+            except LdbError, (num, _):
+                self.assertEquals(num, ERR_NO_SUCH_OBJECT)
+            try:
+                self.ldb_dc1.delete('<GUID=%s>' % 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)