Blame SOURCES/sos-bz1904045-preset-ignores-verbosity.patch

f2c821
From 169898b47b26734a8cdcb748157f7314f7f8821b Mon Sep 17 00:00:00 2001
f2c821
From: Erik Bernoth <ebernoth@redhat.com>
f2c821
Date: Tue, 10 Nov 2020 18:32:40 +0100
f2c821
Subject: [PATCH] [component] Add log verbosity from presets
f2c821
f2c821
Closes: #2289
f2c821
f2c821
The main problem this tries to solve was that preset verbosity was
f2c821
ignored in logging.
f2c821
f2c821
With a simple test this could be reproduced:
f2c821
sudo sh -c "source /path/to/repo/sosreport/venv/bin/activate; \
f2c821
            cd /tmp/foo; sos report --preset sostestpreset; cd -"
f2c821
f2c821
The bug is that without a change of code there are no messages from the
f2c821
plugin `host` (no lines of output start wiht "[plugin:host]").
f2c821
f2c821
The problem is that the logging is set in the inherited __init__() method
f2c821
from Component, but the presets are only handled afterwards in the
f2c821
Report's __init__().
f2c821
f2c821
Since it is good to have logging configured from the beginning, the
f2c821
only option is to reconfigure it after the preset config is known.
f2c821
f2c821
The simplest method is to reinitialize the logging, although maybe not
f2c821
the most efficient.
f2c821
f2c821
Signed-off-by: Erik Bernoth <ebernoth@redhat.com>
f2c821
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
f2c821
---
f2c821
 sos/report/__init__.py | 6 ++++++
f2c821
 1 file changed, 6 insertions(+)
f2c821
f2c821
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
f2c821
index 2e97010b..c6b0c21c 100644
f2c821
--- a/sos/report/__init__.py
f2c821
+++ b/sos/report/__init__.py
f2c821
@@ -153,6 +153,12 @@ class SoSReport(SoSComponent):
f2c821
         self.opts.merge(self.preset.opts)
f2c821
         # re-apply any cmdline overrides to the preset
f2c821
         self.opts = self.apply_options_from_cmdline(self.opts)
f2c821
+        if hasattr(self.preset.opts, 'verbosity') and \
f2c821
+            self.preset.opts.verbosity > 0:
f2c821
+            print('\nWARNING: It is not recommended to set verbosity via the '
f2c821
+                  'preset as it might have\nunforseen consequences for your '
f2c821
+                  'report logs.\n')
f2c821
+            self._setup_logging()
f2c821
 
f2c821
         self._set_directories()
f2c821
 
f2c821
-- 
f2c821
2.26.2
f2c821