Blame SOURCES/sos-bz2023481-plugin-timeouts-proper-handling.patch

92cd8f
From 3fea9a564c4112d04f6324df0d8b212e78feb5b3 Mon Sep 17 00:00:00 2001
92cd8f
From: Jake Hunsaker <jhunsake@redhat.com>
92cd8f
Date: Wed, 3 Nov 2021 11:02:54 -0400
92cd8f
Subject: [PATCH] [Plugin] Ensure specific plugin timeouts are only set for
92cd8f
 that plugin
92cd8f
92cd8f
It was discovered that setting a specific plugin timeout via the `-k
92cd8f
$plugin.timeout` option could influence the timeout setting for other
92cd8f
plugins that are not also having their timeout explicitly set. Fix this
92cd8f
by moving the default plugin opts into `Plugin.__init__()` so that each
92cd8f
plugin is ensured a private copy of these default plugin options.
92cd8f
92cd8f
Additionally, add more timeout data to plugin manifest entries to allow
92cd8f
for better tracking of this setting.
92cd8f
92cd8f
Adds a test case for this scenario.
92cd8f
92cd8f
Closes: #2744
92cd8f
92cd8f
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
92cd8f
---
92cd8f
 sos/report/__init__.py                   |  2 +-
92cd8f
 sos/report/plugins/__init__.py           | 28 +++++++++++++------
92cd8f
 tests/vendor_tests/redhat/rhbz2018033.py | 35 ++++++++++++++++++++++++
92cd8f
 3 files changed, 55 insertions(+), 10 deletions(-)
92cd8f
 create mode 100644 tests/vendor_tests/redhat/rhbz2018033.py
92cd8f
92cd8f
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
92cd8f
index ef86b28d..c95e6300 100644
92cd8f
--- a/sos/report/__init__.py
92cd8f
+++ b/sos/report/__init__.py
92cd8f
@@ -766,7 +766,7 @@ class SoSReport(SoSComponent):
92cd8f
         if self.all_options:
92cd8f
             self.ui_log.info(_("The following options are available for ALL "
92cd8f
                                "plugins:"))
92cd8f
-            for opt in self.all_options[0][0]._default_plug_opts:
92cd8f
+            for opt in self.all_options[0][0].get_default_plugin_opts():
92cd8f
                 val = opt[3]
92cd8f
                 if val == -1:
92cd8f
                     val = TIMEOUT_DEFAULT
92cd8f
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py
92cd8f
index 49f1af27..3e717993 100644
92cd8f
--- a/sos/report/plugins/__init__.py
92cd8f
+++ b/sos/report/plugins/__init__.py
92cd8f
@@ -474,12 +474,6 @@ class Plugin(object):
92cd8f
     # Default predicates
92cd8f
     predicate = None
92cd8f
     cmd_predicate = None
92cd8f
-    _default_plug_opts = [
92cd8f
-        ('timeout', 'Timeout in seconds for plugin to finish', 'fast', -1),
92cd8f
-        ('cmd-timeout', 'Timeout in seconds for a command', 'fast', -1),
92cd8f
-        ('postproc', 'Enable post-processing collected plugin data', 'fast',
92cd8f
-         True)
92cd8f
-    ]
92cd8f
 
92cd8f
     def __init__(self, commons):
92cd8f
 
92cd8f
@@ -506,7 +500,7 @@ class Plugin(object):
92cd8f
             else logging.getLogger('sos')
92cd8f
 
92cd8f
         # add the default plugin opts
92cd8f
-        self.option_list.extend(self._default_plug_opts)
92cd8f
+        self.option_list.extend(self.get_default_plugin_opts())
92cd8f
 
92cd8f
         # get the option list into a dictionary
92cd8f
         for opt in self.option_list:
92cd8f
@@ -591,6 +583,14 @@ class Plugin():
92cd8f
         # Initialise the default --dry-run predicate
92cd8f
         self.set_predicate(SoSPredicate(self))
92cd8f
 
92cd8f
+    def get_default_plugin_opts(self):
92cd8f
+        return [
92cd8f
+            ('timeout', 'Timeout in seconds for plugin to finish', 'fast', -1),
92cd8f
+            ('cmd-timeout', 'Timeout in seconds for a command', 'fast', -1),
92cd8f
+            ('postproc', 'Enable post-processing collected plugin data', 'fast',
92cd8f
+             True)
92cd8f
+        ]
92cd8f
+
92cd8f
     def set_plugin_manifest(self, manifest):
92cd8f
         """Pass in a manifest object to the plugin to write to
92cd8f
 
92cd8f
@@ -547,7 +541,9 @@ class Plugin(object):
92cd8f
         self.manifest.add_field('setup_start', '')
92cd8f
         self.manifest.add_field('setup_end', '')
92cd8f
         self.manifest.add_field('setup_time', '')
92cd8f
+        self.manifest.add_field('timeout', self.timeout)
92cd8f
         self.manifest.add_field('timeout_hit', False)
92cd8f
+        self.manifest.add_field('command_timeout', self.cmdtimeout)
92cd8f
         self.manifest.add_list('commands', [])
92cd8f
         self.manifest.add_list('files', [])
92cd8f