aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2015-01-26 15:33:18 -0500
committerBryn M. Reeves <bmr@redhat.com>2015-07-08 17:05:21 +0100
commita1a1fd6cfcdb62d7af7744bb5710a2c7d5b4262a (patch)
treee85f136f453fb589d97135dd30eaa5c6c9de9343
parentd7cf8535a3403fe6050e0905bef2b4429e595664 (diff)
downloadsos-a1a1fd6cfcdb62d7af7744bb5710a2c7d5b4262a.tar.gz
[policies] make PackageManager and Policy sysroot-aware
Add methods to Policy to get the host root file system path and to test if sos is running in a container and allow Policy classes to pass a chroot path into the PackageManager constructor in order to obtain package data from the chroot. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/policies/__init__.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 4657614a..cea4c091 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -57,11 +57,14 @@ class PackageManager(object):
query_command = None
timeout = 30
+ chroot = None
- def __init__(self, query_command=None):
+ def __init__(self, query_command=None, chroot=None):
self.packages = {}
if query_command:
self.query_command = query_command
+ if chroot:
+ self.chroot = chroot
def all_pkgs_by_name(self, name):
"""
@@ -93,7 +96,11 @@ class PackageManager(object):
version': 'major.minor.version'}}
"""
if self.query_command:
- pkg_list = shell_out(self.query_command, self.timeout).splitlines()
+ cmd = self.query_command
+ pkg_list = shell_out(
+ cmd, timeout=self.timeout, chroot=self.chroot
+ ).splitlines()
+
for pkg in pkg_list:
if '|' not in pkg:
continue
@@ -145,6 +152,9 @@ No changes will be made to system configuration.
vendor_text = ""
PATH = ""
+ _in_container = False
+ _host_sysroot = '/'
+
def __init__(self):
"""Subclasses that choose to override this initializer should call
super() to ensure that they get the required platform bits attached.
@@ -180,6 +190,14 @@ No changes will be made to system configuration.
"""
return False
+ def in_container(self):
+ """ Returns True if sos is running inside a container environment.
+ """
+ return self._in_container
+
+ def host_sysroot(self):
+ return self._host_sysroot
+
def dist_version(self):
"""
Return the OS version