Blame SOURCES/sos-bz1184602-sos-verify-profile-for-valid-plugins-only.patch

c81b6a
From df219b43b5edab9868cb7d7511f7da1c1f5e225a Mon Sep 17 00:00:00 2001
c81b6a
From: "Bryn M. Reeves" <bmr@redhat.com>
c81b6a
Date: Wed, 1 Jul 2015 14:18:50 +0100
c81b6a
Subject: [PATCH] [general] verify --profile contains valid plugins only
c81b6a
c81b6a
If --profile contains an invalid profile name, stop, and
c81b6a
print the list of available profiles as well as the offending
c81b6a
profile name (helpful when multiple profiles have been specified).
c81b6a
c81b6a
E.g.:
c81b6a
c81b6a
sosreport (version 3.2)
c81b6a
c81b6a
Unknown or inactive profile(s) provided: virtuous
c81b6a
The following profiles are available:
c81b6a
c81b6a
 boot            boot, startup, systemd, udev
c81b6a
 cluster
c81b6a
[...]
c81b6a
c81b6a
Based on a patch from Pavel Moravec.
c81b6a
c81b6a
Fixes #505.
c81b6a
c81b6a
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
c81b6a
---
c81b6a
 sos/sosreport.py | 10 ++++++++++
c81b6a
 1 file changed, 10 insertions(+)
c81b6a
c81b6a
diff --git a/sos/sosreport.py.orig b/sos/sosreport.py
c81b6a
index 7ea7b33..2af9de5 100644
c81b6a
--- a/sos/sosreport.py.orig
c81b6a
+++ b/sos/sosreport.py
c81b6a
@@ -844,6 +844,7 @@ class SoSReport(object):
c81b6a
         self.plugin_names = deque()
c81b6a
         self.profiles = set()
c81b6a
         using_profiles = len(self.opts.profiles)
c81b6a
+        remaining_profiles = list(self.opts.profiles)
c81b6a
         # validate and load plugins
c81b6a
         for plug in plugins:
c81b6a
             plugbase, ext = os.path.splitext(plug)
c81b6a
@@ -896,12 +897,21 @@ class SoSReport(object):
c81b6a
                     self._skip(plugin_class, _("not specified"))
c81b6a
                     continue
c81b6a
 
c81b6a
+                for i in plugin_class.profiles:
c81b6a
+                    if i in remaining_profiles:
c81b6a
+                        remaining_profiles.remove(i)
c81b6a
+
c81b6a
                 self._load(plugin_class)
c81b6a
             except Exception as e:
c81b6a
                 self.soslog.warning(_("plugin %s does not install, "
c81b6a
                                     "skipping: %s") % (plug, e))
c81b6a
                 if self.raise_plugins:
c81b6a
                     raise
c81b6a
+        if len(remaining_profiles) > 0:
c81b6a
+            self.soslog.error(_("Unknown or inactive profile(s) provided:"
c81b6a
+                                " %s") % ", ".join(remaining_profiles))
c81b6a
+            self.list_profiles()
c81b6a
+            self._exit(1)
c81b6a
 
c81b6a
     def _set_all_options(self):
c81b6a
         if self.opts.usealloptions: