Skip to content

Commit b17af25

Browse files
author
stroeder
committed
more re-factoring of slapdtest
1 parent 48b65a4 commit b17af25

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Lib/slapdtest.py
1414
instances side-by-side (e.g. with replication)
1515
* added authz-regexp mapping to rootdn for user running the test
1616
* internally use SASL/EXTERNAL via LDAPI to bind
17+
* SlapdObject.server_id used as serverID in slapd.conf for MMR
1718

1819
Tests/
1920
* ReconnectLDAPObject is also tested by sub-classing test class
@@ -1429,4 +1430,4 @@ Released 2.0.0pre02 2002-02-01
14291430
----------------------------------------------------------------
14301431
Released 1.10alpha3 2000-09-19
14311432

1432-
$Id: CHANGES,v 1.440 2017/04/27 16:10:27 stroeder Exp $
1433+
$Id: CHANGES,v 1.441 2017/04/27 16:45:19 stroeder Exp $

Lib/slapdtest.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
See http://www.python-ldap.org/ for details.
55
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 $
77
88
Python compability note:
99
This module only works with Python 2.7.x since
@@ -32,6 +32,7 @@
3232

3333
# a template string for generating simple slapd.conf file
3434
SLAPD_CONF_TEMPLATE = r"""
35+
serverID %(serverid)s
3536
moduleload back_%(database)s
3637
include "%(schema_include)s"
3738
loglevel %(loglevel)s
@@ -120,12 +121,16 @@ def __init__(self):
120121
self._log = combined_logger('python-ldap-test')
121122
self._proc = None
122123
self._port = self._avail_tcp_port()
124+
self.server_id = self._port % 4096
123125
self.testrundir = os.path.join(self.TMPDIR, 'python-ldap-test-%d' % self._port)
124126
self._slapd_conf = os.path.join(self.testrundir, 'slapd.conf')
125127
self._db_directory = os.path.join(self.testrundir, "openldap-data")
126128
self.ldap_uri = "ldap://%s:%d/" % (LOCALHOST, self._port)
127129
ldapi_path = os.path.join(self.testrundir, 'ldapi')
128130
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)
129134

130135
def _setup_rundir(self):
131136
"""
@@ -170,6 +175,7 @@ def _gen_config(self):
170175
generates a slapd.conf and returns it as one string
171176
"""
172177
config_dict = {
178+
'serverid': hex(self.server_id),
173179
'schema_include': self.INIT_SCHEMA_PATH,
174180
'loglevel': self.slapd_loglevel,
175181
'database': self.database,
@@ -229,7 +235,7 @@ def _start_slapd(self):
229235
raise RuntimeError("slapd exited before opening port")
230236
time.sleep(self._start_sleep)
231237
try:
232-
self._log.debug("Connecting to %s", self.ldap_uri)
238+
self._log.debug("slapd connection check to %s", self.ldapi_uri)
233239
self.ldapwhoami()
234240
except RuntimeError:
235241
pass
@@ -245,18 +251,14 @@ def start(self):
245251
# prepare directory structure
246252
self._cleanup_rundir()
247253
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()
260262

261263
def stop(self):
262264
"""Stops the slapd server, and waits for it to terminate"""
@@ -285,10 +287,6 @@ def _stopped(self):
285287
if self._proc is not None:
286288
self._log.info('slapd terminated')
287289
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)
292290

293291
def _cli_auth_args(self):
294292
if self.cli_sasl_external:
@@ -346,10 +344,7 @@ def started(self):
346344
By default, this method adds the two initial objects,
347345
the domain object and the root user object.
348346
"""
349-
assert self.suffix.startswith("dc=")
350347
suffix_dc = self.suffix.split(',')[0][3:]
351-
assert self.root_dn.startswith("cn=")
352-
assert self.root_dn.endswith("," + self.suffix)
353348
self._log.debug(
354349
"adding %s and %s",
355350
self.suffix,
@@ -364,7 +359,7 @@ def started(self):
364359
'o: '+suffix_dc,
365360
'',
366361
'dn: '+self.root_dn,
367-
'objectClass: organizationalRole',
362+
'objectClass: applicationProcess',
368363
'cn: '+self.root_cn,
369364
''
370365
])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy