mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
tests: Move repeated code into a helper function
Several tests hang all the objects they create off a unique OU. Having a common OU makes cleanup easier, and having a unique OU (i.e. adding some randomness) helps protect against one-off test failures (Replication between testenvs is happening in the background. Occasionally, when a test finishes on one testenv and moves onto the next testenv, that testenv may have received the replicated test objects from the first testenv, but has not received their deletion yet). Rather than copy-n-pasting this code yet again, split it out into a helper function. Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
This commit is contained in:
parent
b07b4e459e
commit
597428943b
@ -36,6 +36,7 @@ import re
|
||||
import samba.auth
|
||||
import samba.dcerpc.base
|
||||
from samba.compat import PY3, text_type
|
||||
from random import randint
|
||||
if not PY3:
|
||||
# Py2 only
|
||||
from samba.samdb import SamDB
|
||||
@ -475,3 +476,15 @@ def delete_force(samdb, dn, **kwargs):
|
||||
except ldb.LdbError as error:
|
||||
(num, errstr) = error.args
|
||||
assert num == ldb.ERR_NO_SUCH_OBJECT, "ldb.delete() failed: %s" % errstr
|
||||
|
||||
def create_test_ou(samdb, name):
|
||||
"""Creates a unique OU for the test"""
|
||||
|
||||
# Add some randomness to the test OU. Replication between the testenvs is
|
||||
# constantly happening in the background. 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 the point that tests start on another testenv.
|
||||
rand = randint(1, 10000000)
|
||||
dn = "OU=%s%d,%s" %(name, rand, samdb.get_default_basedn())
|
||||
samdb.add({ "dn": dn, "objectclass": "organizationalUnit"})
|
||||
return dn
|
||||
|
@ -46,15 +46,8 @@ class DrsReplicaSyncIntegrityTestCase(drs_base.DrsBaseTestCase):
|
||||
# the vampire_dc), so we point this test directly at that DC
|
||||
self.set_test_ldb_dc(self.ldb_dc2)
|
||||
|
||||
# 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)
|
||||
self.ou = samba.tests.create_test_ou(self.test_ldb_dc, "getncchanges")
|
||||
self.base_dn = self.test_ldb_dc.get_default_basedn()
|
||||
self.ou = "OU=getncchanges%d_test,%s" %(rand, self.base_dn)
|
||||
self.test_ldb_dc.add({
|
||||
"dn": self.ou,
|
||||
"objectclass": "organizationalUnit"})
|
||||
|
||||
self.default_conn = DcConnection(self, self.ldb_dc2, self.dnsname_dc2)
|
||||
self.set_dc_connection(self.default_conn)
|
||||
|
@ -46,15 +46,8 @@ class DrsReplicaLinkConflictTestCase(drs_base.DrsBaseTestCase):
|
||||
def setUp(self):
|
||||
super(DrsReplicaLinkConflictTestCase, self).setUp()
|
||||
|
||||
# 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)
|
||||
self.ou = samba.tests.create_test_ou(self.ldb_dc1, "test_link_conflict")
|
||||
self.base_dn = self.ldb_dc1.get_default_basedn()
|
||||
self.ou = "OU=test_link_conflict%d,%s" %(rand, self.base_dn)
|
||||
self.ldb_dc1.add({
|
||||
"dn": self.ou,
|
||||
"objectclass": "organizationalUnit"})
|
||||
|
||||
(self.drs, self.drs_handle) = self._ds_bind(self.dnsname_dc1)
|
||||
(self.drs2, self.drs2_handle) = self._ds_bind(self.dnsname_dc2)
|
||||
|
@ -92,17 +92,11 @@ class DrsRodcTestCase(drs_base.DrsBaseTestCase):
|
||||
super(DrsRodcTestCase, self).setUp()
|
||||
self.base_dn = self.ldb_dc1.get_default_basedn()
|
||||
|
||||
rand = random.randint(1, 10000000)
|
||||
|
||||
self.ou = "OU=test_drs_rodc%s,%s" % (rand, self.base_dn)
|
||||
self.ldb_dc1.add({
|
||||
"dn": self.ou,
|
||||
"objectclass": "organizationalUnit"
|
||||
})
|
||||
self.ou = samba.tests.create_test_ou(self.ldb_dc1, "test_drs_rodc")
|
||||
self.allowed_group = "CN=Allowed RODC Password Replication Group,CN=Users,%s" % self.base_dn
|
||||
|
||||
self.site = self.ldb_dc1.server_site_name()
|
||||
self.rodc_name = "TESTRODCDRS%s" % rand
|
||||
self.rodc_name = "TESTRODCDRS%s" % random.randint(1, 10000000)
|
||||
self.rodc_pass = "password12#"
|
||||
self.computer_dn = "CN=%s,OU=Domain Controllers,%s" % (self.rodc_name, self.base_dn)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user