From d35b081d38fad259b1da8eae36b3baeb04c0b0ff Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Mon, 26 Jan 2015 15:33:18 -0500
Subject: [PATCH 78/93] [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>
---
sos/policies/__init__.py | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 9fcbd55..287fe55 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -56,11 +56,14 @@ class PackageManager(object):
"""
query_command = None
+ 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):
"""
@@ -92,7 +95,8 @@ class PackageManager(object):
version': 'major.minor.version'}}
"""
if self.query_command:
- pkg_list = shell_out(self.query_command).splitlines()
+ cmd = self.query_command
+ pkg_list = shell_out(cmd, chroot=self.chroot).splitlines()
for pkg in pkg_list:
if '|' not in pkg:
continue
@@ -144,6 +148,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.
@@ -179,6 +186,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
--
1.9.3