This is an automated email from the git hooks/post-receive script.
firstyear pushed a commit to branch master
in repository 389-ds-base.
commit b28d8b4b5bc4496b25ad11121d30dfcf01b1ce63
Author: Thierry bordaz (tbordaz) <tbordaz(a)redhat.com>
Date: Mon Jan 13 17:10:44 2014 +0100
Ticket 47671 - CI lib389: allow to open a DirSrv without having to create the
instance
Bug Description:
DSAdmin allowed to bind to an already existing instance without creation of the
instance.
Allocate() and open() require that a server-id is provided during Allocate.
This prevents to allocate a DirSrv? to bind to an existing instance.
Fix Description:
Change Allocate so that SER_SERVERID_PROP is not mandatory.
Change Open so that if self.serverid is not defined it retrieves it from the instance
(self.inst)
https://fedorahosted.org/389/ticket/47671
Reviewed by: Rich Megginson
Platforms tested: F17/F19(jenkins)
Flag Day: no
Doc impact: no
---
src/lib389/lib389/__init__.py | 24 +++++++++++------
src/lib389/tests/dirsrv_test.py | 59 ++++++++++++++++++++++++++++++-----------
2 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py
index 6e2b357..8db6aab 100644
--- a/src/lib389/lib389/__init__.py
+++ b/src/lib389/lib389/__init__.py
@@ -234,6 +234,13 @@ class DirSrv(SimpleLDAPObject):
self.sroot, self.inst = match.groups()
else:
self.sroot = self.inst = ''
+ # In case DirSrv was allocated without creating the instance
+ # serverid is not set. Set it now from the config
+ if hasattr(self, 'serverid') and self.serverid:
+ assert self.serverid == self.inst
+ else:
+ self.serverid = self.inst
+
ent = self.getEntry('cn=config,' + DN_LDBM,
attrlist=['nsslapd-directory'])
self.dbdir = os.path.dirname(ent.getValue('nsslapd-directory'))
@@ -355,7 +362,7 @@ class DirSrv(SimpleLDAPObject):
The final state -> DIRSRV_STATE_ALLOCATED
@param args - dictionary that contains the DirSrv properties
properties are
- SER_SERVERID_PROP: mandatory server id of the instance ->
slapd-<serverid>
+ SER_SERVERID_PROP: used for offline op
(create/delete/backup/start/stop..) -> slapd-<serverid>
SER_HOST: hostname [LOCALHOST]
SER_PORT: normal ldap port [DEFAULT_PORT]
SER_SECURE_PORT: secure ldap port
@@ -374,7 +381,7 @@ class DirSrv(SimpleLDAPObject):
raise ValueError("invalid state for calling allocate: %s" %
self.state)
if SER_SERVERID_PROP not in args:
- raise ValueError("%s is a mandatory parameter" %
SER_SERVERID_PROP)
+ self.log.info('SER_SERVERID_PROP not provided')
# Settings from args of server attributes
self.host = args.get(SER_HOST, LOCALHOST)
@@ -393,7 +400,7 @@ class DirSrv(SimpleLDAPObject):
# Settings from args of server attributes
- self.serverid = args.get(SER_SERVERID_PROP)
+ self.serverid = args.get(SER_SERVERID_PROP, None)
self.groupid = args.get(SER_GROUP_ID, self.userid)
self.backupdir = args.get(SER_BACKUP_INST_DIR, DEFAULT_BACKUPDIR)
self.prefix = args.get(SER_DEPLOYED_DIR, None)
@@ -657,7 +664,8 @@ class DirSrv(SimpleLDAPObject):
@return - None
- @raise ValueError - if it exist an instance with the same 'serverid'
+ @raise ValueError - if 'serverid' is missing or if it exist an
+ instance with the same 'serverid'
"""
# check that DirSrv was in DIRSRV_STATE_ALLOCATED state
if self.state != DIRSRV_STATE_ALLOCATED:
@@ -668,6 +676,9 @@ class DirSrv(SimpleLDAPObject):
if len(props) != 0:
raise ValueError("Error it already exists the instance (%s)" %
props[0][CONF_INST_DIR])
+ if not self.serverid:
+ raise ValueError("SER_SERVERID_PROP is missing, it is required to create
an instance")
+
# Time to create the instance and retrieve the effective sroot
self._createDirsrv(verbose=self.verbose)
@@ -721,11 +732,8 @@ class DirSrv(SimpleLDAPObject):
@return None
- @raise ValueError - if the instance has not the right state or can not find
the binddn to bind
+ @raise ValueError - if can not find the binddn to bind
'''
- # check that DirSrv was in DIRSRV_STATE_OFFLINE or DIRSRV_STATE_ONLINE state
- if self.state != DIRSRV_STATE_OFFLINE and self.state != DIRSRV_STATE_ONLINE:
- raise ValueError("invalid state for calling open: %s" %
self.state)
uri = self.toLDAPURL()
diff --git a/src/lib389/tests/dirsrv_test.py b/src/lib389/tests/dirsrv_test.py
index 4650a46..5a2fbb7 100644
--- a/src/lib389/tests/dirsrv_test.py
+++ b/src/lib389/tests/dirsrv_test.py
@@ -62,24 +62,12 @@ class Test_dirsrv():
instance.log.debug("Instance allocated")
assert instance.state == DIRSRV_STATE_INIT
- # Check that SER_SERVERID_PROP is a mandatory parameter
+ # Allocate the instance
args = {SER_HOST: LOCALHOST,
SER_PORT: INSTANCE_PORT,
- SER_DEPLOYED_DIR: INSTANCE_PREFIX
+ SER_DEPLOYED_DIR: INSTANCE_PREFIX,
+ SER_SERVERID_PROP: INSTANCE_SERVERID
}
- try:
- instance.allocate(args)
- except Exception as e:
- instance.log.info('Allocate fails (normal): %s' % e.args)
- assert type(e) == ValueError
- assert e.args[0].find("%s is a mandatory parameter" %
SER_SERVERID_PROP) >= 0
- pass
-
- # Check the state
- assert instance.state == DIRSRV_STATE_INIT
-
- # Now do a successful allocate
- args[SER_SERVERID_PROP] = INSTANCE_SERVERID
instance.allocate(args)
userid = pwd.getpwuid( os.getuid() )[ 0 ]
@@ -162,8 +150,45 @@ class Test_dirsrv():
def test_offline_to_allocated(self):
self.instance.delete()
+
+ def test_allocated_to_online(self, verbose):
+ # Here the instance was already create, check we can connect to it
+ # without creating it (especially without serverid value)
+ # Allocate the instance
+ args = {SER_HOST: LOCALHOST,
+ SER_PORT: INSTANCE_PORT,
+ SER_DEPLOYED_DIR: INSTANCE_PREFIX,
+ SER_SERVERID_PROP: INSTANCE_SERVERID
+ }
+ self.instance.log.info("test_allocated_to_online: Create an instance")
+ self.instance = DirSrv(verbose=verbose)
+ assert not hasattr(self, 'serverid')
+ self.instance.allocate(args)
+ self.instance.create()
+ self.instance.open()
+ assert self.instance.serverid != None
+
+ # The instance is create, allocate a new DirSrv
+ self.instance.log.info("test_allocated_to_online: instance New")
+ self.instance = DirSrv(verbose=verbose)
+ assert not hasattr(self, 'serverid')
+ assert self.instance.state == DIRSRV_STATE_INIT
+
+ args = {SER_HOST: LOCALHOST,
+ SER_PORT: INSTANCE_PORT,
+ SER_DEPLOYED_DIR: INSTANCE_PREFIX,
+ }
+ self.instance.allocate(args)
+ self.instance.log.info("test_allocated_to_online: instance Allocated")
+ assert self.instance.serverid == None
+ assert self.instance.state == DIRSRV_STATE_ALLOCATED
+
+ self.instance.open()
+ self.instance.log.info("test_allocated_to_online: instance online")
+ assert self.instance.serverid != None
+ assert self.instance.serverid == self.instance.inst
+ assert self.instance.state == DIRSRV_STATE_ONLINE
-
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
test = Test_dirsrv()
@@ -201,6 +226,8 @@ if __name__ == "__main__":
test.test_offline_to_allocated()
+ test.test_allocated_to_online(verbose=False)
+
test.tearDown()
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.