selftest: Use a unique(ish) OU for every run of getnc_unpriv
authorTim Beale <timbeale@catalyst.net.nz>
Thu, 17 Aug 2017 00:30:30 +0000 (12:30 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 29 Aug 2017 05:23:28 +0000 (07:23 +0200)
An intermittent problem I noticed with tests in the past is that the
setup can fail to create the base OU because it already exists.
I believe this is because the previous testenv DC has replicated out the
test object, but not its deletion at the point that the next testenv DC
starts running the test.

This only seemed to happen very occassionally (I haven't seen it
happen with getnc_unpriv yet, but I also haven't run it through the
autobuild yet).

Using same randomness in the test OU should help avoid this sort of
problem, and it matches what some other replication tests do.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/torture/drs/python/getnc_unpriv.py

index 85fa88da837c152d252353bea247186353e2f2e9..8b242b18c9c78c71b2f018950259b694c708ee83 100644 (file)
@@ -40,6 +40,7 @@ from samba import werror, WERRORError
 from samba import sd_utils
 import ldb
 from ldb import SCOPE_BASE
+import random
 
 from samba.dcerpc import drsuapi, security
 from samba.credentials import DONT_USE_KERBEROS
@@ -51,13 +52,19 @@ class DrsReplicaSyncUnprivTestCase(drs_base.DrsBaseTestCase):
         super(DrsReplicaSyncUnprivTestCase, self).setUp()
         self.get_changes_user = "get-changes-user"
         self.base_dn = self.ldb_dc1.get_default_basedn()
-        self.ou = "OU=test_getncchanges,%s" % self.base_dn
         self.user_pass = samba.generate_random_password(12, 16)
+
+        # add some randomness to the test OU. (Deletion of the last test's
+        # objects can be slow to replicate out. So the OU created by a previous
+        # testenv may still exist at this point).
+        rand = random.randint(1, 10000000)
+        test_ou = "OU=test_getnc_unpriv%d" %rand
+        self.ou = "%s,%s" %(test_ou, self.base_dn)
         self.ldb_dc1.add({
             "dn": self.ou,
             "objectclass": "organizationalUnit"})
         self.ldb_dc1.newuser(self.get_changes_user, self.user_pass,
-                             userou="OU=test_getncchanges")
+                             userou=test_ou)
         (self.drs, self.drs_handle) = self._ds_bind(self.dnsname_dc1)
 
         self.sd_utils = sd_utils.SDUtils(self.ldb_dc1)