|
|
337b9c |
From 0441d340e752427d0d355a85e5e5e465e911a102 Mon Sep 17 00:00:00 2001
|
|
|
337b9c |
From: Tony Asleson <tasleson@redhat.com>
|
|
|
337b9c |
Date: Tue, 29 Nov 2022 10:04:17 -0600
|
|
|
337b9c |
Subject: [PATCH 3/3] lvmdbusd: Add command_log_selection to command line
|
|
|
337b9c |
|
|
|
337b9c |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2145114
|
|
|
337b9c |
(cherry picked from commit e63b0c7262f50ab43fcde1c50b6d880acab68407)
|
|
|
337b9c |
---
|
|
|
337b9c |
daemons/lvmdbusd/cmdhandler.py | 33 +++++++++++++++++----------------
|
|
|
337b9c |
1 file changed, 17 insertions(+), 16 deletions(-)
|
|
|
337b9c |
|
|
|
337b9c |
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
|
|
|
337b9c |
index 0c7bd8528..9a76db4c9 100644
|
|
|
337b9c |
--- a/daemons/lvmdbusd/cmdhandler.py
|
|
|
337b9c |
+++ b/daemons/lvmdbusd/cmdhandler.py
|
|
|
337b9c |
@@ -17,7 +17,7 @@ import os
|
|
|
337b9c |
|
|
|
337b9c |
from lvmdbusd import cfg
|
|
|
337b9c |
from lvmdbusd.utils import pv_dest_ranges, log_debug, log_error, add_no_notify,\
|
|
|
337b9c |
- make_non_block, read_decoded, extract_stack_trace, LvmBug, add_config_option
|
|
|
337b9c |
+ make_non_block, read_decoded, extract_stack_trace, LvmBug, add_config_option, get_error_msg
|
|
|
337b9c |
from lvmdbusd.lvm_shell_proxy import LVMShellProxy
|
|
|
337b9c |
|
|
|
337b9c |
try:
|
|
|
337b9c |
@@ -121,6 +121,9 @@ def call_lvm(command, debug=False, line_cb=None,
|
|
|
337b9c |
command.insert(0, cfg.LVM_CMD)
|
|
|
337b9c |
command = add_no_notify(command)
|
|
|
337b9c |
|
|
|
337b9c |
+ # Ensure we get an error message when we fork & exec the lvm command line
|
|
|
337b9c |
+ command = add_config_option(command, "--config", 'log/command_log_selection="log_context!=''"')
|
|
|
337b9c |
+
|
|
|
337b9c |
process = Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True,
|
|
|
337b9c |
env=os.environ)
|
|
|
337b9c |
|
|
|
337b9c |
@@ -167,7 +170,17 @@ def call_lvm(command, debug=False, line_cb=None,
|
|
|
337b9c |
if debug or (process.returncode != 0 and (process.returncode != 5 and "fullreport" in command)):
|
|
|
337b9c |
_debug_c(command, process.returncode, (stdout_text, stderr_text))
|
|
|
337b9c |
|
|
|
337b9c |
- return process.returncode, stdout_text, stderr_text
|
|
|
337b9c |
+ try:
|
|
|
337b9c |
+ report_json = json.loads(stdout_text)
|
|
|
337b9c |
+ except json.decoder.JSONDecodeError:
|
|
|
337b9c |
+ # Some lvm commands don't return json even though we are asking for it to do so.
|
|
|
337b9c |
+ return process.returncode, stdout_text, stderr_text
|
|
|
337b9c |
+
|
|
|
337b9c |
+ error_msg = get_error_msg(report_json)
|
|
|
337b9c |
+ if error_msg:
|
|
|
337b9c |
+ stderr_text += error_msg
|
|
|
337b9c |
+
|
|
|
337b9c |
+ return process.returncode, report_json, stderr_text
|
|
|
337b9c |
else:
|
|
|
337b9c |
if cfg.run.value == 0:
|
|
|
337b9c |
raise SystemExit
|
|
|
337b9c |
@@ -619,20 +632,8 @@ def lvm_full_report_json():
|
|
|
337b9c |
rc, out, err = call(cmd)
|
|
|
337b9c |
# When we have an exported vg the exit code of lvs or fullreport will be 5
|
|
|
337b9c |
if rc == 0 or rc == 5:
|
|
|
337b9c |
- # If the 'call' implementation is lvmshell, the out is a dictionary as lvmshell has to
|
|
|
337b9c |
- # parse the output to get the exit value. When doing fork & exec, out is a string
|
|
|
337b9c |
- # representing the JSON. TODO: Make this consistent between implementations.
|
|
|
337b9c |
- if cfg.SHELL_IN_USE:
|
|
|
337b9c |
- assert(type(out) == dict)
|
|
|
337b9c |
- return out
|
|
|
337b9c |
- else:
|
|
|
337b9c |
- try:
|
|
|
337b9c |
- return json.loads(out)
|
|
|
337b9c |
- except json.decoder.JSONDecodeError as joe:
|
|
|
337b9c |
- log_error("JSONDecodeError %s, \n JSON=\n%s\n" %
|
|
|
337b9c |
- (str(joe), out))
|
|
|
337b9c |
- raise LvmBug("'fullreport' returned invalid JSON")
|
|
|
337b9c |
-
|
|
|
337b9c |
+ assert(type(out) == dict)
|
|
|
337b9c |
+ return out
|
|
|
337b9c |
raise LvmBug("'fullreport' exited with code '%d'" % rc)
|
|
|
337b9c |
|
|
|
337b9c |
|
|
|
337b9c |
--
|
|
|
337b9c |
2.39.1
|
|
|
337b9c |
|