Bug 1718087

Summary: sosreport fails on name = self.get_local_name().split('.')[0]
Product: Red Hat Enterprise Linux 8 Reporter: Chris Cheney <ccheney>
Component: sosAssignee: Pavel Moravec <pmoravec>
Status: CLOSED ERRATA QA Contact: Martin KlusoĊˆ <mkluson>
Severity: high Docs Contact:
Priority: high    
Version: 8.0CC: agk, bmr, gavin, jhunsaker, jortialc, mhradile, mkluson, mschibli, plambri, sbradley, vinzenz.meier
Target Milestone: rcKeywords: Patch
Target Release: 8.0   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: sos-3.7-2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-11-05 22:32:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Chris Cheney 2019-06-06 20:59:17 UTC
Description of problem:

sosreport fails almost immediately when run on RHEL8


13154 11:14:48.809396 read(5</usr/lib/python3.6/site-packages/sos/policies/__init__.py>, "", 8192) = 0 <0.000003>
13154 11:14:48.809428 close(5</usr/lib/python3.6/site-packages/sos/policies/__init__.py>) = 0 <0.000016>
13154 11:14:48.809494 write(2</dev/pts/0<char 136:0>>, "Traceback (most recent call last):\n", 35) = 35 <0.000048>
13154 11:14:48.809604 write(2</dev/pts/0<char 136:0>>, "  File \"/usr/lib/python3.6/site-packages/sos/sosreport.py\", line 991, in prework\n    self._set_archive()\n", 105) = 105 <0.000043>
13154 11:14:48.809676 write(2</dev/pts/0<char 136:0>>, "  File \"/usr/lib/python3.6/site-packages/sos/sosreport.py\", line 448, in _set_archive\n    self.policy.get_archive_name())\n", 122) = 122 <0.000031>
13154 11:14:48.809733 write(2</dev/pts/0<char 136:0>>, "  File \"/usr/lib/python3.6/site-packages/sos/policies/__init__.py\", line 387, in get_archive_name\n    name = self.get_local_name().split('.')[0]\n", 145) = 145 <0.000029>
13154 11:14:48.809798 write(2</dev/pts/0<char 136:0>>, "TypeError: a bytes-like object is required, not 'str'\n", 54) = 54 <0.000029>
13154 11:14:48.809887 getpid()          = 13154 <0.000003>
13154 11:14:48.809929 write(4</var/tmp/sos.rwoc_ae1/tmp4c0pz6pk>, "2019-06-03 11:14:48,809 ERROR: a bytes-like object is required, not 'str'\n", 74) = 74 <0.000008>
13154 11:14:48.809957 lseek(4</var/tmp/sos.rwoc_ae1/tmp4c0pz6pk>, 0, SEEK_CUR) = 970 <0.000003>
13154 11:14:48.809983 write(1</dev/pts/0<char 136:0>>, "a bytes-like object is required, not 'str'\n", 43) = 43 <0.000024>


The following patch appears to correct the issue:

        --- /usr/lib/python3.6/site-packages/sos/policies/__init__.py   2019-01-21 18:12:16.000000000 +0100
        +++ /usr/lib/python3.6/site-packages/sos/policies/__init__.py 2019-06-05 09:32:22.006000000 +0200
        @@ -384,7 +384,7 @@
                 in the name_pattern in the format accepted by strftime().
 
                 """
        -        name = self.get_local_name().split('.')[0]
        +        name = self.get_local_name().decode().split('.')[0]
                 case = self.case_id
                 label = self.commons['cmdlineopts'].label
                 rand = ''.join(random.choice(string.ascii_lowercase) for x in range(7))

Comment 10 Pavel Moravec 2019-06-13 14:59:12 UTC
Reproducer:

register a RHEL8 system to Satellite5 (i.e. following https://access.redhat.com/solutions/1282753).

Then just run sosreport ..

Comment 11 Jake Hunsaker 2019-06-13 15:27:46 UTC
Interesting. I was under the impression registering RHEL8 against a Sat 5 deployment was unsupported.

In any case, the fix remains the same. +1 to dropping the rhn calls in the redhat policy entirely and just going with hostname.

Comment 12 Pavel Moravec 2019-06-13 19:58:31 UTC
Minimalistic code workaround:

sed -i.orig "s/self.rhn_username() or //g" /usr/lib/python3.6/site-packages/sos/policies/redhat.py

(to revert the change, either reinstall sos package or "/usr/bin/mv /usr/lib/python3.6/site-packages/sos/policies/redhat.py{.orig,}" )

Comment 13 Pavel Moravec 2019-06-14 06:18:07 UTC
The problem happens on RHEL8 or mor precisely with python3, only. Since:

$ python2.7
Python 2.7.15 (default, Oct 15 2018, 15:24:06) 
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 'admin'.encode('utf-8', 'ignore').split('.')[0]
'admin'
>>> 

vs.:

$ python3.6
Python 3.6.8 (default, Mar 21 2019, 10:08:12) 
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 'admin'.encode('utf-8', 'ignore').split('.')[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'
>>>

Comment 14 Pavel Moravec 2019-06-14 06:31:04 UTC
For QE: reproducer without the need to register to sat5 (to mock the registration):

dnf install rhn-setup   # loads some required python libs, from RHEL8 BaseOS and AppStream repos

echo '<?xml version="1.0"?> <params> <param> <value><struct> <member> <name>username</name> <value><string>admin</string></value> </member> </struct></value> </param> </params>' > /etc/sysconfig/rhn/systemid

sosreport  # whatever params

Comment 18 errata-xmlrpc 2019-11-05 22:32:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2019:3640