[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/5] python: qmp_shell: refactor disconnection handling
From: |
Damien Hedde |
Subject: |
[PATCH 3/5] python: qmp_shell: refactor disconnection handling |
Date: |
Mon, 21 Feb 2022 16:55:17 +0100 |
Introduce QMPShellConnectError (subclass of QMPShellError)
to handle disconnection in read_exec_command().
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
python/qemu/aqmp/qmp_shell.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/python/qemu/aqmp/qmp_shell.py b/python/qemu/aqmp/qmp_shell.py
index a1bd7d5630..cce7732ba2 100644
--- a/python/qemu/aqmp/qmp_shell.py
+++ b/python/qemu/aqmp/qmp_shell.py
@@ -142,6 +142,12 @@ class QMPShellParseError(QMPShellError):
"""
+class QMPShellConnectError(QMPShellError):
+ """
+ QMP Shell Connect error class.
+ """
+
+
class FuzzyJSON(ast.NodeTransformer):
"""
This extension of ast.NodeTransformer filters literal "true/false/null"
@@ -347,8 +353,7 @@ def _execute_cmd(self, cmdline: str) -> bool:
self._print(qmpcmd)
resp = self.cmd_obj(qmpcmd)
if resp is None:
- print('Disconnected')
- return False
+ raise QMPShellConnectError('Disconnected')
self._print(resp)
return True
@@ -400,6 +405,9 @@ def read_exec_command(self) -> bool:
return self._execute_cmd(cmdline)
except QMPShellParseError as err:
self._print_parse_error(err)
+ except QMPShellConnectError as err:
+ print(f"{err!s}");
+ return False
return True
def repl(self) -> Iterator[None]:
@@ -481,8 +489,7 @@ def _execute_cmd(self, cmdline: str) -> bool:
raise QMPShellParseError('cpu command takes an integer
argument')
resp = self._cmd_passthrough(cmdline, self._cpu_index)
if resp is None:
- print('Disconnected')
- return False
+ raise QMPShellConnectError('Disconnected')
assert 'return' in resp or 'error' in resp
if 'return' in resp:
# Success
--
2.35.1
- [PATCH 0/5] qmp-shell modifications for non-interactive use, Damien Hedde, 2022/02/21
- [PATCH 1/5] python: qmp_shell: don't prompt when stdin is non-interactive, Damien Hedde, 2022/02/21
- [PATCH 3/5] python: qmp_shell: refactor disconnection handling,
Damien Hedde <=
- [PATCH 2/5] python: qmp_shell: refactor the parsing error handling, Damien Hedde, 2022/02/21
- [PATCH 5/5] python: qmp_shell: handle comment lines and escaped eol, Damien Hedde, 2022/02/21
- [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Damien Hedde, 2022/02/21
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Daniel P . Berrangé, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Daniel P . Berrangé, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Damien Hedde, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23