python/qmp.py: re-absorb MonitorResponseError
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>
This commit is contained in:
parent
2012453ddd
commit
e3a23b4803
|
@ -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:
|
class QEMUMachine:
|
||||||
"""
|
"""
|
||||||
A QEMU VM
|
A QEMU VM
|
||||||
|
@ -533,7 +520,7 @@ class QEMUMachine:
|
||||||
if reply is None:
|
if reply is None:
|
||||||
raise qmp.QMPError("Monitor is closed")
|
raise qmp.QMPError("Monitor is closed")
|
||||||
if "error" in reply:
|
if "error" in reply:
|
||||||
raise MonitorResponseError(reply)
|
raise qmp.QMPResponseError(reply)
|
||||||
return reply["return"]
|
return reply["return"]
|
||||||
|
|
||||||
def get_qmp_event(self, wait=False):
|
def get_qmp_event(self, wait=False):
|
||||||
|
|
|
@ -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:
|
class QEMUMonitorProtocol:
|
||||||
"""
|
"""
|
||||||
Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
|
Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
|
||||||
|
@ -251,8 +264,8 @@ class QEMUMonitorProtocol:
|
||||||
Build and send a QMP command to the monitor, report errors if any
|
Build and send a QMP command to the monitor, report errors if any
|
||||||
"""
|
"""
|
||||||
ret = self.cmd(cmd, kwds)
|
ret = self.cmd(cmd, kwds)
|
||||||
if "error" in ret:
|
if 'error' in ret:
|
||||||
raise Exception(ret['error']['desc'])
|
raise QMPResponseError(ret)
|
||||||
return ret['return']
|
return ret['return']
|
||||||
|
|
||||||
def pull_event(self, wait=False):
|
def pull_event(self, wait=False):
|
||||||
|
|
|
@ -25,7 +25,10 @@ import json
|
||||||
from graphviz import Digraph
|
from graphviz import Digraph
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
|
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):
|
def perm(arr):
|
||||||
|
@ -102,7 +105,7 @@ class LibvirtGuest():
|
||||||
reply = json.loads(subprocess.check_output(ar))
|
reply = json.loads(subprocess.check_output(ar))
|
||||||
|
|
||||||
if 'error' in reply:
|
if 'error' in reply:
|
||||||
raise MonitorResponseError(reply)
|
raise QMPResponseError(reply)
|
||||||
|
|
||||||
return reply['return']
|
return reply['return']
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue