import samba
import os
from tempfile import mkdtemp
+import time
import samba.tests
from samba.kcc import ldif_import_export
from samba.credentials import Credentials
from samba.samdb import SamDB
+unix_now = int(time.time())
+
MULTISITE_LDIF = os.path.join(os.environ['SRCDIR_ABS'],
"testdata/ldif-utils-test-multisite.ldif")
def samdb_to_ldif_file(self):
#samdb_to_ldif_file(samdb, dburl, lp, creds, ldif_file):
pass
+
+
+class KCCMultisiteLdifTests(samba.tests.TestCase):
+ def setUp(self):
+ super(KCCMultisiteLdifTests, self).setUp()
+ self.lp = LoadParm()
+ self.creds = Credentials()
+ self.creds.guess(self.lp)
+ self.tmpdir = mkdtemp()
+ self.tmpdb = os.path.join(self.tmpdir, 'tmpdb')
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def _get_kcc(self, name, readonly=False, verify=False, dot_file_dir=None):
+ # Note that setting read-only to False won't affect the ldif,
+ # only the temporary database that is created from it.
+ my_kcc = kcc.KCC(unix_now, readonly=readonly, verify=verify,
+ dot_file_dir=dot_file_dir)
+ tmpdb = os.path.join(self.tmpdir, 'tmpdb')
+ my_kcc.import_ldif(tmpdb, self.lp, self.creds, MULTISITE_LDIF)
+ return my_kcc
+
+ def test_list_dsas(self):
+ my_kcc = _get_kcc('test-list')
+ dsas = set(my_kcc.list_dsas())
+ expected_dsas = set(x[0] for x in MULTISITE_LDIF_DSAS)
+ self.assertEqual(dsas, expected_dsas)
+
+ env = os.environ['TEST_ENV']
+ for expected_dsa in ENV_DSAS[env]:
+ self.assertIn(expected_dsa, dsas)
+
+ def test_verify(self):
+ """Check that the KCC generates graphs that pass its own verify
+ option.
+ """
+ my_kcc = _get_kcc('test-list')
+
+ self.kcc = kcc.KCC(unix_now, readonly=False, ver)
+ self.kcc.import_ldif(self.tmpdb, self.lp, self.creds, MULTISITE_LDIF)
+
+
+ if opts.tmpdb is None or opts.tmpdb.startswith('ldap'):
+
+ if opts.tmpdb is None or opts.tmpdb.startswith('ldap'):
+
+ my_kcc = kcc.KCC(unix_now, readonly=True, verify=True,
+ debug=False, dot_file_dir=None)
+
+ my_kcc.run("ldap://%s" % os.environ["SERVER"],
+ self.lp, self.creds,
+ attempt_live_connections=False)