|
|
4841a6 |
From 12f596b66d577eb92f154fadf734d058dd0756d6 Mon Sep 17 00:00:00 2001
|
|
|
4841a6 |
From: Hanna Reitz <hreitz@redhat.com>
|
|
|
4841a6 |
Date: Wed, 16 Feb 2022 11:53:54 +0100
|
|
|
4841a6 |
Subject: [PATCH 23/24] iotests: Allow using QMP with the QSD
|
|
|
4841a6 |
|
|
|
4841a6 |
RH-Author: Hanna Reitz <hreitz@redhat.com>
|
|
|
4841a6 |
RH-MergeRequest: 189: block: Make bdrv_refresh_limits() non-recursive
|
|
|
4841a6 |
RH-Commit: [2/3] 55bee4690a2e02d3be9f2bd68f2d244d0a36743b
|
|
|
4841a6 |
RH-Bugzilla: 2072932
|
|
|
4841a6 |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
4841a6 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
4841a6 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
4841a6 |
|
|
|
4841a6 |
Add a parameter to optionally open a QMP connection when creating a
|
|
|
4841a6 |
QemuStorageDaemon instance.
|
|
|
4841a6 |
|
|
|
4841a6 |
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
|
|
|
4841a6 |
Message-Id: <20220216105355.30729-3-hreitz@redhat.com>
|
|
|
4841a6 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
4841a6 |
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
4841a6 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
4841a6 |
(cherry picked from commit ec88eed8d14088b36a3495710368b8d1a3c33420)
|
|
|
4841a6 |
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
|
|
|
4841a6 |
---
|
|
|
4841a6 |
tests/qemu-iotests/iotests.py | 32 +++++++++++++++++++++++++++++++-
|
|
|
4841a6 |
1 file changed, 31 insertions(+), 1 deletion(-)
|
|
|
4841a6 |
|
|
|
4841a6 |
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
|
|
|
4841a6 |
index a51b5ce8cd..2ef493755c 100644
|
|
|
4841a6 |
--- a/tests/qemu-iotests/iotests.py
|
|
|
4841a6 |
+++ b/tests/qemu-iotests/iotests.py
|
|
|
4841a6 |
@@ -38,6 +38,7 @@
|
|
|
4841a6 |
|
|
|
4841a6 |
from qemu.machine import qtest
|
|
|
4841a6 |
from qemu.qmp import QMPMessage
|
|
|
4841a6 |
+from qemu.aqmp.legacy import QEMUMonitorProtocol
|
|
|
4841a6 |
|
|
|
4841a6 |
# Use this logger for logging messages directly from the iotests module
|
|
|
4841a6 |
logger = logging.getLogger('qemu.iotests')
|
|
|
4841a6 |
@@ -315,14 +316,30 @@ def cmd(self, cmd):
|
|
|
4841a6 |
|
|
|
4841a6 |
|
|
|
4841a6 |
class QemuStorageDaemon:
|
|
|
4841a6 |
- def __init__(self, *args: str, instance_id: str = 'a'):
|
|
|
4841a6 |
+ _qmp: Optional[QEMUMonitorProtocol] = None
|
|
|
4841a6 |
+ _qmpsock: Optional[str] = None
|
|
|
4841a6 |
+ # Python < 3.8 would complain if this type were not a string literal
|
|
|
4841a6 |
+ # (importing `annotations` from `__future__` would work; but not on <= 3.6)
|
|
|
4841a6 |
+ _p: 'Optional[subprocess.Popen[bytes]]' = None
|
|
|
4841a6 |
+
|
|
|
4841a6 |
+ def __init__(self, *args: str, instance_id: str = 'a', qmp: bool = False):
|
|
|
4841a6 |
assert '--pidfile' not in args
|
|
|
4841a6 |
self.pidfile = os.path.join(test_dir, f'qsd-{instance_id}-pid')
|
|
|
4841a6 |
all_args = [qsd_prog] + list(args) + ['--pidfile', self.pidfile]
|
|
|
4841a6 |
|
|
|
4841a6 |
+ if qmp:
|
|
|
4841a6 |
+ self._qmpsock = os.path.join(sock_dir, f'qsd-{instance_id}.sock')
|
|
|
4841a6 |
+ all_args += ['--chardev',
|
|
|
4841a6 |
+ f'socket,id=qmp-sock,path={self._qmpsock}',
|
|
|
4841a6 |
+ '--monitor', 'qmp-sock']
|
|
|
4841a6 |
+
|
|
|
4841a6 |
+ self._qmp = QEMUMonitorProtocol(self._qmpsock, server=True)
|
|
|
4841a6 |
+
|
|
|
4841a6 |
# Cannot use with here, we want the subprocess to stay around
|
|
|
4841a6 |
# pylint: disable=consider-using-with
|
|
|
4841a6 |
self._p = subprocess.Popen(all_args)
|
|
|
4841a6 |
+ if self._qmp is not None:
|
|
|
4841a6 |
+ self._qmp.accept()
|
|
|
4841a6 |
while not os.path.exists(self.pidfile):
|
|
|
4841a6 |
if self._p.poll() is not None:
|
|
|
4841a6 |
cmd = ' '.join(all_args)
|
|
|
4841a6 |
@@ -337,11 +354,24 @@ def __init__(self, *args: str, instance_id: str = 'a'):
|
|
|
4841a6 |
|
|
|
4841a6 |
assert self._pid == self._p.pid
|
|
|
4841a6 |
|
|
|
4841a6 |
+ def qmp(self, cmd: str, args: Optional[Dict[str, object]] = None) \
|
|
|
4841a6 |
+ -> QMPMessage:
|
|
|
4841a6 |
+ assert self._qmp is not None
|
|
|
4841a6 |
+ return self._qmp.cmd(cmd, args)
|
|
|
4841a6 |
+
|
|
|
4841a6 |
def stop(self, kill_signal=15):
|
|
|
4841a6 |
self._p.send_signal(kill_signal)
|
|
|
4841a6 |
self._p.wait()
|
|
|
4841a6 |
self._p = None
|
|
|
4841a6 |
|
|
|
4841a6 |
+ if self._qmp:
|
|
|
4841a6 |
+ self._qmp.close()
|
|
|
4841a6 |
+
|
|
|
4841a6 |
+ if self._qmpsock is not None:
|
|
|
4841a6 |
+ try:
|
|
|
4841a6 |
+ os.remove(self._qmpsock)
|
|
|
4841a6 |
+ except OSError:
|
|
|
4841a6 |
+ pass
|
|
|
4841a6 |
try:
|
|
|
4841a6 |
os.remove(self.pidfile)
|
|
|
4841a6 |
except OSError:
|
|
|
4841a6 |
--
|
|
|
4841a6 |
2.35.3
|
|
|
4841a6 |
|