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

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