diff options
author | Pierguido Lambri <plambri@redhat.com> | 2018-04-28 13:51:41 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-06-22 14:13:15 +0100 |
commit | 0e4fef79f6fcf9a023ec807fb8494cccad81a6f2 (patch) | |
tree | a8ea6532da6cff37ce9abfbdb0508f5433dce06b | |
parent | d03a78cccf0f1b0a1c7b0cb6b698c0656dc10f7b (diff) | |
download | sos-0e4fef79f6fcf9a023ec807fb8494cccad81a6f2.tar.gz |
[sosreport] adds a per-policy package manager file list
Add a 'files' member to the PackageManager class, and a new
'files_command' kwarg to the initialiser. If the 'files_command'
is defined it is used to obtain a list of all package managed
files present on the system.
The list may be retrieved by calling PackageManager.all_files().
An implementation of 'files_command' is added to the Red Hat
policy classes.
Signed-off-by: Pierguido Lambri <plambri@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/policies/__init__.py | 16 | ||||
-rw-r--r-- | sos/policies/redhat.py | 9 |
2 files changed, 24 insertions, 1 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index ca9b181a..45eecfe1 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -64,14 +64,18 @@ class PackageManager(object): verify_command = None verify_filter = None chroot = None + files = None def __init__(self, chroot=None, query_command=None, - verify_command=None, verify_filter=None): + verify_command=None, verify_filter=None, + files_command=None): self.packages = {} + self.files = [] self.query_command = query_command if query_command else None self.verify_command = verify_command if verify_command else None self.verify_filter = verify_filter if verify_filter else None + self.files_command = files_command if files_command else None if chroot: self.chroot = chroot @@ -144,6 +148,16 @@ class PackageManager(object): name = "-".join(fields[:-3]) return (name, version, release, arch) + def all_files(self): + """ + Returns a list of files known by the package manager + """ + if self.files_command and not self.files: + cmd = self.files_command + files = shell_out(cmd, timeout=0, chroot=self.chroot) + self.files = files.splitlines() + return self.files + def build_verify_command(self, packages): """build_verify_command(self, packages) -> str Generate a command to verify the list of packages given diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py index 42f67c5b..5c93d69d 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -37,6 +37,7 @@ class RedHatPolicy(LinuxPolicy): _redhat_release = '/etc/redhat-release' _tmp_dir = "/var/tmp" _rpmq_cmd = 'rpm -qa --queryformat "%{NAME}|%{VERSION}|%{RELEASE}\\n"' + _rpmql_cmd = 'rpm -qal' _rpmv_cmd = 'rpm -V' _rpmv_filter = ["debuginfo", "-devel"] _in_container = False @@ -57,17 +58,25 @@ class RedHatPolicy(LinuxPolicy): self.package_manager = PackageManager(query_command=self._rpmq_cmd, verify_command=self._rpmv_cmd, verify_filter=self._rpmv_filter, + files_command=self._rpmql_cmd, chroot=sysroot) self.valid_subclasses = [RedHatPlugin] pkgs = self.package_manager.all_pkgs() + files = self.package_manager.all_files() # If rpm query failed, exit if not pkgs: print("Could not obtain installed package list", file=sys.stderr) sys.exit(1) + # If the files rpm query failed, exit + if not files: + print("Could not obtain the files list known to the package \ + manager", file=sys.stderr) + sys.exit(1) + # handle PATH for UsrMove if 'filesystem' not in pkgs: print("Could not find 'filesystem' package: " |