Blame SOURCES/sos-plugins-allow-discard-stderr.patch

c81b6a
From 7b2885740216f8e4076781e088d37cb7b4f96f63 Mon Sep 17 00:00:00 2001
c81b6a
From: John Haxby <john.haxby@oracle.com>
c81b6a
Date: Wed, 28 Jan 2015 19:30:29 +0000
c81b6a
Subject: [PATCH] [plugins,utilities] Allow commands to discard stderr
c81b6a
c81b6a
Just add "stderr=False" to add_cmd_output() if you don't want the
c81b6a
command's stderr in the sosreport.
c81b6a
c81b6a
Signed-off-by: John Haxby <john.haxby@oracle.com>
c81b6a
c81b6a
Minor edits for pep8 conformance and to shorten the argument name.
c81b6a
c81b6a
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
c81b6a
---
c81b6a
 sos/plugins/__init__.py | 29 +++++++++++++++++------------
c81b6a
 sos/utilities.py        |  5 +++--
c81b6a
 2 files changed, 20 insertions(+), 14 deletions(-)
c81b6a
---
c81b6a
 sos/plugins/__init__.py | 33 +++++++++++++++++++++------------
c81b6a
 sos/utilities.py        |  5 +++--
c81b6a
 2 files changed, 24 insertions(+), 14 deletions(-)
c81b6a
c81b6a
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
c81b6a
index 4fd85be..9d126a5 100644
c81b6a
--- a/sos/plugins/__init__.py
c81b6a
+++ b/sos/plugins/__init__.py
c81b6a
@@ -460,8 +460,9 @@ class Plugin(object):
c81b6a
             self.copy_paths.update(copy_paths)
c81b6a
             self._log_info("added copyspec '%s'" % copyspec)
c81b6a
 
c81b6a
-    def get_command_output(self, prog, timeout=300, runat=None):
c81b6a
-        result = sos_get_command_output(prog, timeout=timeout, runat=runat)
c81b6a
+    def get_command_output(self, prog, timeout=300, runat=None, stderr=True):
c81b6a
+        result = sos_get_command_output(prog, timeout=timeout, runat=runat,
c81b6a
+                                        stderr=stderr)
c81b6a
         if result['status'] == 124:
c81b6a
             self._log_warn("command '%s' timed out after %ds"
c81b6a
                            % (prog, timeout))
c81b6a
@@ -470,11 +471,12 @@ class Plugin(object):
c81b6a
             self._log_debug("could not run '%s': command not found" % prog)
c81b6a
         return result
c81b6a
 
c81b6a
-    def call_ext_prog(self, prog, timeout=300, runat=None):
c81b6a
+    def call_ext_prog(self, prog, timeout=300, runat=None, stderr=True):
c81b6a
         """Execute a command independantly of the output gathering part of
c81b6a
         sosreport.
c81b6a
         """
c81b6a
-        return self.get_command_output(prog, timeout=timeout, runat=runat)
c81b6a
+        return self.get_command_output(prog, timeout=timeout, runat=runat,
c81b6a
+                                       stderr=True)
c81b6a
 
c81b6a
     def check_ext_prog(self, prog):
c81b6a
         """Execute a command independently of the output gathering part of
c81b6a
@@ -484,15 +486,19 @@ class Plugin(object):
c81b6a
         return self.call_ext_prog(prog)['status'] == 0
c81b6a
 
c81b6a
     def add_cmd_output(self, cmds, suggest_filename=None,
c81b6a
-                       root_symlink=None, timeout=300, runat=None):
c81b6a
+                       root_symlink=None, timeout=300, runat=None,
c81b6a
+                       stderr=True):
c81b6a
         """Run a program or a list of programs and collect the output"""
c81b6a
         if isinstance(cmds, six.string_types):
c81b6a
             cmds = [cmds]
c81b6a
         if len(cmds) > 1 and (suggest_filename or root_symlink):
c81b6a
             self._log_warn("ambiguous filename or symlink for command list")
c81b6a
         for cmd in cmds:
c81b6a
-            cmdt = (cmd, suggest_filename, root_symlink, timeout, runat)
c81b6a
-            _logstr = "packed command tuple: ('%s', '%s', '%s', %s, '%s')"
c81b6a
+            cmdt = (
c81b6a
+                cmd, suggest_filename, root_symlink, timeout, runat, stderr
c81b6a
+            )
c81b6a
+            _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s')"
c81b6a
+            _logstr = "packed command tuple: " + _tuplefmt
c81b6a
             self._log_debug(_logstr % cmdt)
c81b6a
             self.collect_cmds.append(cmdt)
c81b6a
             self._log_info("added cmd output '%s'" % cmd)
c81b6a
@@ -547,12 +553,13 @@ class Plugin(object):
c81b6a
 
c81b6a
     def get_cmd_output_now(self, exe, suggest_filename=None,
c81b6a
                            root_symlink=False, timeout=300,
c81b6a
-                           runat=None):
c81b6a
+                           runat=None, stderr=True):
c81b6a
         """Execute a command and save the output to a file for inclusion in the
c81b6a
         report.
c81b6a
         """
c81b6a
         start = time()
c81b6a
-        result = self.get_command_output(exe, timeout=timeout, runat=runat)
c81b6a
+        result = self.get_command_output(exe, timeout=timeout, runat=runat,
c81b6a
+                                         stderr=stderr)
c81b6a
         # 126 means 'found but not executable'
c81b6a
         if result['status'] == 126 or result['status'] == 127:
c81b6a
             return None
c81b6a
@@ -601,13 +608,15 @@ class Plugin(object):
c81b6a
 
c81b6a
     def _collect_cmd_output(self):
c81b6a
         for progs in zip(self.collect_cmds):
c81b6a
-            prog, suggest_filename, root_symlink, timeout, runat = progs[0]
c81b6a
+            (prog, suggest_filename, root_symlink, timeout, runat, stderr
c81b6a
+             ) = progs[0]
c81b6a
             self._log_debug("unpacked command tuple: "
c81b6a
-                            + "('%s', '%s', '%s', %s, '%s')" % progs[0])
c81b6a
+                            + "('%s', '%s', '%s', %s, '%s', %s)" % progs[0])
c81b6a
             self._log_info("collecting output of '%s'" % prog)
c81b6a
             self.get_cmd_output_now(prog, suggest_filename=suggest_filename,
c81b6a
                                     root_symlink=root_symlink,
c81b6a
-                                    timeout=timeout, runat=runat)
c81b6a
+                                    timeout=timeout, runat=runat,
c81b6a
+                                    stderr=stderr)
c81b6a
 
c81b6a
     def _collect_strings(self):
c81b6a
         for string, file_name in self.copy_strings:
c81b6a
diff --git a/sos/utilities.py b/sos/utilities.py
c81b6a
index 2638ce4..db340f8 100644
c81b6a
--- a/sos/utilities.py
c81b6a
+++ b/sos/utilities.py
c81b6a
@@ -120,7 +120,7 @@ def is_executable(command):
c81b6a
     return any(os.access(path, os.X_OK) for path in candidates)
c81b6a
 
c81b6a
 
c81b6a
-def sos_get_command_output(command, timeout=300, runat=None):
c81b6a
+def sos_get_command_output(command, timeout=300, runat=None, stderr=True):
c81b6a
     """Execute a command through the system shell. First checks to see if the
c81b6a
     requested command is executable. Returns (returncode, stdout, 0)"""
c81b6a
     def _child_chdir():
c81b6a
@@ -142,7 +142,8 @@ def sos_get_command_output(command, timeout=300, runat=None):
c81b6a
         command = command.encode('utf-8', 'ignore')
c81b6a
     args = shlex.split(command)
c81b6a
     try:
c81b6a
-        p = Popen(args, shell=False, stdout=PIPE, stderr=STDOUT,
c81b6a
+        p = Popen(args, shell=False, stdout=PIPE,
c81b6a
+                  stderr=STDOUT if stderr else PIPE,
c81b6a
                   bufsize=-1, env=cmd_env, close_fds=True,
c81b6a
                   preexec_fn=_child_chdir)
c81b6a
     except OSError as e:
c81b6a
-- 
c81b6a
1.8.3.1
c81b6a