Blame SOURCES/0057-sosreport-add-chroot-option.patch

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