3
3
4
4
See http://www.python-ldap.org/ for details.
5
5
6
- \$Id: slapdtest.py,v 1.6 2017/04/27 16:06:52 stroeder Exp $
6
+ \$Id: slapdtest.py,v 1.7 2017/04/27 16:45:19 stroeder Exp $
7
7
8
8
Python compability note:
9
9
This module only works with Python 2.7.x since
32
32
33
33
# a template string for generating simple slapd.conf file
34
34
SLAPD_CONF_TEMPLATE = r"""
35
+ serverID %(serverid)s
35
36
moduleload back_%(database)s
36
37
include "%(schema_include)s"
37
38
loglevel %(loglevel)s
@@ -120,12 +121,16 @@ def __init__(self):
120
121
self ._log = combined_logger ('python-ldap-test' )
121
122
self ._proc = None
122
123
self ._port = self ._avail_tcp_port ()
124
+ self .server_id = self ._port % 4096
123
125
self .testrundir = os .path .join (self .TMPDIR , 'python-ldap-test-%d' % self ._port )
124
126
self ._slapd_conf = os .path .join (self .testrundir , 'slapd.conf' )
125
127
self ._db_directory = os .path .join (self .testrundir , "openldap-data" )
126
128
self .ldap_uri = "ldap://%s:%d/" % (LOCALHOST , self ._port )
127
129
ldapi_path = os .path .join (self .testrundir , 'ldapi' )
128
130
self .ldapi_uri = "ldapi://%s" % urllib .quote_plus (ldapi_path )
131
+ assert self .suffix .startswith ("dc=" )
132
+ assert self .root_dn .startswith ("cn=" )
133
+ assert self .root_dn .endswith ("," + self .suffix )
129
134
130
135
def _setup_rundir (self ):
131
136
"""
@@ -170,6 +175,7 @@ def _gen_config(self):
170
175
generates a slapd.conf and returns it as one string
171
176
"""
172
177
config_dict = {
178
+ 'serverid' : hex (self .server_id ),
173
179
'schema_include' : self .INIT_SCHEMA_PATH ,
174
180
'loglevel' : self .slapd_loglevel ,
175
181
'database' : self .database ,
@@ -229,7 +235,7 @@ def _start_slapd(self):
229
235
raise RuntimeError ("slapd exited before opening port" )
230
236
time .sleep (self ._start_sleep )
231
237
try :
232
- self ._log .debug ("Connecting to %s" , self .ldap_uri )
238
+ self ._log .debug ("slapd connection check to %s" , self .ldapi_uri )
233
239
self .ldapwhoami ()
234
240
except RuntimeError :
235
241
pass
@@ -245,18 +251,14 @@ def start(self):
245
251
# prepare directory structure
246
252
self ._cleanup_rundir ()
247
253
self ._setup_rundir ()
248
- try :
249
- self ._write_config ()
250
- self ._test_config ()
251
- self ._start_slapd ()
252
- self ._log .debug (
253
- 'slapd with pid=%d listing on %s and %s' ,
254
- self ._proc .pid , self .ldap_uri , self .ldapi_uri
255
- )
256
- self .started ()
257
- finally :
258
- pass
259
- #self._cleanup_rundir()
254
+ self ._write_config ()
255
+ self ._test_config ()
256
+ self ._start_slapd ()
257
+ self ._log .debug (
258
+ 'slapd with pid=%d listening on %s and %s' ,
259
+ self ._proc .pid , self .ldap_uri , self .ldapi_uri
260
+ )
261
+ self .started ()
260
262
261
263
def stop (self ):
262
264
"""Stops the slapd server, and waits for it to terminate"""
@@ -285,10 +287,6 @@ def _stopped(self):
285
287
if self ._proc is not None :
286
288
self ._log .info ('slapd terminated' )
287
289
self ._proc = None
288
- try :
289
- os .remove (self ._slapd_conf )
290
- except os .error :
291
- self ._log .debug ('could not remove %s' , self ._slapd_conf )
292
290
293
291
def _cli_auth_args (self ):
294
292
if self .cli_sasl_external :
@@ -346,10 +344,7 @@ def started(self):
346
344
By default, this method adds the two initial objects,
347
345
the domain object and the root user object.
348
346
"""
349
- assert self .suffix .startswith ("dc=" )
350
347
suffix_dc = self .suffix .split (',' )[0 ][3 :]
351
- assert self .root_dn .startswith ("cn=" )
352
- assert self .root_dn .endswith ("," + self .suffix )
353
348
self ._log .debug (
354
349
"adding %s and %s" ,
355
350
self .suffix ,
@@ -364,7 +359,7 @@ def started(self):
364
359
'o: ' + suffix_dc ,
365
360
'' ,
366
361
'dn: ' + self .root_dn ,
367
- 'objectClass: organizationalRole ' ,
362
+ 'objectClass: applicationProcess ' ,
368
363
'cn: ' + self .root_cn ,
369
364
''
370
365
])
0 commit comments