From d61959cfa64f0f1f38a8e1ecb5b800485c49d217 Mon Sep 17 00:00:00 2001 From: stroeder Date: Fri, 5 Feb 2016 09:08:39 +0000 Subject: [PATCH] Stripped trailing spaces, honor TMP env var, changed PATH_SCHEMA_CORE --- Tests/slapd.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Tests/slapd.py b/Tests/slapd.py index 48747fa..0c5d925 100644 --- a/Tests/slapd.py +++ b/Tests/slapd.py @@ -1,6 +1,6 @@ """ -Utilities for starting up a test slapd server +Utilities for starting up a test slapd server and talking to it with ldapsearch/ldapadd. """ @@ -21,10 +21,10 @@ def mkdirs(path): def delete_directory_content(path): for dirpath,dirnames,filenames in os.walk(path, topdown=False): - for n in filenames: + for n in filenames: _log.info("remove %s", os.path.join(dirpath, n)) os.remove(os.path.join(dirpath, n)) - for n in dirnames: + for n in dirnames: _log.info("rmdir %s", os.path.join(dirpath, n)) os.rmdir(os.path.join(dirpath, n)) @@ -53,10 +53,10 @@ class Slapd: _log = logging.getLogger("Slapd") # Use /var/tmp to placate apparmour on Ubuntu: - PATH_TMPDIR = "/var/tmp/python-ldap-test" + PATH_TMPDIR = "/var/tmp/python-ldap-test" PATH_SBINDIR = "/usr/sbin" PATH_BINDIR = "/usr/bin" - PATH_SCHEMA_CORE = "/etc/ldap/schema/core.schema" + PATH_SCHEMA_CORE = "/etc/openldap/schema/core.schema" PATH_LDAPADD = os.path.join(PATH_BINDIR, "ldapadd") PATH_LDAPSEARCH = os.path.join(PATH_BINDIR, "ldapsearch") PATH_SLAPD = os.path.join(PATH_SBINDIR, "slapd") @@ -89,7 +89,7 @@ def __init__(self): self._root_password = "password" self._slapd_debug_level = 0 - # Setters + # Setters def set_port(self, port): self._port = port def set_dn_suffix(self, dn): @@ -120,7 +120,7 @@ def get_root_dn(self): def get_root_password(self): return self._root_password def get_tmpdir(self): - return self._tmpdir + return os.environ.get('TMP',self._tmpdir) def __del__(self): self.stop() @@ -159,7 +159,7 @@ def _write_config(self): def start(self): """ - Starts the slapd server process running, and waits for it to come up. + Starts the slapd server process running, and waits for it to come up. """ if self._proc is None: ok = False @@ -184,9 +184,9 @@ def _start_slapd(self): # Spawns/forks the slapd process config_path = self._write_config() self._log.info("starting slapd") - self._proc = subprocess.Popen([self.PATH_SLAPD, - "-f", config_path, - "-h", self.get_url(), + self._proc = subprocess.Popen([self.PATH_SLAPD, + "-f", config_path, + "-h", self.get_url(), "-d", str(self._slapd_debug_level), ]) self._proc_config = config_path @@ -239,9 +239,9 @@ def _stopped(self): if self._proc is not None: self._log.info("slapd terminated") self._proc = None - try: + try: os.remove(self._proc_config) - except os.error: + except os.error: self._log.debug("could not remove %s", self._proc_config) def _test_configuration(self): @@ -252,8 +252,8 @@ def _test_configuration(self): if self._log.isEnabledFor(logging.DEBUG): verboseflag = "-v" p = subprocess.Popen([ - self.PATH_SLAPTEST, - verboseflag, + self.PATH_SLAPTEST, + verboseflag, "-f", config_path ]) if p.wait() != 0: @@ -265,7 +265,7 @@ def _test_configuration(self): def ldapadd(self, ldif, extra_args=[]): """Runs ldapadd on this slapd instance, passing it the ldif content""" self._log.debug("adding %s", repr(ldif)) - p = subprocess.Popen([self.PATH_LDAPADD, + p = subprocess.Popen([self.PATH_LDAPADD, "-x", "-D", self.get_root_dn(), "-w", self.get_root_password(), @@ -279,7 +279,7 @@ def ldapsearch(self, base=None, filter='(objectClass=*)', attrs=[], scope='sub', extra_args=[]): if base is None: base = self.get_dn_suffix() self._log.debug("ldapsearch filter=%s", repr(filter)) - p = subprocess.Popen([self.PATH_LDAPSEARCH, + p = subprocess.Popen([self.PATH_LDAPSEARCH, "-x", "-D", self.get_root_dn(), "-w", self.get_root_password(),