Bug 1630956

Summary: skydive plugin traceback due to type conversion
Product: Red Hat Enterprise Linux 7 Reporter: Miroslav Hradílek <mhradile>
Component: sosAssignee: Pavel Moravec <pmoravec>
Status: CLOSED ERRATA QA Contact: Miroslav Hradílek <mhradile>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.6CC: agk, bmr, gavin, plambri, sbradley
Target Milestone: rc   
Target Release: 7.7   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: sos-3.7-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-06 13:15:20 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 Miroslav Hradílek 2018-09-19 15:12:36 UTC
Description of problem:
In newly added skydive plugin in sos-3.6-9.el7.noarch there is a set of options that plugin uses to setupp environmental variables for analyzing tool.

Problem is that self.get_option does the implicit type conversion while os.environ expects only string.

Version-Release number of selected component (if applicable):
sos-3.6-9.el7.noarch

How reproducible:
100%

Steps to Reproduce:
sosreport -o skydive -k skydive.username=john -k skydive.password='123' -k skydive.analyzer=localhost --batch --debug

Actual results:
. . .
 Setting up archive ...
 Setting up plugins ...
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1033, in setup
    plug.setup()
  File "/usr/lib/python2.7/site-packages/sos/plugins/skydive.py", line 55, in setup
    os.environ["SKYDIVE_PASSWORD"] = password
  File "/usr/lib64/python2.7/os.py", line 471, in __setitem__
    putenv(key, item)
TypeError: must be string, not int

> /usr/lib64/python2.7/os.py(471)__setitem__()
-> putenv(key, item)
(Pdb) 


Expected results:
Clean run.

Comment 2 Bryn M. Reeves 2018-09-19 15:27:25 UTC
I think this is probably something we can address in a subsequent errata: what's happening here is that the plugin options code is "helpfully" noticing that the string passed in is an integer, and is automatically casting it to a Python 'int' type.

That should only be the case if the "password" is a valid base-10 integer, which hopefully will not be a common case in the field.

There's a straightforward way to hack around this for this specific cases, although it would be better to carry out a review of the automatic type conversion and decide whether it's actually useful or not.

Comment 3 Miroslav Hradílek 2018-09-19 15:30:14 UTC
I agree, that is why I'm suggesting 7.7.

Comment 4 Bryn M. Reeves 2018-09-19 15:31:37 UTC
Works fine with either alpha/mixed strings:

# ./sosreport --batch --debug -o skydive -k skydive.username="qux",skydive.password="password"

sosreport (version 3.6)

This command will collect system configuration and diagnostic
information from this Fedora system. An archive containing the collected
information will be generated in /var/tmp/sos.ppM4se.

For more information on the Fedora Project visit:

  https://fedoraproject.org/

The generated archive may contain data considered sensitive and its
content should be reviewed by the originating organization before being
passed to any third party.

No changes will be made to system configuration.


 Setting up archive ...
 Setting up plugins ...
 Running plugins. Please wait ...

  Starting 1/1   skydive         [Running: skydive]

  Finished running plugins

Creating compressed archive...

Your sosreport has been generated and saved in:
  /var/tmp/sosreport-localhost-2018-09-19-eadnxwl.tar.xz

The checksum is: 7d9a19dfa7787aa59574760b07c9ce6a

Please send this file to your support representative.

And:

# ./sosreport --batch --debug -o skydive -k skydive.username="qux",skydive.password="1passw0rd"

sosreport (version 3.6)

[...]

  Starting 1/1   skydive         [Running: skydive]

  Finished running plugins

Creating compressed archive...

Your sosreport has been generated and saved in:
  /var/tmp/sosreport-localhost-2018-09-19-wrksnus.tar.xz

The checksum is: c72ed77b0def1bc2f89afbbd494aae3b

Please send this file to your support representative.

Comment 5 Pavel Moravec 2018-09-30 19:16:00 UTC
(In reply to Bryn M. Reeves from comment #2)
> I think this is probably something we can address in a subsequent errata:
> what's happening here is that the plugin options code is "helpfully"
> noticing that the string passed in is an integer, and is automatically
> casting it to a Python 'int' type.

We have several plugin options (logs.log_days and pcp.pcplogs at least) that relies on this automatic conversion. While several other plugins (skydive, postgresql at least) are affected by this BZ.

Anyway each opt_parms has its default value in "enabled" field - should not we ensure set_option preserves this type, "only"?

Comment 6 Pavel Moravec 2018-09-30 19:21:15 UTC
Dirty patch for this:

--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -499,6 +499,9 @@ class Plugin(object):
         '''set the named option to value.'''
         for name, parms in zip(self.opt_names, self.opt_parms):
             if name == optionname:
+		defaulttype = type(parms['enabled'])
+		if defaulttype != type(value):
+		    value = (defaulttype)(value)
                 parms['enabled'] = value
                 return True
         else:

Comment 7 Pavel Moravec 2019-03-20 10:38:31 UTC
POSTed to upstream.

Comment 11 errata-xmlrpc 2019-08-06 13:15:20 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:2295