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

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