|
|
69a90f |
From 27f5e7152444df82eb7a560b1ccef78d40f16296 Mon Sep 17 00:00:00 2001
|
|
|
69a90f |
From: Pavel Moravec <pmoravec@redhat.com>
|
|
|
69a90f |
Date: Fri, 19 Aug 2016 11:19:45 +0200
|
|
|
69a90f |
Subject: [PATCH 1/2] [general] call a command with specified environment
|
|
|
69a90f |
|
|
|
69a90f |
Enable calling commands via add_cmd_output with the possibility to
|
|
|
69a90f |
update environmental variables.
|
|
|
69a90f |
|
|
|
69a90f |
New option 'env' added (None or a dict). When set, it appends to or
|
|
|
69a90f |
overrides os.environ used when calling the command from add_cmd_output.
|
|
|
69a90f |
|
|
|
69a90f |
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
|
|
|
69a90f |
---
|
|
|
69a90f |
sos/plugins/__init__.py | 31 ++++++++++++++++++-------------
|
|
|
69a90f |
sos/utilities.py | 6 +++++-
|
|
|
69a90f |
2 files changed, 23 insertions(+), 14 deletions(-)
|
|
|
69a90f |
|
|
|
69a90f |
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
|
|
|
69a90f |
index 6f86553..c6f1fd7 100644
|
|
|
69a90f |
--- a/sos/plugins/__init__.py
|
|
|
69a90f |
+++ b/sos/plugins/__init__.py
|
|
|
69a90f |
@@ -561,14 +561,15 @@ class Plugin(object):
|
|
|
69a90f |
self._log_info("added copyspec '%s'" % copy_paths)
|
|
|
69a90f |
|
|
|
69a90f |
def get_command_output(self, prog, timeout=300, stderr=True,
|
|
|
69a90f |
- chroot=True, runat=None):
|
|
|
69a90f |
+ chroot=True, runat=None, env=None):
|
|
|
69a90f |
if chroot or self.commons['cmdlineopts'].chroot == 'always':
|
|
|
69a90f |
root = self.sysroot
|
|
|
69a90f |
else:
|
|
|
69a90f |
root = None
|
|
|
69a90f |
|
|
|
69a90f |
result = sos_get_command_output(prog, timeout=timeout, stderr=stderr,
|
|
|
69a90f |
- chroot=root, chdir=runat)
|
|
|
69a90f |
+ chroot=root, chdir=runat,
|
|
|
69a90f |
+ env=env)
|
|
|
69a90f |
|
|
|
69a90f |
if result['status'] == 124:
|
|
|
69a90f |
self._log_warn("command '%s' timed out after %ds"
|
|
|
69a90f |
@@ -582,7 +583,8 @@ class Plugin(object):
|
|
|
69a90f |
"re-trying in host root"
|
|
|
69a90f |
% (prog.split()[0], root))
|
|
|
69a90f |
return self.get_command_output(prog, timeout=timeout,
|
|
|
69a90f |
- chroot=False, runat=runat)
|
|
|
69a90f |
+ chroot=False, runat=runat,
|
|
|
69a90f |
+ env=env)
|
|
|
69a90f |
self._log_debug("could not run '%s': command not found" % prog)
|
|
|
69a90f |
return result
|
|
|
69a90f |
|
|
|
69a90f |
@@ -603,14 +605,14 @@ class Plugin(object):
|
|
|
69a90f |
|
|
|
69a90f |
def _add_cmd_output(self, cmd, suggest_filename=None,
|
|
|
69a90f |
root_symlink=None, timeout=300, stderr=True,
|
|
|
69a90f |
- chroot=True, runat=None):
|
|
|
69a90f |
+ chroot=True, runat=None, env=None):
|
|
|
69a90f |
"""Internal helper to add a single command to the collection list."""
|
|
|
69a90f |
cmdt = (
|
|
|
69a90f |
cmd, suggest_filename,
|
|
|
69a90f |
root_symlink, timeout, stderr,
|
|
|
69a90f |
- chroot, runat
|
|
|
69a90f |
+ chroot, runat, env
|
|
|
69a90f |
)
|
|
|
69a90f |
- _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s', '%s')"
|
|
|
69a90f |
+ _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s')"
|
|
|
69a90f |
_logstr = "packed command tuple: " + _tuplefmt
|
|
|
69a90f |
self._log_debug(_logstr % cmdt)
|
|
|
69a90f |
self.collect_cmds.append(cmdt)
|
|
|
69a90f |
@@ -618,7 +620,7 @@ class Plugin(object):
|
|
|
69a90f |
|
|
|
69a90f |
def add_cmd_output(self, cmds, suggest_filename=None,
|
|
|
69a90f |
root_symlink=None, timeout=300, stderr=True,
|
|
|
69a90f |
- chroot=True, runat=None):
|
|
|
69a90f |
+ chroot=True, runat=None, env=None):
|
|
|
69a90f |
"""Run a program or a list of programs and collect the output"""
|
|
|
69a90f |
if isinstance(cmds, six.string_types):
|
|
|
69a90f |
cmds = [cmds]
|
|
|
69a90f |
@@ -627,7 +629,7 @@ class Plugin(object):
|
|
|
69a90f |
for cmd in cmds:
|
|
|
69a90f |
self._add_cmd_output(cmd, suggest_filename,
|
|
|
69a90f |
root_symlink, timeout, stderr,
|
|
|
69a90f |
- chroot, runat)
|
|
|
69a90f |
+ chroot, runat, env)
|
|
|
69a90f |
|
|
|
69a90f |
def get_cmd_output_path(self, name=None, make=True):
|
|
|
69a90f |
"""Return a path into which this module should store collected
|
|
|
69a90f |
@@ -679,13 +681,14 @@ class Plugin(object):
|
|
|
69a90f |
|
|
|
69a90f |
def get_cmd_output_now(self, exe, suggest_filename=None,
|
|
|
69a90f |
root_symlink=False, timeout=300, stderr=True,
|
|
|
69a90f |
- chroot=True, runat=None):
|
|
|
69a90f |
+ chroot=True, runat=None, env=None):
|
|
|
69a90f |
"""Execute a command and save the output to a file for inclusion in the
|
|
|
69a90f |
report.
|
|
|
69a90f |
"""
|
|
|
69a90f |
start = time()
|
|
|
69a90f |
result = self.get_command_output(exe, timeout=timeout, stderr=stderr,
|
|
|
69a90f |
- chroot=chroot, runat=runat)
|
|
|
69a90f |
+ chroot=chroot, runat=runat,
|
|
|
69a90f |
+ env=env)
|
|
|
69a90f |
# 126 means 'found but not executable'
|
|
|
69a90f |
if result['status'] == 126 or result['status'] == 127:
|
|
|
69a90f |
return None
|
|
|
69a90f |
@@ -807,15 +810,17 @@ class Plugin(object):
|
|
|
69a90f |
suggest_filename, root_symlink,
|
|
|
69a90f |
timeout,
|
|
|
69a90f |
stderr,
|
|
|
69a90f |
- chroot, runat
|
|
|
69a90f |
+ chroot, runat,
|
|
|
69a90f |
+ env
|
|
|
69a90f |
) = progs[0]
|
|
|
69a90f |
self._log_debug("unpacked command tuple: " +
|
|
|
69a90f |
- "('%s', '%s', '%s', %s, '%s', '%s', '%s')" %
|
|
|
69a90f |
+ "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s')" %
|
|
|
69a90f |
progs[0])
|
|
|
69a90f |
self._log_info("collecting output of '%s'" % prog)
|
|
|
69a90f |
self.get_cmd_output_now(prog, suggest_filename=suggest_filename,
|
|
|
69a90f |
root_symlink=root_symlink, timeout=timeout,
|
|
|
69a90f |
- stderr=stderr, chroot=chroot, runat=runat)
|
|
|
69a90f |
+ stderr=stderr, chroot=chroot, runat=runat,
|
|
|
69a90f |
+ env=env)
|
|
|
69a90f |
|
|
|
69a90f |
def _collect_strings(self):
|
|
|
69a90f |
for string, file_name in self.copy_strings:
|
|
|
69a90f |
diff --git a/sos/utilities.py b/sos/utilities.py
|
|
|
69a90f |
index 588cb3f..bc998fa 100644
|
|
|
69a90f |
--- a/sos/utilities.py
|
|
|
69a90f |
+++ b/sos/utilities.py
|
|
|
69a90f |
@@ -110,7 +110,7 @@ def is_executable(command):
|
|
|
69a90f |
|
|
|
69a90f |
|
|
|
69a90f |
def sos_get_command_output(command, timeout=300, stderr=False,
|
|
|
69a90f |
- chroot=None, chdir=None):
|
|
|
69a90f |
+ chroot=None, chdir=None, env=None):
|
|
|
69a90f |
"""Execute a command and return a dictionary of status and output,
|
|
|
69a90f |
optionally changing root or current working directory before
|
|
|
69a90f |
executing command.
|
|
|
69a90f |
@@ -127,6 +127,10 @@ def sos_get_command_output(command, timeout=300, stderr=False,
|
|
|
69a90f |
cmd_env = os.environ
|
|
|
69a90f |
# ensure consistent locale for collected command output
|
|
|
69a90f |
cmd_env['LC_ALL'] = 'C'
|
|
|
69a90f |
+ # optionally add an environment change for the command
|
|
|
69a90f |
+ if env:
|
|
|
69a90f |
+ for key, value in env.iteritems():
|
|
|
69a90f |
+ cmd_env[key] = value
|
|
|
69a90f |
# use /usr/bin/timeout to implement a timeout
|
|
|
69a90f |
if timeout and is_executable("timeout"):
|
|
|
69a90f |
command = "timeout %ds %s" % (timeout, command)
|
|
|
69a90f |
--
|
|
|
69a90f |
2.4.11
|
|
|
69a90f |
|
|
|
69a90f |
From 57fdeaaad3436f374f4a68dbfef686c5dd8b4d5b Mon Sep 17 00:00:00 2001
|
|
|
69a90f |
From: Pavel Moravec <pmoravec@redhat.com>
|
|
|
69a90f |
Date: Fri, 19 Aug 2016 11:20:55 +0200
|
|
|
69a90f |
Subject: [PATCH 2/2] [grub2] grub2-mkconfig loads ext4 and brctl kernel
|
|
|
69a90f |
modules
|
|
|
69a90f |
|
|
|
69a90f |
Call grub2-mkconfig with GRUB_DISABLE_OS_PROBER=true to prevent
|
|
|
69a90f |
explicit loading of the kernel modules.
|
|
|
69a90f |
|
|
|
69a90f |
Resolves: #822
|
|
|
69a90f |
|
|
|
69a90f |
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
|
|
|
69a90f |
---
|
|
|
69a90f |
sos/plugins/grub2.py | 11 +++++++----
|
|
|
69a90f |
1 file changed, 7 insertions(+), 4 deletions(-)
|
|
|
69a90f |
|
|
|
69a90f |
diff --git a/sos/plugins/grub2.py b/sos/plugins/grub2.py
|
|
|
69a90f |
index d321494..a98d3d0 100644
|
|
|
69a90f |
--- a/sos/plugins/grub2.py
|
|
|
69a90f |
+++ b/sos/plugins/grub2.py
|
|
|
69a90f |
@@ -33,10 +33,13 @@ class Grub2(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
|
|
|
69a90f |
"/etc/grub2.cfg",
|
|
|
69a90f |
"/etc/grub.d"
|
|
|
69a90f |
])
|
|
|
69a90f |
- self.add_cmd_output([
|
|
|
69a90f |
- "ls -lanR /boot",
|
|
|
69a90f |
- "grub2-mkconfig"
|
|
|
69a90f |
- ])
|
|
|
69a90f |
+
|
|
|
69a90f |
+ self.add_cmd_output("ls -lanR /boot")
|
|
|
69a90f |
+ # call grub2-mkconfig with GRUB_DISABLE_OS_PROBER=true to prevent
|
|
|
69a90f |
+ # possible unwanted loading of some kernel modules
|
|
|
69a90f |
+ env = {}
|
|
|
69a90f |
+ env['GRUB_DISABLE_OS_PROBER'] = 'true'
|
|
|
69a90f |
+ self.add_cmd_output("grub2-mkconfig", env=env)
|
|
|
69a90f |
|
|
|
69a90f |
def postproc(self):
|
|
|
69a90f |
# the trailing space is required; python treats '_' as whitespace
|
|
|
69a90f |
--
|
|
|
69a90f |
2.4.11
|
|
|
69a90f |
|