aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierguido Lambri <plambri@redhat.com>2018-04-28 19:15:39 +0100
committerBryn M. Reeves <bmr@redhat.com>2018-06-22 15:08:11 +0100
commit984cbe8350dbd42eb41ae5f2029976d9d9d008ed (patch)
treeb29f3e89f2fdaadf9ea1d18976d73ab0aa395b11
parent0e4fef79f6fcf9a023ec807fb8494cccad81a6f2 (diff)
downloadsos-984cbe8350dbd42eb41ae5f2029976d9d9d008ed.tar.gz
[sosreport] Add check_usrmove() and mangle_package_path()
This adds two new methods to the class RedHatPolicy. These two methods helps to handle an UsrMove system. In particular mangle_package_path() can be used to substitute the usual /[s]bin references with the real target /usr/[s]bin. Signed-off-by: Pierguido Lambri <plambri@redhat.com>
-rw-r--r--sos/policies/redhat.py43
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.