Blob Blame History Raw
From 18ae45219c9aa5ed2340a21e9f0aacad62d69242 Mon Sep 17 00:00:00 2001
From: Pavel Moravec <pmoravec@redhat.com>
Date: Sat, 8 Sep 2018 17:39:32 +0200
Subject: [PATCH 1/3] [plugins] fix exception when collecting empty strings

get first line of string to log only for nonempty content

Relevant to: #1422

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
---
 sos/plugins/__init__.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index c87ae19b..6c3b153e 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -746,9 +746,10 @@ class Plugin(object):
     def add_string_as_file(self, content, filename):
         """Add a string to the archive as a file named `filename`"""
         self.copy_strings.append((content, filename))
-        content = content.splitlines()[0]
-        if not isinstance(content, six.string_types):
-            content = content.decode('utf8', 'ignore')
+        if content:
+            content = content.splitlines()[0]
+            if not isinstance(content, six.string_types):
+                content = content.decode('utf8', 'ignore')
         self._log_debug("added string ...'%s' as '%s'" % (content, filename))
 
     def get_cmd_output_now(self, exe, suggest_filename=None,
@@ -948,9 +949,11 @@ class Plugin(object):
 
     def _collect_strings(self):
         for string, file_name in self.copy_strings:
-            content = string.splitlines()[0]
-            if not isinstance(content, six.string_types):
-                content = content.decode('utf8', 'ignore')
+            content = ''
+            if string:
+                content = string.splitlines()[0]
+                if not isinstance(content, six.string_types):
+                    content = content.decode('utf8', 'ignore')
             self._log_info("collecting string ...'%s' as '%s'"
                            % (content, file_name))
             try:
-- 
2.17.2


From 036bbd0fa4c85f97da536717673ca0b668dd5276 Mon Sep 17 00:00:00 2001
From: Pavel Moravec <pmoravec@redhat.com>
Date: Sat, 8 Sep 2018 17:45:09 +0200
Subject: [PATCH 2/3] [juju] catch exceptions when "juju status" command fails

Catch exceptions when "juju status" command:
- does not exist (and generates empty output), or
- does not generate valid/expected JSON output

Resolves: #1422

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
---
 sos/plugins/juju.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sos/plugins/juju.py b/sos/plugins/juju.py
index cbd4a17b..8d996041 100644
--- a/sos/plugins/juju.py
+++ b/sos/plugins/juju.py
@@ -51,7 +51,12 @@ class Juju(Plugin, UbuntuPlugin):
         cmd = "juju status --format json"
         status_json = self.call_ext_prog(cmd)['output']
         self.add_string_as_file(status_json, "juju_status_json")
-        return json_loads(status_json)['services'].keys()
+        # if status_json isn't in JSON format (i.e. 'juju' command not found),
+        # or if it does not contain 'services' key, return empty list
+        try:
+            return json_loads(status_json)['services'].keys()
+        except ValueError:
+            return []
 
     @ensure_service_is_running("juju-db")
     def export_mongodb(self):
-- 
2.17.2


From 549591879a01edcb856f7f353af9d6324d469c39 Mon Sep 17 00:00:00 2001
From: Pavel Moravec <pmoravec@redhat.com>
Date: Mon, 24 Sep 2018 20:09:47 +0200
Subject: [PATCH 3/3] [unpackaged] compare realpaths of files

To compare files in $PATH with files installed from a package, we must
expand all symlinks to their realpaths. Otherwise we get false positives
like /bin/systemctl (as /bin -> /usr/bin).

Resolves: #1437

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
---
 sos/plugins/unpackaged.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sos/plugins/unpackaged.py b/sos/plugins/unpackaged.py
index 4c065e11..91de9de2 100644
--- a/sos/plugins/unpackaged.py
+++ b/sos/plugins/unpackaged.py
@@ -45,9 +45,10 @@ class Unpackaged(Plugin, RedHatPlugin):
                             path = os.path.abspath(os.readlink(path))
                     except Exception:
                         continue
-                    file_list.append(path)
+                    file_list.append(os.path.realpath(path))
                 for name in dirs:
-                    file_list.append(os.path.join(root, name))
+                    file_list.append(os.path.realpath(
+                                     os.path.join(root, name)))
 
             return file_list
 
@@ -63,7 +64,8 @@ class Unpackaged(Plugin, RedHatPlugin):
             return expanded
 
         all_fsystem = []
-        all_frpm = set(self.policy.mangle_package_path(
+        all_frpm = set(os.path.realpath(x)
+                       for x in self.policy.mangle_package_path(
                        self.policy.package_manager.files))
 
         for d in get_env_path_list():
-- 
2.17.2