From c4a17d405a27edc010b957695029b849d922d625 Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 12 Oct 2016 16:53:38 +1000 Subject: [PATCH] Ticket 49007 - lib389 fixes for paths to use online values Bug Description: The test basic relied on some values that were not in lib389 Fix Description: Update the values in lib389 for what test basic expects: While we are messing about, may as well just update all the values and simplify out the __initPart2 function. https://fedorahosted.org/389/ticket/49007 Author: wibrown Review by: ??? --- lib389/__init__.py | 93 +++++++++++++----------------------------------------- lib389/paths.py | 34 ++++++++++++++++++-- 2 files changed, 54 insertions(+), 73 deletions(-) diff --git a/lib389/__init__.py b/lib389/__init__.py index 0e0d1e6..f71092f 100644 --- a/lib389/__init__.py +++ b/lib389/__init__.py @@ -263,57 +263,15 @@ class DirSrv(SimpleLDAPObject): @raise ldap.LDAPError - if failure during initialization """ - if self.binddn and len(self.binddn): - try: - # XXX this fields are stale and not continuously updated - # do they have sense? - ent = self.getEntry(DN_CONFIG, attrlist=[ - 'nsslapd-instancedir', - 'nsslapd-errorlog', - 'nsslapd-accesslog', - 'nsslapd-auditlog', - 'nsslapd-certdir', - 'nsslapd-schemadir', - 'nsslapd-bakdir', - 'nsslapd-ldifdir']) - self.errlog = ent.getValue('nsslapd-errorlog') - self.accesslog = ent.getValue('nsslapd-accesslog') - self.auditlog = ent.getValue('nsslapd-auditlog') - self.confdir = ent.getValue('nsslapd-certdir') - self.schemadir = ent.getValue('nsslapd-schemadir') - self.bakdir = ent.getValue('nsslapd-bakdir') - self.ldifdir = ent.getValue('nsslapd-ldifdir') - - if self.isLocal: - if not self.confdir or \ - not os.access(self.confdir.decode('utf-8') + '/dse.ldif', os.R_OK): - self.confdir = ent.getValue('nsslapd-schemadir') - if self.confdir: - self.confdir = os.path.dirname(self.confdir) - if not self.schemadir: - # assume it is in the "schema" subdir of the confdir - self.schemadir = os.path.join(self.confdir, "schema") - instdir = ent.getValue('nsslapd-instancedir') - if not instdir and self.isLocal: - if self.isLocal: - instdir = self.ds_paths.inst_dir - if not instdir: - instdir = self.confdir.decode('utf-8') - - # parse the lib dir, and so set the plugin dir - self.instdir = instdir - - ent = self.getEntry('cn=config,' + DN_LDBM, - attrlist=['nsslapd-directory']) - self.dbdir = os.path.dirname(ent.getValue('nsslapd-directory')) - except (ldap.INSUFFICIENT_ACCESS, ldap.CONNECT_ERROR, - NoSuchEntryError): - log.exception("Skipping exception during initialization") - except ldap.OPERATIONS_ERROR as e: - log.exception("Skipping exception: Probably Active Directory") - except ldap.LDAPError as e: - log.exception("Error during initialization, error: " + str(e)) - raise + self.errlog = self.ds_paths.error_log + self.accesslog = self.ds_paths.access_log + self.auditlog = self.ds_paths.audit_log + self.confdir = self.ds_paths.config_dir + self.schemadir = self.ds_paths.schema_dir + self.bakdir = self.ds_paths.backup_dir + self.ldifdir = self.ds_paths.ldif_dir + self.instdir = self.ds_paths.inst_dir + self.dbdir = self.ds_paths.db_dir def __localinit__(self): ''' @@ -446,7 +404,7 @@ class DirSrv(SimpleLDAPObject): self.timeout = timeout self.confdir = None - self.ds_paths = Paths() + self.ds_paths = Paths(instance=self) # Reset the args (py.test reuses the args_instance for each test case) args_instance[SER_DEPLOYED_DIR] = os.environ.get('PREFIX', self.ds_paths.prefix) @@ -512,9 +470,9 @@ class DirSrv(SimpleLDAPObject): self.log.debug('SER_SERVERID_PROP not provided') # The lack of this value basically rules it out in most cases self.isLocal = False - self.ds_paths = Paths() + self.ds_paths = Paths(instance=self) else: - self.ds_paths = Paths(args[SER_SERVERID_PROP]) + self.ds_paths = Paths(args[SER_SERVERID_PROP], instance=self) # Do we have ldapi settings? @@ -786,24 +744,14 @@ class DirSrv(SimpleLDAPObject): serverid = self.serverid # first identify the directories we will scan - confdir = os.getenv('INITCONFIGDIR') - if confdir: - if self.verbose: - self.log.info("$INITCONFIGDIR set to: %s" % confdir) - if not os.path.isdir(confdir): - raise ValueError("$INITCONFIGDIR incorrect directory (%s)" % - confdir) - sysconfig_head = confdir + sysconfig_head = self.ds_paths.initconfig_dir + privconfig_head = os.path.join(os.getenv('HOME'), ENV_LOCAL_DIR) + if not os.path.isdir(sysconfig_head): privconfig_head = None - else: - sysconfig_head = self.ds_paths.initconfig_dir - privconfig_head = os.path.join(os.getenv('HOME'), ENV_LOCAL_DIR) - if not os.path.isdir(sysconfig_head): - privconfig_head = None - if self.verbose: - self.log.info("dir (sys) : %s" % sysconfig_head) - if privconfig_head and self.verbose: - self.log.info("dir (priv): %s" % privconfig_head) + if self.verbose: + self.log.info("dir (sys) : %s" % sysconfig_head) + if privconfig_head and self.verbose: + self.log.info("dir (priv): %s" % privconfig_head) # list of the found instances instances = [] @@ -1564,6 +1512,9 @@ class DirSrv(SimpleLDAPObject): def get_local_state_dir(self): return self.ds_paths.local_state_dir + def get_config_dir(self): + return self.ds_paths.config_dir + def get_sysconf_dir(self): return self.ds_paths.sysconf_dir diff --git a/lib389/paths.py b/lib389/paths.py index 57f6a7c..e0c2518 100644 --- a/lib389/paths.py +++ b/lib389/paths.py @@ -9,6 +9,8 @@ import sys import os +from lib389._constants import DIRSRV_STATE_ONLINE + MAJOR, MINOR, _, _, _ = sys.version_info if MAJOR >= 3: @@ -60,10 +62,30 @@ MUST = [ 'initconfig_dir', ] +# will need to add the access, error, audit log later. + +# This maps a config to (entry, attr). +# This can be used online, or while the server is offline and we can parse dse.ldif + +CONFIG_MAP = { + 'user' : ('cn=config', 'nsslapd-localuser'), + 'group' : ('cn=config','nsslapd-localuser'), # Is this correct? + 'schema_dir' : ('cn=config','nsslapd-schemadir'), + 'cert_dir' : ('cn=config','nsslapd-certdir'), + 'lock_dir' : ('cn=config','nsslapd-lockdir'), + 'inst_dir' : ('cn=config','nsslapd-instancedir'), + 'db_dir' : ('cn=config,cn=ldbm database,cn=plugins,cn=config', 'nsslapd-directory'), + 'backup_dir': ('cn=config','nsslapd-bakdir'), + 'ldif_dir': ('cn=config','nsslapd-ldifdir'), + 'error_log' : ('cn=config', 'nsslapd-errorlog'), + 'access_log' : ('cn=config', 'nsslapd-accesslog'), + 'audit_log' : ('cn=config', 'nsslapd-auditlog'), +} + SECTION = 'slapd' class Paths(object): - def __init__(self, serverid=None): + def __init__(self, serverid=None, instance=None): """ Parses and uses a set of default paths from wellknown locations. The list of keys available is from the MUST attribute in this module. @@ -86,6 +108,7 @@ class Paths(object): self._defaults_cached = False self._config = None self._serverid = serverid + self._instance = instance def _get_defaults_loc(self, search_paths): for spath in search_paths: @@ -111,7 +134,14 @@ class Paths(object): if self._defaults_cached is False: self._read_defaults() self._validate_defaults() - if self._serverid is not None: + # Are we online? Is our key in the config map? + if name in CONFIG_MAP and self._instance is not None and self._instance.state == DIRSRV_STATE_ONLINE: + # Get the online value. + (dn, attr) = CONFIG_MAP[name] + ent = self._instance.getEntry(dn, attrlist=[attr,]) + return ent.getValue(attr) + + elif self._serverid is not None: return self._config.get(SECTION, name).format(instance_name=self._serverid) else: return self._config.get(SECTION, name) -- 1.8.3.1