1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

lvmdbusd: Move get_error_msg to utils

Moving this so we can re-use outside of lvm_shell_proxy.
This commit is contained in:
Tony Asleson 2022-11-29 10:00:39 -06:00
parent 61917fbac2
commit 8f60c49451
2 changed files with 20 additions and 20 deletions

View File

@ -28,7 +28,7 @@ except ImportError:
import lvmdbusd.cfg as cfg import lvmdbusd.cfg as cfg
from lvmdbusd.utils import log_debug, log_error, add_no_notify, make_non_block,\ from lvmdbusd.utils import log_debug, log_error, add_no_notify, make_non_block,\
read_decoded, extract_stack_trace, LvmBug read_decoded, extract_stack_trace, LvmBug, get_error_msg
SHELL_PROMPT = "lvm> " SHELL_PROMPT = "lvm> "
@ -191,24 +191,7 @@ class LVMShellProxy(object):
def get_last_log(self): def get_last_log(self):
self._write_cmd('lastlog\n') self._write_cmd('lastlog\n')
report_json = self._read_response()[1] report_json = self._read_response()[1]
return LVMShellProxy.get_error_msg(report_json) return get_error_msg(report_json)
@staticmethod
def get_error_msg(report_json):
# Get the error message from the returned JSON
if 'log' in report_json:
error_msg = ""
# Walk the entire log array and build an error string
for log_entry in report_json['log']:
if log_entry['log_type'] == "error":
if error_msg:
error_msg += ', ' + log_entry['log_message']
else:
error_msg = log_entry['log_message']
return error_msg
return None
def call_lvm(self, argv, debug=False): def call_lvm(self, argv, debug=False):
rc = 1 rc = 1
@ -245,7 +228,7 @@ class LVMShellProxy(object):
# report json too. # report json too.
error_msg = self.get_last_log() error_msg = self.get_last_log()
if error_msg is None: if error_msg is None:
error_msg = LVMShellProxy.get_error_msg(report_json) error_msg = get_error_msg(report_json)
if error_msg is None: if error_msg is None:
error_msg = 'No error reason provided! (missing "log" section)' error_msg = 'No error reason provided! (missing "log" section)'

View File

@ -859,3 +859,20 @@ class LvmDebugData:
self._close_fd() self._close_fd()
# In case lvm_complete doesn't get called. # In case lvm_complete doesn't get called.
self._remove_file() self._remove_file()
def get_error_msg(report_json):
# Get the error message from the returned JSON
if 'log' in report_json:
error_msg = ""
# Walk the entire log array and build an error string
for log_entry in report_json['log']:
if log_entry['log_type'] == "error":
if error_msg:
error_msg += ', ' + log_entry['log_message']
else:
error_msg = log_entry['log_message']
return error_msg
return None