From b133a7418388823222fb41d4d6ab57a60482def3 Mon Sep 17 00:00:00 2001 From: William Brown Date: Dec 30 2019 03:33:54 +0000 Subject: Ticket 50667 - dsctl -l did not respect PREFIX Bug Description: dsctl list was not coded to allow using the paths module. Fix Description: Change to the paths module to allow better and consistent CLI handling. https://pagure.io/389-ds-base/issue/50667 Author: William Brown Review by: mreynolds, spichugi (thanks) --- diff --git a/src/lib389/cli/dsctl b/src/lib389/cli/dsctl index 8484f86..a4a5f9c 100755 --- a/src/lib389/cli/dsctl +++ b/src/lib389/cli/dsctl @@ -47,8 +47,8 @@ parser.add_argument('-l', '--list', default=False, action='store_true' ) -parser.add_argument('--remove-all', nargs="?", default=False, const=None, - help="Remove all instances of Directory Server (you can also provide an optional directory prefix for this argument)", +parser.add_argument('--remove-all', default=False, action='store_true', + help=argparse.SUPPRESS ) subparsers = parser.add_subparsers(help="action") diff --git a/src/lib389/lib389/cli_ctl/instance.py b/src/lib389/lib389/cli_ctl/instance.py index 95958e1..f0111f3 100644 --- a/src/lib389/lib389/cli_ctl/instance.py +++ b/src/lib389/lib389/cli_ctl/instance.py @@ -127,7 +127,7 @@ def instance_remove_all(log, args): """Remove all instances - clean sweep! """ - inst_names = get_instance_list(args.remove_all) + inst_names = get_instance_list() if len(inst_names) > 0: answer = input("Are you sure you want to remove all the Directory Server instances? Enter \"Yes\" to continue: ") if answer != 'Yes': diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py index f0c94a2..f71b1af 100644 --- a/src/lib389/lib389/utils.py +++ b/src/lib389/lib389/utils.py @@ -1252,9 +1252,10 @@ def get_ldapurl_from_serverid(instance): return ("ldap://{}:{}".format(host, port), None) -def get_instance_list(prefix=None): +def get_instance_list(): # List all server instances - conf_dir = (prefix or "") + "/etc/dirsrv/" + paths = Paths() + conf_dir = os.path.join(paths.sysconf_dir, 'dirsrv') insts = [] try: for inst in os.listdir(conf_dir): @@ -1262,6 +1263,9 @@ def get_instance_list(prefix=None): insts.append(inst) except OSError as e: log.error("Failed to check directory: {} - {}".format(conf_dir, str(e))) + except IOError as e: + log.error(e) + log.error("Perhaps you need to be a different user?") insts.sort() return insts