From becaf70c0a5eb29982b7f7f559fc04b60ca77e99 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Sun, 25 Jan 2015 14:30:13 +0000 Subject: [PATCH 57/93] [sosreport] add --chroot option Add a --chroot option to sosreport to control command chrooting. The option takes one of three values: * auto - Allow callers of the API to control chroot behaviour * always - Always chroot external commands to --sysroot * never - Never chroot external commands This is a fairly low-level option and may not be exposed to the user in a final release; for now it will allow tests in container environments to control the chrooting behaviour used for a run. Signed-off-by: Bryn M. Reeves --- sos/sosreport.py | 18 ++++++++++++++++++ tests/utilities_tests.py | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sos/sosreport.py b/sos/sosreport.py index 21c12ad..0bcc026 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -525,6 +525,21 @@ class SoSOptions(object): self._sysroot = value @property + def chroot(self): + if self._options is not None: + return self._options.chroot + return self._chroot + + @chroot.setter + def chroot(self, value): + self._check_options_initialized() + if value not in ["auto", "always", "never"]: + msg = "SoSOptions.chroot '%s' is not a valid chroot mode: " + msg += "('auto', 'always', 'never')" + raise ValueError(msg % value) + self._chroot = value + + @property def compression_type(self): if self._options is not None: return self._options.compression_type @@ -612,6 +627,9 @@ class SoSOptions(object): parser.add_option("-s", "--sysroot", action="store", dest="sysroot", help="system root directory path (default='/')", default="/") + parser.add_option("-c", "--chroot", action="store", dest="chroot", + help="chroot executed commands (default=auto)", + default="auto") parser.add_option("-z", "--compression-type", dest="compression_type", help="compression technology to use [auto, " "gzip, bzip2, xz] (default=auto)", diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py index def3aed..ecb252a 100644 --- a/tests/utilities_tests.py +++ b/tests/utilities_tests.py @@ -69,7 +69,9 @@ class ExecutableTest(unittest.TestCase): self.assertEquals(result['output'], "") def test_output_chdir(self): - result = sos_get_command_output("/usr/bin/pwd", chdir=TEST_DIR) + cmd = "/bin/bash -c 'echo $PWD'" + result = sos_get_command_output(cmd, chdir=TEST_DIR) + print(result) self.assertEquals(result['status'], 0) self.assertEquals(result['output'].strip(), TEST_DIR) -- 1.9.3