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

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