From 8fe9992cffed82e9e26ebe8185f372c8a1dfb3a9 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Mon, 22 Jun 2015 16:38:29 +1200 Subject: KCC: load samdb before calling kcc.run() kcc.run() is a mega-function that does nearly everything, including loading the database. The --list-valid-dsas and --test-all-reps-from tasks also want to load the database, but not do all that other run() stuff, so it makes sense to pull it out. When the samdb has not been loaded, run() will still load it -- this avoids having to change all the tests. Signed-off-by: Douglas Bagnall Reviewed-by: Garming Sam Reviewed-by: Andrew Bartlett --- python/samba/kcc/__init__.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/samba/kcc/__init__.py b/python/samba/kcc/__init__.py index 458af39b373..d9c47c61720 100644 --- a/python/samba/kcc/__init__.py +++ b/python/samba/kcc/__init__.py @@ -2361,12 +2361,14 @@ class KCC(object): :param force: a boolean indicating whether to overwrite. """ - if self.samdb is not None and not force: - return - - self.samdb = SamDB(url=dburl, - session_info=system_session(), - credentials=creds, lp=lp) + if force or self.samdb is None: + try: + self.samdb = SamDB(url=dburl, + session_info=system_session(), + credentials=creds, lp=lp) + except ldb.LdbError, (num, msg): + raise KCCError("Unable to open sam database %s : %s" % + (dburl, msg)) def plot_all_connections(self, basename, verify_properties=()): """Helper function to plot and verify NTDSConnections @@ -2420,12 +2422,9 @@ class KCC(object): determine link availability (boolean, default False) :return: 1 on error, 0 otherwise """ - try: + if self.samdb is None: + DEBUG_FN("samdb is None; let's load it from %s" % (dburl,)) self.load_samdb(dburl, lp, creds, force=False) - except ldb.LdbError, (num, msg): - logger.error("Unable to open sam database %s : %s" % - (dburl, msg)) - return 1 if forced_local_dsa: self.samdb.set_ntds_settings_dn("CN=NTDS Settings,%s" % -- cgit v1.2.3