1
0
forked from rpms/sos
sos/SOURCES/sos-bz2041488-virsh-in-foreground.patch

147 lines
6.5 KiB
Diff
Raw Normal View History

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