python/samba/tests: make sure samba.tests can be imported without SamDB
authorAlexander Bokovoy <ab@samba.org>
Sat, 21 Jul 2018 09:05:15 +0000 (12:05 +0300)
committerGünther Deschner <gd@samba.org>
Mon, 23 Jul 2018 17:36:56 +0000 (19:36 +0200)
We are using samba.tests Python module __init__.py file as a catch-all
for all types of helpers. Some of these helpers are only usable with
Samba AD DC targets.

When SamDB is not available in a non-Samba AD DC target, provide a
dummy replacement that simply returns None. This allows to complete
initialization for non-Samba AD DC target tests which do not use
connect_samdb() helper.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13542

Signed-off-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Mon Jul 23 19:36:56 CEST 2018 on sn-devel-144

python/samba/tests/__init__.py

index 1d50710209523337abd1836618eea182b6c0ee0a..dcee691e6e91f90441cdd39f8d4f0b2e55af68f9 100644 (file)
@@ -38,7 +38,12 @@ import samba.dcerpc.base
 from samba.compat import PY3, text_type
 from samba.compat import string_types
 from random import randint
-from samba.samdb import SamDB
+try:
+    from samba.samdb import SamDB
+except ImportError:
+    # We are built without samdb support,
+    # imitate it so that connect_samdb() can recover
+    SamDB = lambda *x: None
 import samba.ndr
 import samba.dcerpc.dcerpc
 import samba.dcerpc.epmapper