diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2015-01-25 14:30:13 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2015-07-08 17:05:20 +0100 |
commit | 9a87cb3415a7a9587828ee40d689439949def1be (patch) | |
tree | 2ebee404257f5d69fa63c0d6378194bc5211af54 | |
parent | 4a0a3f9607006d402713320fc31780fb54556e6a (diff) | |
download | sos-9a87cb3415a7a9587828ee40d689439949def1be.tar.gz |
[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 <bmr@redhat.com>
-rw-r--r-- | sos/sosreport.py | 19 | ||||
-rw-r--r-- | tests/utilities_tests.py | 4 |
2 files changed, 22 insertions, 1 deletions
diff --git a/sos/sosreport.py b/sos/sosreport.py index 580b5bd7..d9abcb8d 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -540,6 +540,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 @@ -630,6 +645,10 @@ 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 to SYSROOT " + "[auto, always, never] (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 9327b1f9..c4646926 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) |