|
|
0cd6dc |
From 027ad7291801301c63cd462fb54b0d999063c1b1 Mon Sep 17 00:00:00 2001
|
|
|
0cd6dc |
From: "Bryn M. Reeves" <bmr@redhat.com>
|
|
|
0cd6dc |
Date: Sun, 25 Jan 2015 23:03:08 +0000
|
|
|
0cd6dc |
Subject: [PATCH 63/93] [plugins] add chroot parameter to callout APIs
|
|
|
0cd6dc |
|
|
|
0cd6dc |
Expose sos_get_command_output()'s chroot support to plugins via
|
|
|
0cd6dc |
add_cmd_output(), get_command_output(), call_ext_prog() and
|
|
|
0cd6dc |
related Plugin methods.
|
|
|
0cd6dc |
|
|
|
0cd6dc |
'chroot' is a boolean indicating whether the command should run
|
|
|
0cd6dc |
in the chroot (True) or in the host namespace (False).
|
|
|
0cd6dc |
|
|
|
0cd6dc |
Has no effect when Plugin.use_sysroot() is False.
|
|
|
0cd6dc |
|
|
|
0cd6dc |
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
|
|
|
0cd6dc |
---
|
|
|
0cd6dc |
sos/plugins/__init__.py | 33 ++++++++++++++++++++-------------
|
|
|
0cd6dc |
1 file changed, 20 insertions(+), 13 deletions(-)
|
|
|
0cd6dc |
|
|
|
0cd6dc |
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
|
|
|
0cd6dc |
index 3263eaa..bff11be 100644
|
|
|
0cd6dc |
--- a/sos/plugins/__init__.py
|
|
|
0cd6dc |
+++ b/sos/plugins/__init__.py
|
|
|
0cd6dc |
@@ -492,8 +492,8 @@ class Plugin(object):
|
|
|
0cd6dc |
self._add_copy_paths(copy_paths)
|
|
|
0cd6dc |
self._log_info("added copyspec '%s'" % copy_paths)
|
|
|
0cd6dc |
|
|
|
0cd6dc |
- def get_command_output(self, prog, timeout=300, runat=None):
|
|
|
0cd6dc |
- if self.commons['cmdlineopts'].chroot == 'always':
|
|
|
0cd6dc |
+ def get_command_output(self, prog, timeout=300, chroot=True, runat=None):
|
|
|
0cd6dc |
+ if chroot or self.commons['cmdlineopts'].chroot == 'always':
|
|
|
0cd6dc |
root = self.sysroot
|
|
|
0cd6dc |
else:
|
|
|
0cd6dc |
root = None
|
|
|
0cd6dc |
@@ -507,11 +507,12 @@ class Plugin(object):
|
|
|
0cd6dc |
self._log_debug("could not run '%s': command not found" % prog)
|
|
|
0cd6dc |
return result
|
|
|
0cd6dc |
|
|
|
0cd6dc |
- def call_ext_prog(self, prog, timeout=300, runat=None):
|
|
|
0cd6dc |
+ def call_ext_prog(self, prog, timeout=300, chroot=True, runat=None):
|
|
|
0cd6dc |
"""Execute a command independantly of the output gathering part of
|
|
|
0cd6dc |
sosreport.
|
|
|
0cd6dc |
"""
|
|
|
0cd6dc |
- return self.get_command_output(prog, timeout=timeout, runat=runat)
|
|
|
0cd6dc |
+ return self.get_command_output(prog, timeout=timeout,
|
|
|
0cd6dc |
+ chroot=chroot, runat=runat)
|
|
|
0cd6dc |
|
|
|
0cd6dc |
def check_ext_prog(self, prog):
|
|
|
0cd6dc |
"""Execute a command independently of the output gathering part of
|
|
|
0cd6dc |
@@ -521,15 +522,19 @@ class Plugin(object):
|
|
|
0cd6dc |
return self.call_ext_prog(prog)['status'] == 0
|
|
|
0cd6dc |
|
|
|
0cd6dc |
def add_cmd_output(self, cmds, suggest_filename=None,
|
|
|
0cd6dc |
- root_symlink=None, timeout=300, runat=None):
|
|
|
0cd6dc |
+ root_symlink=None, timeout=300,
|
|
|
0cd6dc |
+ chroot=True, runat=None):
|
|
|
0cd6dc |
"""Run a program or a list of programs and collect the output"""
|
|
|
0cd6dc |
if isinstance(cmds, six.string_types):
|
|
|
0cd6dc |
cmds = [cmds]
|
|
|
0cd6dc |
if len(cmds) > 1 and (suggest_filename or root_symlink):
|
|
|
0cd6dc |
self._log_warn("ambiguous filename or symlink for command list")
|
|
|
0cd6dc |
for cmd in cmds:
|
|
|
0cd6dc |
- cmdt = (cmd, suggest_filename, root_symlink, timeout, runat)
|
|
|
0cd6dc |
- _logstr = "packed command tuple: ('%s', '%s', '%s', %s, '%s')"
|
|
|
0cd6dc |
+ cmdt = (
|
|
|
0cd6dc |
+ cmd, suggest_filename, root_symlink, timeout, chroot, runat
|
|
|
0cd6dc |
+ )
|
|
|
0cd6dc |
+ _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s')"
|
|
|
0cd6dc |
+ _logstr = "packed command tuple: " + _tuplefmt
|
|
|
0cd6dc |
self._log_debug(_logstr % cmdt)
|
|
|
0cd6dc |
self.collect_cmds.append(cmdt)
|
|
|
0cd6dc |
self._log_info("added cmd output '%s'" % cmd)
|
|
|
0cd6dc |
@@ -584,12 +589,13 @@ class Plugin(object):
|
|
|
0cd6dc |
|
|
|
0cd6dc |
def get_cmd_output_now(self, exe, suggest_filename=None,
|
|
|
0cd6dc |
root_symlink=False, timeout=300,
|
|
|
0cd6dc |
- runat=None):
|
|
|
0cd6dc |
+ chroot=True, runat=None):
|
|
|
0cd6dc |
"""Execute a command and save the output to a file for inclusion in the
|
|
|
0cd6dc |
report.
|
|
|
0cd6dc |
"""
|
|
|
0cd6dc |
start = time()
|
|
|
0cd6dc |
- result = self.get_command_output(exe, timeout=timeout, runat=runat)
|
|
|
0cd6dc |
+ result = self.get_command_output(exe, timeout=timeout,
|
|
|
0cd6dc |
+ chroot=chroot, runat=runat)
|
|
|
0cd6dc |
# 126 means 'found but not executable'
|
|
|
0cd6dc |
if result['status'] == 126 or result['status'] == 127:
|
|
|
0cd6dc |
return None
|
|
|
0cd6dc |
@@ -638,13 +644,14 @@ class Plugin(object):
|
|
|
0cd6dc |
|
|
|
0cd6dc |
def _collect_cmd_output(self):
|
|
|
0cd6dc |
for progs in zip(self.collect_cmds):
|
|
|
0cd6dc |
- prog, suggest_filename, root_symlink, timeout, runat = progs[0]
|
|
|
0cd6dc |
+ (prog, suggest_filename, root_symlink, timeout, chroot, runat
|
|
|
0cd6dc |
+ ) = progs[0]
|
|
|
0cd6dc |
self._log_debug("unpacked command tuple: "
|
|
|
0cd6dc |
- + "('%s', '%s', '%s', %s, '%s')" % progs[0])
|
|
|
0cd6dc |
+ + "('%s', '%s', '%s', %s, '%s', '%s')" % progs[0])
|
|
|
0cd6dc |
self._log_info("collecting output of '%s'" % prog)
|
|
|
0cd6dc |
self.get_cmd_output_now(prog, suggest_filename=suggest_filename,
|
|
|
0cd6dc |
- root_symlink=root_symlink,
|
|
|
0cd6dc |
- timeout=timeout, runat=runat)
|
|
|
0cd6dc |
+ root_symlink=root_symlink, timeout=timeout,
|
|
|
0cd6dc |
+ chroot=chroot, runat=runat)
|
|
|
0cd6dc |
|
|
|
0cd6dc |
def _collect_strings(self):
|
|
|
0cd6dc |
for string, file_name in self.copy_strings:
|
|
|
0cd6dc |
--
|
|
|
0cd6dc |
1.9.3
|
|
|
0cd6dc |
|