Blame SOURCES/sos-bz2041855-virsh-in-foreground.patch

819553
From 137abd394f64a63b6633949b5c81159af12038b7 Mon Sep 17 00:00:00 2001
819553
From: Pavel Moravec <pmoravec@redhat.com>
819553
Date: Fri, 14 Jan 2022 20:07:17 +0100
819553
Subject: [PATCH] [report] pass foreground argument to collect_cmd_output
819553
819553
Related to: #2825
819553
819553
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
819553
---
819553
 sos/report/plugins/__init__.py | 12 +++++++++---
819553
 1 file changed, 9 insertions(+), 3 deletions(-)
819553
819553
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py
819553
index 98f163ab9..1bbdf28a4 100644
819553
--- a/sos/report/plugins/__init__.py
819553
+++ b/sos/report/plugins/__init__.py
819553
@@ -1920,6 +1920,8 @@ class Plugin(object):
819553
             :param subdir:              Subdir in plugin directory to save to
819553
             :param changes:             Does this cmd potentially make a change
819553
                                         on the system?
819553
+            :param foreground:          Run the `cmd` in the foreground with a
819553
+                                        TTY
819553
             :param tags:                Add tags in the archive manifest
819553
             :param cmd_as_tag:          Format command string to tag
819553
 
819553
@@ -2145,7 +2147,8 @@ def collect_cmd_output(self, cmd, suggest_filename=None,
819553
                            root_symlink=False, timeout=None,
819553
                            stderr=True, chroot=True, runat=None, env=None,
819553
                            binary=False, sizelimit=None, pred=None,
819553
-                           changes=False, subdir=None, tags=[]):
819553
+                           changes=False, foreground=False, subdir=None,
819553
+                           tags=[]):
819553
         """Execute a command and save the output to a file for inclusion in the
819553
         report, then return the results for further use by the plugin
819553
 
819553
@@ -2188,6 +2191,9 @@ def collect_cmd_output(self, cmd, suggest_filename=None,
819553
                                     on the system?
819553
         :type changes: ``bool``
819553
 
819553
+        :param foreground:          Run the `cmd` in the foreground with a TTY
819553
+        :type foreground: ``bool``
819553
+
819553
         :param tags:                Add tags in the archive manifest
819553
         :type tags: ``str`` or a ``list`` of strings
819553
 
819553
@@ -2206,8 +2212,8 @@ def collect_cmd_output(self, cmd, suggest_filename=None,
819553
         return self._collect_cmd_output(
819553
             cmd, suggest_filename=suggest_filename, root_symlink=root_symlink,
819553
             timeout=timeout, stderr=stderr, chroot=chroot, runat=runat,
819553
-            env=env, binary=binary, sizelimit=sizelimit, subdir=subdir,
819553
-            tags=tags
819553
+            env=env, binary=binary, sizelimit=sizelimit, foreground=foreground,
819553
+            subdir=subdir, tags=tags
819553
         )
819553
 
819553
     def exec_cmd(self, cmd, timeout=None, stderr=True, chroot=True,
819553
From 747fef695e4ff08f320c5f03090bdefa7154c761 Mon Sep 17 00:00:00 2001
819553
From: Pavel Moravec <pmoravec@redhat.com>
819553
Date: Fri, 14 Jan 2022 20:10:22 +0100
819553
Subject: [PATCH] [virsh] Call virsh commands in the foreground / with a TTY
819553
819553
In some virsh errors (like unable to connect to a hypervisor),
819553
the tool requires to communicate to TTY otherwise it can get stuck
819553
(when called via Popen with a timeout).
819553
819553
Calling it on foreground prevents the stuck / waiting on cmd timeout.
819553
819553
Resolves: #2825
819553
819553
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
819553
---
819553
 sos/report/plugins/virsh.py | 14 +++++++++-----
819553
 1 file changed, 9 insertions(+), 5 deletions(-)
819553
819553
diff --git a/sos/report/plugins/virsh.py b/sos/report/plugins/virsh.py
819553
index d6b7c16761..08f9a8488c 100644
819553
--- a/sos/report/plugins/virsh.py
819553
+++ b/sos/report/plugins/virsh.py
819553
@@ -39,26 +39,30 @@ def setup(self):
819553
         ]
819553
 
819553
         for subcmd in subcmds:
819553
-            self.add_cmd_output('%s %s' % (cmd, subcmd))
819553
+            self.add_cmd_output('%s %s' % (cmd, subcmd), foreground=True)
819553
 
819553
         # get network, pool and nwfilter elements
819553
         for k in ['net', 'nwfilter', 'pool']:
819553
-            k_list = self.collect_cmd_output('%s %s-list' % (cmd, k))
819553
+            k_list = self.collect_cmd_output('%s %s-list' % (cmd, k),
819553
+                                             foreground=True)
819553
             if k_list['status'] == 0:
819553
                 k_lines = k_list['output'].splitlines()
819553
                 # the 'Name' column position changes between virsh cmds
819553
                 pos = k_lines[0].split().index('Name')
819553
                 for j in filter(lambda x: x, k_lines[2:]):
819553
                     n = j.split()[pos]
819553
-                    self.add_cmd_output('%s %s-dumpxml %s' % (cmd, k, n))
819553
+                    self.add_cmd_output('%s %s-dumpxml %s' % (cmd, k, n),
819553
+                                        foreground=True)
819553
 
819553
         # cycle through the VMs/domains list, ignore 2 header lines and latest
819553
         # empty line, and dumpxml domain name in 2nd column
819553
-        domains_output = self.exec_cmd('%s list --all' % cmd)
819553
+        domains_output = self.exec_cmd('%s list --all' % cmd, foreground=True)
819553
         if domains_output['status'] == 0:
819553
             domains_lines = domains_output['output'].splitlines()[2:]
819553
             for domain in filter(lambda x: x, domains_lines):
819553
                 d = domain.split()[1]
819553
                 for x in ['dumpxml', 'dominfo', 'domblklist']:
819553
-                    self.add_cmd_output('%s %s %s' % (cmd, x, d))
819553
+                    self.add_cmd_output('%s %s %s' % (cmd, x, d),
819553
+                                        foreground=True)
819553
+
819553
 # vim: et ts=4 sw=4
819553
From 9bc032129ec66766f07349dd115335f104888efa Mon Sep 17 00:00:00 2001
819553
From: Pavel Moravec <pmoravec@redhat.com>
819553
Date: Wed, 26 Jan 2022 09:44:01 +0100
819553
Subject: [PATCH] [virsh] Catch parsing exception
819553
819553
In case virsh output is malformed or missing 'Name' otherwise,
819553
catch parsing exception and continue in next for loop iteration.
819553
819553
Resolves: #2836
819553
819553
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
819553
---
819553
 sos/report/plugins/virsh.py | 6 +++++-
819553
 1 file changed, 5 insertions(+), 1 deletion(-)
819553
819553
diff --git a/sos/report/plugins/virsh.py b/sos/report/plugins/virsh.py
819553
index 08f9a8488..2ce1df15c 100644
819553
--- a/sos/report/plugins/virsh.py
819553
+++ b/sos/report/plugins/virsh.py
819553
@@ -48,7 +48,11 @@ def setup(self):
819553
             if k_list['status'] == 0:
819553
                 k_lines = k_list['output'].splitlines()
819553
                 # the 'Name' column position changes between virsh cmds
819553
-                pos = k_lines[0].split().index('Name')
819553
+                # catch the rare exceptions when 'Name' is not found
819553
+                try:
819553
+                    pos = k_lines[0].split().index('Name')
819553
+                except Exception:
819553
+                    continue
819553
                 for j in filter(lambda x: x, k_lines[2:]):
819553
                     n = j.split()[pos]
819553
                     self.add_cmd_output('%s %s-dumpxml %s' % (cmd, k, n),