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