From 599187ead61340d8d3bd3e9db7eab034175bfd7b Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Wed, 5 Nov 2014 06:26:25 +0100 Subject: [PATCH] s4-dsdb-test: Implement samdb_connect_env() to rely solely on environment this is to help me port Python tests to be more Unit test alike and remove all global handling Starting from a new test suite - tombstone_reanimation.py Andrew Bartlett rose his concerns that passing parameters through environment may make tests hard to trace for failures. However, passing parameters on command line is not Unit test alike either. After discussing this with him offline, we agreed to continue this approach, but prefix environment variables with "TEST_". So that an env var should not be used by coincidence. Change-Id: I29445c42cdcafede3897c8dd1f1529222a74afc9 Signed-off-by: Kamen Mazdrashki Reviewed-by: Andrew Bartlett Reviewed-by: Garming Sam --- python/samba/tests/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index 952b6eecdd1..5b45865a815 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -23,6 +23,7 @@ import samba import samba.auth from samba import param from samba.samdb import SamDB +from samba import credentials import subprocess import tempfile @@ -234,6 +235,26 @@ def connect_samdb_ex(samdb_url, lp=None, session_info=None, credentials=None, return (sam_db, res[0]) +def connect_samdb_env(env_url, env_username, env_password, lp=None): + """Connect to SamDB by getting URL and Credentials from environment + + :param env_url: Environment variable name to get lsb url from + :param env_username: Username environment variable + :param env_password: Password environment variable + :return: sam_db_connection + """ + samdb_url = env_get_var_value(env_url) + creds = credentials.Credentials() + if lp is None: + # guess Credentials parameters here. Otherwise workstation + # and domain fields are NULL and gencache code segfalts + lp = param.LoadParm() + creds.guess(lp) + creds.set_username(env_get_var_value(env_username)) + creds.set_password(env_get_var_value(env_password)) + return connect_samdb(samdb_url, credentials=creds, lp=lp) + + def delete_force(samdb, dn): try: samdb.delete(dn) -- 2.11.4.GIT