diff options
author | Dan Streetman <ddstreet@canonical.com> | 2018-04-10 09:19:15 -0400 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-05-24 14:57:03 +0100 |
commit | 476bd7f324dcfa8189860400bc83e7aaaa86f174 (patch) | |
tree | c64b068b5805156e8e888e3d4fa9945ede2e2373 | |
parent | c8e1dc4951690e709cca32718c07ef7899736039 (diff) | |
download | sos-476bd7f324dcfa8189860400bc83e7aaaa86f174.tar.gz |
[Plugin] Fix string decoding for debug log output
In add_string_as_file and _collect_strings, the first line of each
string is printed to debug log, however there is a bug in
_collect_strings that tries to decode the first line of '...'
instead of the actual string; this causes a error like:
File "/usr/share/sosreport/sos/sosreport.py", line 1300, in collect
plug.collect()
File "/usr/share/sosreport/sos/plugins/__init__.py", line 877, in collect
self._collect_strings()
File "/usr/share/sosreport/sos/plugins/__init__.py", line 860, in _collect_strings
(content.splitlines()[0]).decode('utf8', 'ignore'))
AttributeError: 'str' object has no attribute 'decode'
This simplifies the (string or bytearray)-to-first-line-string of both
functions, which also fixes the bug using the wrong variable to decode.
Fixes: 7ba2fb47d05b608f3863fda9271894e38b43937a
Resolves: #1267
Signed-off-by: Dan Streetman <ddstreet@canonical.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index a21cb5cf..598cc127 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -717,12 +717,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)) - if isinstance(content, six.string_types): - content = "..." + content.splitlines()[0] - else: - content = ("..." + - (content.splitlines()[0]).decode('utf8', 'ignore')) - self._log_debug("added string '%s' as '%s'" % (content, filename)) + 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, root_symlink=False, timeout=300, stderr=True, @@ -883,13 +881,10 @@ class Plugin(object): def _collect_strings(self): for string, file_name in self.copy_strings: - content = "..." - if isinstance(string, six.string_types): - content = "..." + content.splitlines()[0] - else: - content = ("..." + - (content.splitlines()[0]).decode('utf8', 'ignore')) - self._log_info("collecting string '%s' as '%s'" + 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: self.archive.add_string(string, |