From d005366b2af1cc41e1db8beba25ecda953f9ad62 Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Mon, 26 Jan 2015 17:13:24 -0500
Subject: [PATCH 83/93] [policies] pass --sysroot down to policy classes
Policies that don't auto-detect a container environment with a
host file system need to pass the value of --sysroot down to the
PackageManager class in order to obtain package details from the
chroot environment.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
---
sos/policies/__init__.py | 11 ++++++-----
sos/policies/debian.py | 4 ++--
sos/policies/redhat.py | 18 +++++++++++-------
sos/policies/ubuntu.py | 4 ++--
sos/sosreport.py | 2 +-
5 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 287fe55..3dd00df 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -28,7 +28,7 @@ def import_policy(name):
return None
-def load(cache={}):
+def load(cache={}, sysroot=None):
if 'policy' in cache:
return cache.get('policy')
@@ -37,7 +37,7 @@ def load(cache={}):
for module in helper.get_modules():
for policy in import_policy(module):
if policy.check():
- cache['policy'] = policy()
+ cache['policy'] = policy(sysroot=sysroot)
if 'policy' not in cache:
cache['policy'] = GenericPolicy()
@@ -151,7 +151,7 @@ No changes will be made to system configuration.
_in_container = False
_host_sysroot = '/'
- def __init__(self):
+ def __init__(self, sysroot=None):
"""Subclasses that choose to override this initializer should call
super() to ensure that they get the required platform bits attached.
super(SubClass, self).__init__(). Policies that require runtime
@@ -163,6 +163,7 @@ No changes will be made to system configuration.
self.package_manager = PackageManager()
self._valid_subclasses = []
self.set_exec_path()
+ self._host_sysroot = sysroot
def get_valid_subclasses(self):
return [IndependentPlugin] + self._valid_subclasses
@@ -366,8 +367,8 @@ class LinuxPolicy(Policy):
vendor = "None"
PATH = "/bin:/sbin:/usr/bin:/usr/sbin"
- def __init__(self):
- super(LinuxPolicy, self).__init__()
+ def __init__(self, sysroot=None):
+ super(LinuxPolicy, self).__init__(sysroot=sysroot)
def get_preferred_hash_algorithm(self):
checksum = "md5"
diff --git a/sos/policies/debian.py b/sos/policies/debian.py
index 564f5c6..342c7a1 100644
--- a/sos/policies/debian.py
+++ b/sos/policies/debian.py
@@ -16,8 +16,8 @@ class DebianPolicy(LinuxPolicy):
PATH = "/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" \
+ ":/usr/local/sbin:/usr/local/bin"
- def __init__(self):
- super(DebianPolicy, self).__init__()
+ def __init__(self, sysroot=None):
+ super(DebianPolicy, self).__init__(sysroot=sysroot)
self.report_name = ""
self.ticket_number = ""
self.package_manager = PackageManager(
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index e85b166..81ed8ad 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -41,12 +41,16 @@ class RedHatPolicy(LinuxPolicy):
_in_container = False
_host_sysroot = '/'
- def __init__(self):
- super(RedHatPolicy, self).__init__()
+ def __init__(self, sysroot=None):
+ super(RedHatPolicy, self).__init__(sysroot=sysroot)
self.report_name = ""
self.ticket_number = ""
# need to set _host_sysroot before PackageManager()
- sysroot = self._container_init()
+ if sysroot:
+ self._container_init()
+ self._host_sysroot = sysroot
+ else:
+ sysroot = self._container_init()
self.package_manager = PackageManager(self._rpmq_cmd, chroot=sysroot)
self.valid_subclasses = [RedHatPlugin]
@@ -137,8 +141,8 @@ No changes will be made to system configuration.
%(vendor_text)s
""")
- def __init__(self):
- super(RHELPolicy, self).__init__()
+ def __init__(self, sysroot=None):
+ super(RHELPolicy, self).__init__(sysroot=sysroot)
@classmethod
def check(self):
@@ -184,8 +188,8 @@ class FedoraPolicy(RedHatPolicy):
vendor = "the Fedora Project"
vendor_url = "https://fedoraproject.org/"
- def __init__(self):
- super(FedoraPolicy, self).__init__()
+ def __init__(self, sysroot=None):
+ super(FedoraPolicy, self).__init__(sysroot=sysroot)
@classmethod
def check(self):
diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py
index 4c87eca..a3105cf 100644
--- a/sos/policies/ubuntu.py
+++ b/sos/policies/ubuntu.py
@@ -9,8 +9,8 @@ class UbuntuPolicy(DebianPolicy):
vendor = "Ubuntu"
vendor_url = "http://www.ubuntu.com/"
- def __init__(self):
- super(UbuntuPolicy, self).__init__()
+ def __init__(self, sysroot=None):
+ super(UbuntuPolicy, self).__init__(sysroot=sysroot)
self.valid_subclasses = [UbuntuPlugin, DebianPlugin]
@classmethod
diff --git a/sos/sosreport.py b/sos/sosreport.py
index 90be4ca..f0542d9 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -668,7 +668,7 @@ class SoSReport(object):
self._read_config()
try:
- self.policy = sos.policies.load()
+ self.policy = sos.policies.load(sysroot=self.opts.sysroot)
except KeyboardInterrupt:
self._exit(0)
--
1.9.3