From: Christian O. <chr...@gm...> - 2009-12-15 14:53:40
|
On my system, slapd.py fails because of a missing /var/tmp/python-ldap-test . Not sure what your patch submission procedure is, but here's a patch to fix that: ================================== diff --git a/pstat/dynamic_ldap/slapd.py b/pstat/dynamic_ldap/slapd.py index 735b58e..2cd3e25 100644 --- a/pstat/dynamic_ldap/slapd.py +++ b/pstat/dynamic_ldap/slapd.py @@ -13,12 +13,25 @@ def quote(s): '''Quotes the '"' and '\' characters in a string and surrounds with "..."''' return '"' + s.replace('\\','\\\\').replace('"','\\"') + '"' -def mkdirs(path): - """Creates the directory path unless it already exists""" - if not os.access(os.path.join(path, os.path.curdir), os.F_OK): - _log.debug("creating temp directory %s", path) - os.mkdir(path) - return path +def mkdir(newdir): + #http://code.activestate.com/recipes/82465/ + """works the way a good mkdir should :) + - already exists, silently complete + - regular file in the way, raise an exception + - parent directory(ies) does not exist, make them as well + """ + if os.path.isdir(newdir): + pass + elif os.path.isfile(newdir): + raise OSError("a file with the same name as the desired " \ + "dir, '%s', already exists." % newdir) + else: + head, tail = os.path.split(newdir) + if head and not os.path.isdir(head): + mkdir(head) + if tail: + os.mkdir(newdir) + return newdir def delete_directory_content(path): for dirpath,dirnames,filenames in os.walk(path, topdown=False): @@ -138,7 +151,8 @@ class Slapd: cfg.append("allow bind_v2") # Database - ldif_dir = mkdirs(os.path.join(self.get_tmpdir(), "ldif-data")) + ldif_dir = os.path.join(self.get_tmpdir(), "ldif-data") + mkdir(ldif_dir) delete_directory_content(ldif_dir) # clear it out cfg.append("database ldif") cfg.append("directory " + quote(ldif_dir)) @@ -150,7 +164,7 @@ class Slapd: def _write_config(self): """Writes the slapd.conf file out, and returns the path to it.""" path = os.path.join(self._tmpdir, "slapd.conf") - ldif_dir = mkdirs(self._tmpdir) + mkdir(self._tmpdir) if os.access(path, os.F_OK): self._log.debug("deleting existing %s", path) os.remove(path) |
From: Michael S. <mi...@st...> - 2009-12-17 19:29:13
|
Christian Oudard wrote: > On my system, slapd.py fails because of a missing /var/tmp/python-ldap-test . > > Not sure what your patch submission procedure is, but here's a patch > to fix that: Hmm, normally I review patches and commit them. So you did the right thing posting it here. In this case I'm not familiar with slapd.py which was written by David and after glancing over it I strongly dislike some of the assumptions made therein. So I'm not going to touch that now because of lack of time. Ciao, Michael. |
From: Christian O. <chr...@gm...> - 2009-12-17 19:56:51
|
I'm in the process of adapting slapd.py to be a general purpose mock ldap test server for running unit tests against. I would be interested in contributing improvements to it that keep it compatible with the test suite of python-ldap. Specifically, what sort of assumptions are you trying to get rid of? 2009/12/17 Michael Ströder <mi...@st...>: > Christian Oudard wrote: >> On my system, slapd.py fails because of a missing /var/tmp/python-ldap-test . >> >> Not sure what your patch submission procedure is, but here's a patch >> to fix that: > > Hmm, normally I review patches and commit them. So you did the right thing > posting it here. > > In this case I'm not familiar with slapd.py which was written by David and > after glancing over it I strongly dislike some of the assumptions made > therein. So I'm not going to touch that now because of lack of time. > > Ciao, Michael. > > |
From: Michael S. <mi...@st...> - 2009-12-18 12:56:51
|
Christian Oudard wrote: > 2009/12/17 Michael Ströder <mi...@st...>: >> In this case I'm not familiar with slapd.py which was written by David and >> after glancing over it I strongly dislike some of the assumptions made >> therein. So I'm not going to touch that now because of lack of time. > > I'm in the process of adapting slapd.py to be a general purpose mock > ldap test server for running unit tests against. I would be interested > in contributing improvements to it that keep it compatible with the > test suite of python-ldap. > Specifically, what sort of assumptions are you trying to get rid of? Some short comments: 1. It should also work on Windows which is not possible with the currently implemented filename handling. 2. Probably a template for slapd.conf should be used which can be more easily adapted to various OpenLDAP releases, especially no references to specific schema files etc. 3. Data should be kept locally in a sub-directory like with OpenLDAP's test suite. No need for /var/blurb. 4. The assumption about slapd executable being in something like /usr/sbin/ is wrong. Rather the full path to slapd and slaptest should be specified. Ciao, Michael. |