Blame SOURCES/0007-Ticket-50667-dsctl-l-did-not-respect-PREFIX.patch

8394b4
From f77760fb4e39e6d5b673ee8c5388407ff1ae98be Mon Sep 17 00:00:00 2001
8394b4
From: William Brown <william@blackhats.net.au>
8394b4
Date: Wed, 23 Oct 2019 12:01:04 +1000
8394b4
Subject: [PATCH] Ticket 50667 - dsctl -l did not respect PREFIX
8394b4
8394b4
Bug Description: dsctl list was not coded to allow
8394b4
using the paths module.
8394b4
8394b4
Fix Description: Change to the paths module to allow
8394b4
better and consistent CLI handling.
8394b4
8394b4
https://pagure.io/389-ds-base/issue/50667
8394b4
8394b4
Author: William Brown <william@blackhats.net.au>
8394b4
8394b4
Review by: mreynolds, spichugi (thanks)
8394b4
---
8394b4
 src/lib389/cli/dsctl                  | 4 ++--
8394b4
 src/lib389/lib389/cli_ctl/instance.py | 2 +-
8394b4
 src/lib389/lib389/utils.py            | 8 ++++++--
8394b4
 3 files changed, 9 insertions(+), 5 deletions(-)
8394b4
8394b4
diff --git a/src/lib389/cli/dsctl b/src/lib389/cli/dsctl
8394b4
index 8b86629ac..47ca8269b 100755
8394b4
--- a/src/lib389/cli/dsctl
8394b4
+++ b/src/lib389/cli/dsctl
8394b4
@@ -46,8 +46,8 @@ parser.add_argument('-l', '--list',
8394b4
         default=False, action='store_true'
8394b4
     )
8394b4
 
8394b4
-parser.add_argument('--remove-all', nargs="?", default=False, const=None,
8394b4
-        help="Remove all instances of Directory Server (you can also provide an optional directory prefix for this argument)",
8394b4
+parser.add_argument('--remove-all', default=False, action='store_true',
8394b4
+        help=argparse.SUPPRESS
8394b4
     )
8394b4
 
8394b4
 subparsers = parser.add_subparsers(help="action")
8394b4
diff --git a/src/lib389/lib389/cli_ctl/instance.py b/src/lib389/lib389/cli_ctl/instance.py
8394b4
index 95958e14c..f0111f35b 100644
8394b4
--- a/src/lib389/lib389/cli_ctl/instance.py
8394b4
+++ b/src/lib389/lib389/cli_ctl/instance.py
8394b4
@@ -127,7 +127,7 @@ def instance_remove_all(log, args):
8394b4
     """Remove all instances - clean sweep!
8394b4
     """
8394b4
 
8394b4
-    inst_names = get_instance_list(args.remove_all)
8394b4
+    inst_names = get_instance_list()
8394b4
     if len(inst_names) > 0:
8394b4
         answer = input("Are you sure you want to remove all the Directory Server instances?  Enter \"Yes\" to continue: ")
8394b4
         if answer != 'Yes':
8394b4
diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py
8394b4
index b9eacfdea..587c7b07b 100644
8394b4
--- a/src/lib389/lib389/utils.py
8394b4
+++ b/src/lib389/lib389/utils.py
8394b4
@@ -1244,9 +1244,10 @@ def get_ldapurl_from_serverid(instance):
8394b4
         return ("ldap://{}:{}".format(host, port), None)
8394b4
 
8394b4
 
8394b4
-def get_instance_list(prefix=None):
8394b4
+def get_instance_list():
8394b4
     # List all server instances
8394b4
-    conf_dir = (prefix or "") + "/etc/dirsrv/"
8394b4
+    paths = Paths()
8394b4
+    conf_dir = os.path.join(paths.sysconf_dir, 'dirsrv')
8394b4
     insts = []
8394b4
     try:
8394b4
         for inst in os.listdir(conf_dir):
8394b4
@@ -1254,6 +1255,9 @@ def get_instance_list(prefix=None):
8394b4
                 insts.append(inst)
8394b4
     except OSError as e:
8394b4
         log.error("Failed to check directory: {} - {}".format(conf_dir, str(e)))
8394b4
+    except IOError as e:
8394b4
+        log.error(e)
8394b4
+        log.error("Perhaps you need to be a different user?")
8394b4
     insts.sort()
8394b4
     return insts
8394b4
 
8394b4
-- 
8394b4
2.21.1
8394b4