From 6963780bd89a37b758799ec390983db5392b596f Mon Sep 17 00:00:00 2001 From: William Brown Date: Feb 25 2019 04:11:10 +0000 Subject: Ticket 50213 - fix list instance issue Bug Description: A format string would not always be created which caused instance list to fail. This may lead to instance removal failing (creation and api removal still functioned) Fix Description: Use a correctly initialised paths object, and add extra debugging around the list capability for -v https://pagure.io/389-ds-base/issue/50213 Author: William Brown Review by: mreynolds (Thanks) --- diff --git a/src/lib389/cli/dsctl b/src/lib389/cli/dsctl index cad37ae..a6df241 100755 --- a/src/lib389/cli/dsctl +++ b/src/lib389/cli/dsctl @@ -103,7 +103,7 @@ if __name__ == '__main__': log.error("Unable to access instance information. Are you running as root or dirsrv?") sys.exit(1) if len(insts) != 1: - log.error("No such instance %s" % args.instance) + log.error("No such instance '%s': this may be a permission issue." % args.instance) sys.exit(1) inst.allocate(insts[0]) diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py index 1d0d693..470d252 100644 --- a/src/lib389/lib389/__init__.py +++ b/src/lib389/lib389/__init__.py @@ -753,7 +753,14 @@ class DirSrv(SimpleLDAPObject, object): # now prepare the list of instances properties if not all: - dse_ldif = os.path.join(self.ds_paths.config_dir, 'dse.ldif') + # Don't use self.ds_paths here, because it has no server id : this + # causes the config_dir to have a formatting issue. + # + # As dse.ldif is one of the only fixed locations in the server, this is + # okay to use this without parsing of dse.ldif to add the other paths + # required: yet. + inst_paths = Paths(serverid) + dse_ldif = os.path.join(inst_paths.config_dir, 'dse.ldif') # easy case we just look for the current instance if os.path.exists(dse_ldif): # It's real @@ -761,7 +768,7 @@ class DirSrv(SimpleLDAPObject, object): instances.append(_parse_configfile(dse_ldif, serverid)) else: # it's not - self.log.debug("list instance not found: %s\n", serverid) + self.log.debug("list instance not found: %s -> %s\n" % (serverid, dse_ldif)) else: # For each dir that starts with slapd-* diff --git a/src/lib389/lib389/instance/remove.py b/src/lib389/lib389/instance/remove.py index 9e7f3ee..c5d6622 100644 --- a/src/lib389/lib389/instance/remove.py +++ b/src/lib389/lib389/instance/remove.py @@ -36,10 +36,7 @@ def remove_ds_instance(dirsrv, force=False): """ _log = dirsrv.log.getChild('remove_ds') _log.debug("Removing instance %s" % dirsrv.serverid) - # Stop the instance (if running) - _log.debug("Stopping instance %s" % dirsrv.serverid) - dirsrv.stop() - # Copy all the paths we are about to tamp with + # Copy all the paths we are about to tamper with remove_paths = {} remove_paths['backup_dir'] = dirsrv.ds_paths.backup_dir remove_paths['cert_dir'] = dirsrv.ds_paths.cert_dir @@ -54,13 +51,13 @@ def remove_ds_instance(dirsrv, force=False): remove_paths['lock_dir'] = dirsrv.ds_paths.lock_dir remove_paths['log_dir'] = dirsrv.ds_paths.log_dir # remove_paths['run_dir'] = dirsrv.ds_paths.run_dir - remove_paths['tmpfiles_d'] = dirsrv.ds_paths.tmpfiles_d + "/dirsrv-" + dirsrv.serverid + ".conf" remove_paths['inst_dir'] = dirsrv.ds_paths.inst_dir remove_paths['etc_sysconfig'] = "%s/sysconfig/dirsrv-%s" % (dirsrv.ds_paths.sysconf_dir, dirsrv.serverid) + tmpfiles_d_path = dirsrv.ds_paths.tmpfiles_d + "/dirsrv-" + dirsrv.serverid + ".conf" + # These are handled in a special way. - etc_dirsrv_path = os.path.join(dirsrv.ds_paths.sysconf_dir, 'dirsrv/') - dse_ldif_path = os.path.join(etc_dirsrv_path, 'dse.ldif') + dse_ldif_path = os.path.join(dirsrv.ds_paths.config_dir, 'dse.ldif') # Check the marker exists. If it *does not* warn about this, and say that to # force removal you should touch this file. @@ -70,6 +67,12 @@ def remove_ds_instance(dirsrv, force=False): _log.info("Instance configuration not found, no action will be taken") _log.info("If you want us to cleanup anyway, recreate '%s'" % dse_ldif_path) return + _log.debug("Found instance marker at %s! Proceeding to remove ..." % dse_ldif_path) + + # Stop the instance (if running) and now we know it really does exist + # and hopefully have permission to access it ... + _log.debug("Stopping instance %s" % dirsrv.serverid) + dirsrv.stop() ### ANY NEW REMOVAL ACTION MUST BE BELOW THIS LINE!!! @@ -89,6 +92,9 @@ def remove_ds_instance(dirsrv, force=False): _log.debug("Removing the systemd symlink") subprocess.check_call(["systemctl", "disable", "dirsrv@{}".format(dirsrv.serverid)]) + _log.debug("Removing %s" % tmpfiles_d_path) + shutil.rmtree(tmpfiles_d_path, ignore_errors=True) + # Nor can we assume we have selinux. Try docker sometime ;) if dirsrv.ds_paths.with_selinux: # Remove selinux port label