aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2019-01-01 14:17:02 +0100
committerBryn M. Reeves <bmr@redhat.com>2019-03-20 10:13:57 +0000
commita725a319b50057495b6335df2891334aa9b18069 (patch)
treec701608c7aa486e8c6764158a0ce682e9ec2ba62
parent9343fd7c640f6aa371aad2f0e7b0afccff0095cf (diff)
downloadsos-a725a319b50057495b6335df2891334aa9b18069.tar.gz
[plugins] Preserve data type of a plugin option to the default one
Some plugin options rely on the default data type that can be automatically overwritten by Python (e.g. from str to int). The commit preserves the original data type to ensure implicit data type specified in option definition is always used. Resolves: #1526 Related: #1597 Signed-off-by: Pavel Moravec <pmoravec@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/__init__.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 2e30d86b..36efcb0e 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -547,9 +547,19 @@ class Plugin(object):
return (self.opt_names, self.opt_parms)
def set_option(self, optionname, value):
- '''set the named option to value.'''
+ """Set the named option to value. Ensure the original type
+ of the option value is preserved.
+ """
for name, parms in zip(self.opt_names, self.opt_parms):
if name == optionname:
+ # FIXME: ensure that the resulting type of the set option
+ # matches that of the default value. This prevents a string
+ # option from being coerced to int simply because it holds
+ # a numeric value (e.g. a password).
+ # See PR #1526 and Issue #1597
+ defaulttype = type(parms['enabled'])
+ if defaulttype != type(value) and defaulttype != type(None):
+ value = (defaulttype)(value)
parms['enabled'] = value
return True
else: