Blame SOURCES/sos-bz1030553-fix-command-output-substitution-exception.patch

629484
From c6e2ab3f1e941ececc7a461fd46a1a40041ad2b5 Mon Sep 17 00:00:00 2001
629484
From: "Bryn M. Reeves" <bmr@redhat.com>
629484
Date: Sun, 6 Oct 2013 15:01:23 +0100
629484
Subject: [PATCH 1/3] Fix exception in command output substitution
629484
629484
If an attempt is made to apply command output substitution via
629484
Plugin.do_cmd_output_sub() and no output has been collected (i.e.
629484
called['file'] == None) an exception is thrown by os.path.join().
629484
629484
The exception is also not logged properly due to an attempt in
629484
the do_cmd_output_sub() exception handler to access an unbound
629484
local variable (path - the exception occurs before it is
629484
assigned).
629484
629484
Fix both of these by checking for an empty file entry and avoiding
629484
access to the path variable from the exception handler.
629484
629484
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
629484
---
629484
 sos/plugins/__init__.py | 5 ++++-
629484
 1 file changed, 4 insertions(+), 1 deletion(-)
629484
629484
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
629484
index 4a72161..fc3a851 100644
629484
--- a/sos/plugins/__init__.py
629484
+++ b/sos/plugins/__init__.py
629484
@@ -180,6 +180,9 @@ class Plugin(object):
629484
 
629484
         try:
629484
             for called in self.executed_commands:
629484
+                # was anything collected?
629484
+                if called['file'] == None:
629484
+                    continue
629484
                 if fnmatch.fnmatch(called['exe'], globstr):
629484
                     path = os.path.join(self.commons['cmddir'], called['file'])
629484
                     self.soslog.debug("applying substitution to %s" % path)
629484
@@ -192,7 +195,7 @@ class Plugin(object):
629484
                         replacements = 0
629484
         except Exception, e:
629484
             msg = 'regex substitution failed for %s in plugin %s with: "%s"'
629484
-            self.soslog.error(msg % (path, self.name(), e))
629484
+            self.soslog.error(msg % (called['exe'], self.name(), e))
629484
             replacements = 0
629484
         if self.commons['cmdlineopts'].profiler:
629484
             time_passed = time() - start_time
629484
-- 
629484
1.7.11.7
629484
629484
629484
From dafcbf33022ee2be24109c6c90bae97a1a4a2077 Mon Sep 17 00:00:00 2001
629484
From: "Bryn M. Reeves" <bmr@redhat.com>
629484
Date: Tue, 11 Feb 2014 16:53:16 +0000
629484
Subject: [PATCH 2/3] Fix command output substitution exception
629484
629484
If a comand has a substitution registered via do_cmd_output_sub()
629484
but no data was collected (e.g. command not found) the postproc
629484
code will throw an exception as the return value ('replacements')
629484
is never assigned.
629484
629484
Initialise replacements to None before scanning the list of run
629484
commands and return this if no substitutions were made.
629484
629484
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
629484
629484
Conflicts:
629484
	sos/plugins/__init__.py
629484
---
629484
 sos/plugins/__init__.py | 9 +++++----
629484
 1 file changed, 5 insertions(+), 4 deletions(-)
629484
629484
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
629484
index fc3a851..2bf8d98 100644
629484
--- a/sos/plugins/__init__.py
629484
+++ b/sos/plugins/__init__.py
629484
@@ -178,6 +178,7 @@ class Plugin(object):
629484
         if not self.executed_commands:
629484
             return 0
629484
 
629484
+        replacements = None
629484
         try:
629484
             for called in self.executed_commands:
629484
                 # was anything collected?
629484
@@ -191,12 +192,12 @@ class Plugin(object):
629484
                             regexp, subst, readable.read())
629484
                     if replacements:
629484
                         self.archive.add_string(result, path)
629484
-                    else:
629484
-                        replacements = 0
629484
-        except Exception, e:
629484
+
629484
+        except Exception as e:
629484
             msg = 'regex substitution failed for %s in plugin %s with: "%s"'
629484
             self.soslog.error(msg % (called['exe'], self.name(), e))
629484
-            replacements = 0
629484
+            replacements = None
629484
+
629484
         if self.commons['cmdlineopts'].profiler:
629484
             time_passed = time() - start_time
629484
             self.proflog.debug("subst: %-75s time: %f"
629484
-- 
629484
1.7.11.7
629484
629484
629484
From 59e7695c52ef77b9045e0f1737672728e6b0275a Mon Sep 17 00:00:00 2001
629484
From: "Bryn M. Reeves" <bmr@redhat.com>
629484
Date: Tue, 11 Feb 2014 16:56:37 +0000
629484
Subject: [PATCH 3/3] Improve error message when cluster.crm_from is invalid
629484
629484
If a user passes a non-date string value as the crm_from parameter
629484
of the cluster plugin an error message is logged:
629484
629484
  crm_from parameter 'True' is not a valid date
629484
629484
The plugin continues to run and uses the default value (T-72hrs)
629484
as the value of crm_from. Make this clear in the message displayed
629484
to users:
629484
629484
  crm_from parameter 'True' is not a valid date: using default
629484
629484
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
629484
---
629484
 sos/plugins/cluster.py | 3 ++-
629484
 1 file changed, 2 insertions(+), 1 deletion(-)
629484
629484
diff --git a/sos/plugins/cluster.py b/sos/plugins/cluster.py
629484
index eeacdab..8d73dc1 100644
629484
--- a/sos/plugins/cluster.py
629484
+++ b/sos/plugins/cluster.py
629484
@@ -93,7 +93,8 @@ class Cluster(Plugin, RedHatPlugin):
629484
                         str(self.get_option('crm_from'))):
629484
                 crm_from = self.get_option('crm_from')
629484
             else:
629484
-                self.soslog.error("crm_from parameter '%s' is not a valid date"
629484
+                self.soslog.error(
629484
+                    "crm_from parameter '%s' is not a valid date: using default"
629484
                             % self.get_option('crm_from'))
629484
 
629484
         crm_dest = os.path.join(self.get_cmd_dir(), 'crm_report')
629484
-- 
629484
1.7.11.7
629484