diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2015-01-26 17:13:24 -0500 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2015-07-08 17:05:22 +0100 |
commit | 6a239ddeb5de9a04e7e7081ea6425d89dddda3f5 (patch) | |
tree | 35d1fe0a2831af5aaf6829b01c8fc5efd99dd53b | |
parent | fac57721ae10dafec909c4fac408f42ebe23d4ac (diff) | |
download | sos-6a239ddeb5de9a04e7e7081ea6425d89dddda3f5.tar.gz |
[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>
-rw-r--r-- | sos/policies/__init__.py | 11 | ||||
-rw-r--r-- | sos/policies/debian.py | 4 | ||||
-rw-r--r-- | sos/policies/redhat.py | 18 | ||||
-rw-r--r-- | sos/policies/ubuntu.py | 4 | ||||
-rw-r--r-- | sos/sosreport.py | 2 |
5 files changed, 22 insertions, 17 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index cea4c091..a403bb92 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() @@ -155,7 +155,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 @@ -167,6 +167,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 @@ -372,8 +373,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 acb5b85d..e56e546b 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 f1db8acb..f20359d7 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -42,12 +42,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] @@ -145,8 +149,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): @@ -192,8 +196,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 0dd2ea29..f2364219 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 835d8281..ad13a2d2 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -687,7 +687,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) |