aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2015-01-26 15:36:40 -0500
committerBryn M. Reeves <bmr@redhat.com>2015-07-08 17:05:22 +0100
commit63805ed15d63ddfebb06cd03f96f310bbf60d3b2 (patch)
treef5898f7bb4cbb86911cc4c49b548023d64a76f5b
parenta1a1fd6cfcdb62d7af7744bb5710a2c7d5b4262a (diff)
downloadsos-63805ed15d63ddfebb06cd03f96f310bbf60d3b2.tar.gz
[policies] add container support to Red Hat policy
Check for the presence of container-specific environment variables and set _host_sysroot if present: container_uuid=UUID HOST=/path If both a container environment variable and HOST are present run the PackageManager query command in a chroot. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/policies/redhat.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index d2f8db05..f1db8acb 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -38,13 +38,17 @@ class RedHatPolicy(LinuxPolicy):
vendor = "Red Hat"
vendor_url = "http://www.redhat.com/"
_tmp_dir = "/var/tmp"
+ _rpmq_cmd = 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"'
+ _in_container = False
+ _host_sysroot = '/'
def __init__(self):
super(RedHatPolicy, self).__init__()
self.report_name = ""
self.ticket_number = ""
- self.package_manager = PackageManager(
- 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"')
+ # need to set _host_sysroot before PackageManager()
+ sysroot = self._container_init()
+ self.package_manager = PackageManager(self._rpmq_cmd, chroot=sysroot)
self.valid_subclasses = [RedHatPlugin]
pkgs = self.package_manager.all_pkgs()
@@ -70,6 +74,17 @@ class RedHatPolicy(LinuxPolicy):
Fedora, RHEL or other Red Hat distribution or False otherwise."""
return False
+ def _container_init(self):
+ """Check if sos is running in a container and if a host sysroot
+ has been passed in the environment.
+ """
+ if ENV_CONTAINER_UUID in os.environ:
+ self._in_container = True
+ if ENV_HOST_SYSROOT in os.environ:
+ self._host_sysroot = os.environ[ENV_HOST_SYSROOT]
+ use_sysroot = self._in_container and self._host_sysroot != '/'
+ return self._host_sysroot if use_sysroot else None
+
def runlevel_by_service(self, name):
from subprocess import Popen, PIPE
ret = []
@@ -100,6 +115,10 @@ class RedHatPolicy(LinuxPolicy):
def get_local_name(self):
return self.host_name()
+# Container environment variables on Red Hat systems.
+ENV_CONTAINER_UUID = 'container_uuid'
+ENV_HOST_SYSROOT = 'HOST'
+
class RHELPolicy(RedHatPolicy):
distro = "Red Hat Enterprise Linux"