[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/19] python/qmp.py: re-absorb MonitorResponseError
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 16/19] python/qmp.py: re-absorb MonitorResponseError |
Date: |
Wed, 15 Jul 2020 00:21:29 +0200 |
From: John Snow <jsnow@redhat.com>
When I initially split this out, I considered this more of a machine
error than a QMP protocol error, but I think that's misguided.
Move this back to qmp.py and name it QMPResponseError. Convert
qmp.command() to use this exception type.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200710052220.3306-4-jsnow@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
python/qemu/machine.py | 15 +--------------
python/qemu/qmp.py | 17 +++++++++++++++--
scripts/render_block_graph.py | 7 +++++--
3 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 69055189bd..80c4d4a8b6 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -56,19 +56,6 @@ class AbnormalShutdown(QEMUMachineError):
"""
-class MonitorResponseError(qmp.QMPError):
- """
- Represents erroneous QMP monitor reply
- """
- def __init__(self, reply):
- try:
- desc = reply["error"]["desc"]
- except KeyError:
- desc = reply
- super().__init__(desc)
- self.reply = reply
-
-
class QEMUMachine:
"""
A QEMU VM
@@ -533,7 +520,7 @@ def command(self, cmd, conv_keys=True, **args):
if reply is None:
raise qmp.QMPError("Monitor is closed")
if "error" in reply:
- raise MonitorResponseError(reply)
+ raise qmp.QMPResponseError(reply)
return reply["return"]
def get_qmp_event(self, wait=False):
diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
index 8388c7b603..aa8a666b8a 100644
--- a/python/qemu/qmp.py
+++ b/python/qemu/qmp.py
@@ -61,6 +61,19 @@ class QMPTimeoutError(QMPError):
"""
+class QMPResponseError(QMPError):
+ """
+ Represents erroneous QMP monitor reply
+ """
+ def __init__(self, reply: QMPMessage):
+ try:
+ desc = reply['error']['desc']
+ except KeyError:
+ desc = reply
+ super().__init__(desc)
+ self.reply = reply
+
+
class QEMUMonitorProtocol:
"""
Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
@@ -251,8 +264,8 @@ def command(self, cmd, **kwds):
Build and send a QMP command to the monitor, report errors if any
"""
ret = self.cmd(cmd, kwds)
- if "error" in ret:
- raise Exception(ret['error']['desc'])
+ if 'error' in ret:
+ raise QMPResponseError(ret)
return ret['return']
def pull_event(self, wait=False):
diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py
index 409b4321f2..da6acf050d 100755
--- a/scripts/render_block_graph.py
+++ b/scripts/render_block_graph.py
@@ -25,7 +25,10 @@
from graphviz import Digraph
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
-from qemu.machine import MonitorResponseError
+from qemu.qmp import (
+ QEMUMonitorProtocol,
+ QMPResponseError,
+)
def perm(arr):
@@ -102,7 +105,7 @@ def command(self, cmd):
reply = json.loads(subprocess.check_output(ar))
if 'error' in reply:
- raise MonitorResponseError(reply)
+ raise QMPResponseError(reply)
return reply['return']
--
2.21.3
- [PULL 06/19] python/machine.py: Prohibit multiple shutdown() calls, (continued)
- [PULL 06/19] python/machine.py: Prohibit multiple shutdown() calls, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 07/19] python/machine.py: Add a configurable timeout to shutdown(), Philippe Mathieu-Daudé, 2020/07/14
- [PULL 08/19] python/machine.py: Make wait() call shutdown(), Philippe Mathieu-Daudé, 2020/07/14
- [PULL 09/19] tests/acceptance: wait() instead of shutdown() where appropriate, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 11/19] python/machine.py: split shutdown into hard and soft flavors, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 10/19] tests/acceptance: Don't test reboot on cubieboard, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 12/19] python/machine.py: re-add sigkill warning suppression, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 13/19] python/machine.py: change default wait timeout to 3 seconds, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 14/19] python/qmp.py: Define common types, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 15/19] iotests.py: use qemu.qmp type aliases, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 16/19] python/qmp.py: re-absorb MonitorResponseError,
Philippe Mathieu-Daudé <=
- [PULL 17/19] python/qmp.py: Do not return None from cmd_obj, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 18/19] python/qmp.py: add casts to JSON deserialization, Philippe Mathieu-Daudé, 2020/07/14
- [PULL 19/19] python/qmp.py: add QMPProtocolError, Philippe Mathieu-Daudé, 2020/07/14
- Re: [PULL 00/19] Python patches for 5.1, Peter Maydell, 2020/07/15