diff options
-rw-r--r-- | sos/policies/redhat.py | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py index 5c93d69d..3d38be1b 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -12,6 +12,7 @@ from __future__ import print_function import os import sys +import re from sos.plugins import RedHatPlugin from sos.policies import LinuxPolicy, PackageManager, PresetDefaults @@ -48,6 +49,7 @@ class RedHatPolicy(LinuxPolicy): def __init__(self, sysroot=None): super(RedHatPolicy, self).__init__(sysroot=sysroot) self.ticket_number = "" + self.usrmove = False # need to set _host_sysroot before PackageManager() if sysroot: self._container_init() @@ -77,16 +79,9 @@ class RedHatPolicy(LinuxPolicy): manager", file=sys.stderr) sys.exit(1) - # handle PATH for UsrMove - if 'filesystem' not in pkgs: - print("Could not find 'filesystem' package: " - "assuming PATH settings") - usrmove = True - else: - filesys_version = pkgs['filesystem']['version'] - usrmove = True if filesys_version[0] == '3' else False + self.usrmove = self.check_usrmove(pkgs) - if usrmove: + if self.usrmove: self.PATH = "/usr/sbin:/usr/bin:/root/bin" else: self.PATH = "/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" @@ -102,6 +97,36 @@ class RedHatPolicy(LinuxPolicy): Fedora, RHEL or other Red Hat distribution or False otherwise.""" return False + def check_usrmove(self, pkgs): + """Test whether the running system implements UsrMove. + + If the 'filesystem' package is present, it will check that the + version is greater than 3. If the package is not present the + '/bin' and '/sbin' paths are checked and UsrMove is assumed + if both are symbolic links. + + :param pkgs: a packages dictionary + """ + if 'filesystem' not in pkgs: + return os.path.islink('/bin') and os.path.islink('/sbin') + else: + filesys_version = pkgs['filesystem']['version'] + return True if filesys_version[0] == '3' else False + + def mangle_package_path(self, files): + """Mangle paths for post-UsrMove systems. + + If the system implements UsrMove, all files will be in + '/usr/[s]bin'. This method substitutes all the /[s]bin + references in the 'files' list with '/usr/[s]bin'. + + :param files: the list of package managed files + """ + if self.usrmove: + return [re.sub(r'(^)(/s?bin)', r'\1/usr\2', f) for f in files] + else: + return files + def _container_init(self): """Check if sos is running in a container and perform container specific initialisation based on ENV_HOST_SYSROOT. |