Blame SOURCES/0079-policies-add-container-support-to-Red-Hat-policy.patch

0cd6dc
From 127db5bea3e9409bee9bdbce30af88a42c4e1e60 Mon Sep 17 00:00:00 2001
0cd6dc
From: "Bryn M. Reeves" <bmr@redhat.com>
0cd6dc
Date: Mon, 26 Jan 2015 15:36:40 -0500
0cd6dc
Subject: [PATCH 79/93] [policies] add container support to Red Hat policy
0cd6dc
0cd6dc
Check for the presence of container-specific environment variables
0cd6dc
and set _host_sysroot if present:
0cd6dc
0cd6dc
  container_uuid=UUID
0cd6dc
  HOST=/path
0cd6dc
0cd6dc
If both a container environment variable and HOST are present run
0cd6dc
the PackageManager query command in a chroot.
0cd6dc
0cd6dc
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
0cd6dc
---
0cd6dc
 sos/policies/redhat.py | 23 +++++++++++++++++++++--
0cd6dc
 1 file changed, 21 insertions(+), 2 deletions(-)
0cd6dc
0cd6dc
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
0cd6dc
index 2219246..e85b166 100644
0cd6dc
--- a/sos/policies/redhat.py
0cd6dc
+++ b/sos/policies/redhat.py
0cd6dc
@@ -37,13 +37,17 @@ class RedHatPolicy(LinuxPolicy):
0cd6dc
     vendor = "Red Hat"
0cd6dc
     vendor_url = "http://www.redhat.com/"
0cd6dc
     _tmp_dir = "/var/tmp"
0cd6dc
+    _rpmq_cmd = 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"'
0cd6dc
+    _in_container = False
0cd6dc
+    _host_sysroot = '/'
0cd6dc
 
0cd6dc
     def __init__(self):
0cd6dc
         super(RedHatPolicy, self).__init__()
0cd6dc
         self.report_name = ""
0cd6dc
         self.ticket_number = ""
0cd6dc
-        self.package_manager = PackageManager(
0cd6dc
-            'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"')
0cd6dc
+        # need to set _host_sysroot before PackageManager()
0cd6dc
+        sysroot = self._container_init()
0cd6dc
+        self.package_manager = PackageManager(self._rpmq_cmd, chroot=sysroot)
0cd6dc
         self.valid_subclasses = [RedHatPlugin]
0cd6dc
 
0cd6dc
         # handle PATH for UsrMove
0cd6dc
@@ -62,6 +66,17 @@ class RedHatPolicy(LinuxPolicy):
0cd6dc
         Fedora, RHEL or other Red Hat distribution or False otherwise."""
0cd6dc
         return False
0cd6dc
 
0cd6dc
+    def _container_init(self):
0cd6dc
+        """Check if sos is running in a container and if a host sysroot
0cd6dc
+        has been passed in the environment.
0cd6dc
+        """
0cd6dc
+        if ENV_CONTAINER_UUID in os.environ:
0cd6dc
+            self._in_container = True
0cd6dc
+        if ENV_HOST_SYSROOT in os.environ:
0cd6dc
+            self._host_sysroot = os.environ[ENV_HOST_SYSROOT]
0cd6dc
+        use_sysroot = self._in_container and self._host_sysroot != '/'
0cd6dc
+        return self._host_sysroot if use_sysroot else None
0cd6dc
+
0cd6dc
     def runlevel_by_service(self, name):
0cd6dc
         from subprocess import Popen, PIPE
0cd6dc
         ret = []
0cd6dc
@@ -92,6 +107,10 @@ class RedHatPolicy(LinuxPolicy):
0cd6dc
     def get_local_name(self):
0cd6dc
         return self.host_name()
0cd6dc
 
0cd6dc
+# Container environment variables on Red Hat systems.
0cd6dc
+ENV_CONTAINER_UUID = 'container_uuid'
0cd6dc
+ENV_HOST_SYSROOT = 'HOST'
0cd6dc
+
0cd6dc
 
0cd6dc
 class RHELPolicy(RedHatPolicy):
0cd6dc
     distro = "Red Hat Enterprise Linux"
0cd6dc
-- 
0cd6dc
1.9.3
0cd6dc