Blame SOURCES/sos-bz1393961-missing-filesystem-nonfatal.patch

b939f5
From 4df4897146d4f2a0589a8b32532f912f1ea2ed8c Mon Sep 17 00:00:00 2001
b939f5
From: "Bryn M. Reeves" <bmr@redhat.com>
b939f5
Date: Mon, 22 May 2017 16:30:35 +0100
b939f5
Subject: [PATCH] [policies/redhat] make missing 'filesystem' package non-fatal
b939f5
b939f5
On Red Hat systems, we use the version of the installed filesystem'
b939f5
package to enable handling of UsrMove[1] in the PATH used when
b939f5
running commands from sos.
b939f5
b939f5
If the package is not present (e.g. because of a broken system
b939f5
configuration, rpm timeout, corrupt database or other cause),
b939f5
previous versions would fail immediately. In this situation
b939f5
there was no way for the user to attempt a complete run (short
b939f5
of fixing the problem related to the 'filesystem' package).
b939f5
b939f5
Now that the timeout has been lengthened for this command, make
b939f5
the UsrMove determination a bit more robust to prevent users from
b939f5
being unable to run sos at all:
b939f5
b939f5
  - If RPM fails entirely, exit (plugin enablement tests will fail)
b939f5
  - If RPM succeeds but 'filesystem' is missing assume UsrMove
b939f5
    (this is true for all supported Red Hat distros today)
b939f5
  - Otherwise apply the normal PATH logic.
b939f5
b939f5
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
b939f5
---
b939f5
 sos/policies/redhat.py | 12 ++++++++++--
b939f5
 1 file changed, 10 insertions(+), 2 deletions(-)
b939f5
b939f5
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
b939f5
index b801b5e..ec1d974 100644
b939f5
--- a/sos/policies/redhat.py
b939f5
+++ b/sos/policies/redhat.py
b939f5
@@ -58,13 +58,21 @@ class RedHatPolicy(LinuxPolicy):
b939f5
 
b939f5
         pkgs = self.package_manager.all_pkgs()
b939f5
 
b939f5
-        # If rpm query timed out after timeout duration exit
b939f5
+        # If rpm query failed, exit
b939f5
         if not pkgs:
b939f5
             print("Could not obtain installed package list", file=sys.stderr)
b939f5
             sys.exit(1)
b939f5
 
b939f5
         # handle PATH for UsrMove
b939f5
-        if pkgs['filesystem']['version'][0] == '3':
b939f5
+        if 'filesystem' not in pkgs:
b939f5
+            print("Could not find 'filesystem' package: "
b939f5
+                  "assuming PATH settings")
b939f5
+            usrmove = True
b939f5
+        else:
b939f5
+            filesys_version = pkgs['filesystem']['version']
b939f5
+            usrmove = True if filesys_version[0] == '3' else False
b939f5
+
b939f5
+        if usrmove:
b939f5
             self.PATH = "/usr/sbin:/usr/bin:/root/bin"
b939f5
         else:
b939f5
             self.PATH = "/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
b939f5
-- 
b939f5
2.7.4
b939f5