diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2021-05-14 16:12:25 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2021-08-02 10:35:40 -0400 |
commit | 7df45d4cc81646fe95234c6c496fc44b6a18d4ed (patch) | |
tree | f4b9d489ce772b3f42ebe4461c9ee5439d6757e1 | |
parent | 22de3d5725efb2cfffadd38f832d56876e4ea4b3 (diff) | |
download | sos-7df45d4cc81646fe95234c6c496fc44b6a18d4ed.tar.gz |
[report] Fix display of default values in --list for magic values
When plugin options use a magic value as a placeholder for logic checks
used during collections, those magic values can be confusing to users
when reported via `--list`.
This was originally limited to the timeout-related options, and was
mitigated by a note in the option description. However, this approach is
not maintainable as more plugin options implement magic values to allow
complex determination of what the actual value should be during an
execution - for example, with the new `--namespaces` option and plugin
options allowing users to override that global value.
Fix the former by implementing a `TIMEOUT_DEFAULT` constant. Fix the
latter by reassigning the internal magic value from `None` to the
implied value of `0`.
Related: #2547
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/report/__init__.py | 14 | ||||
-rw-r--r-- | sos/report/plugins/__init__.py | 17 | ||||
-rw-r--r-- | sos/utilities.py | 4 |
3 files changed, 21 insertions, 14 deletions
diff --git a/sos/report/__init__.py b/sos/report/__init__.py index 4e9e5fcb..16213c0a 100644 --- a/sos/report/__init__.py +++ b/sos/report/__init__.py @@ -18,7 +18,7 @@ from datetime import datetime import glob import sos.report.plugins from sos.utilities import (ImporterHelper, SoSTimeoutError, - sos_get_command_output) + sos_get_command_output, TIMEOUT_DEFAULT) from shutil import rmtree import hashlib from concurrent.futures import ThreadPoolExecutor, TimeoutError @@ -108,8 +108,8 @@ class SoSReport(SoSComponent): 'note': '', 'only_plugins': [], 'preset': 'auto', - 'plugin_timeout': 300, - 'cmd_timeout': 300, + 'plugin_timeout': TIMEOUT_DEFAULT, + 'cmd_timeout': TIMEOUT_DEFAULT, 'profiles': [], 'since': None, 'verify': False, @@ -733,7 +733,10 @@ class SoSReport(SoSComponent): self.ui_log.info(_("The following options are available for ALL " "plugins:")) for opt in self.all_options[0][0]._default_plug_opts: - self.ui_log.info(" %-25s %-15s %s" % (opt[0], opt[3], opt[1])) + val = opt[3] + if val == -1: + val = TIMEOUT_DEFAULT + self.ui_log.info(" %-25s %-15s %s" % (opt[0], val, opt[1])) self.ui_log.info("") self.ui_log.info(_("The following plugin options are available:")) @@ -749,6 +752,9 @@ class SoSReport(SoSComponent): else: tmpopt = optparm["enabled"] + if tmpopt is None: + tmpopt = 0 + self.ui_log.info(" %-25s %-15s %s" % ( plugname + "." + optname, tmpopt, optparm["desc"])) else: diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py index d851ef3e..549a70ef 100644 --- a/sos/report/plugins/__init__.py +++ b/sos/report/plugins/__init__.py @@ -11,8 +11,10 @@ """ This exports methods available for use by plugins for sos """ from sos.utilities import (sos_get_command_output, import_module, grep, - fileobj, tail, is_executable, path_exists, - path_isdir, path_isfile, path_islink, listdir) + fileobj, tail, is_executable, TIMEOUT_DEFAULT, + path_exists, path_isdir, path_isfile, path_islink, + listdir) + import os import glob import re @@ -462,8 +464,8 @@ class Plugin(object): archive = None profiles = () sysroot = '/' - plugin_timeout = 300 - cmd_timeout = 300 + plugin_timeout = TIMEOUT_DEFAULT + cmd_timeout = TIMEOUT_DEFAULT _timeout_hit = False cmdtags = {} filetags = {} @@ -473,11 +475,8 @@ class Plugin(object): predicate = None cmd_predicate = None _default_plug_opts = [ - ('timeout', 'Timeout in seconds for plugin. The default value (-1) ' + - 'defers to the general plugin timeout, 300 seconds', 'fast', -1), - ('cmd-timeout', 'Timeout in seconds for a command execution. The ' + - 'default value (-1) defers to the general cmd timeout, 300 ' + - 'seconds', 'fast', -1), + ('timeout', 'Timeout in seconds for plugin to finish', 'fast', -1), + ('cmd-timeout', 'Timeout in seconds for a command', 'fast', -1), ('postproc', 'Enable post-processing collected plugin data', 'fast', True) ] diff --git a/sos/utilities.py b/sos/utilities.py index 95df19cb..c940e066 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -23,6 +23,8 @@ import io from contextlib import closing from collections import deque +TIMEOUT_DEFAULT = 300 + def tail(filename, number_of_bytes): """Returns the last number_of_bytes of filename""" @@ -102,7 +104,7 @@ def is_executable(command): return any(os.access(path, os.X_OK) for path in candidates) -def sos_get_command_output(command, timeout=300, stderr=False, +def sos_get_command_output(command, timeout=TIMEOUT_DEFAULT, stderr=False, chroot=None, chdir=None, env=None, foreground=False, binary=False, sizelimit=None, poller=None): """Execute a command and return a dictionary of status and output, |