[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 2/9] python/qemu: improve event_wait method of vm
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH v2 2/9] python/qemu: improve event_wait method of vm |
Date: |
Fri, 31 May 2019 19:31:55 +0300 |
Support several names to wait for, which useful, when we don't sure
which event will we get. For example when mirror fails we get
BLOCK_JOB_COMPLETE otherwise we get BLOCK_JOB_READY (and only then,
after completing block-job we get BLOCK_JOB_COMPLETE).
Also, add filtered version for convenient use.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
python/qemu/__init__.py | 9 ++++++---
tests/qemu-iotests/iotests.py | 5 +++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py
index 81d9657ec0..5e517025b9 100644
--- a/python/qemu/__init__.py
+++ b/python/qemu/__init__.py
@@ -402,7 +402,7 @@ class QEMUMachine(object):
self._qmp.clear_events()
return events
- def event_wait(self, name, timeout=60.0, match=None):
+ def event_wait(self, names, timeout=60.0, match=None):
"""
Wait for specified timeout on named event in QMP; optionally filter
results by match.
@@ -412,6 +412,9 @@ class QEMUMachine(object):
{"foo": {"bar": 1}} matches {"foo": None}
{"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
"""
+ if not isinstance(names, list):
+ names = [names]
+
def event_match(event, match=None):
if match is None:
return True
@@ -430,14 +433,14 @@ class QEMUMachine(object):
# Search cached events
for event in self._events:
- if (event['event'] == name) and event_match(event, match):
+ if (event['event'] in names) and event_match(event, match):
self._events.remove(event)
return event
# Poll for new events
while True:
event = self._qmp.pull_event(wait=timeout)
- if (event['event'] == name) and event_match(event, match):
+ if (event['event'] in names) and event_match(event, match):
return event
self._events.append(event)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 7bde380d96..4218fc908b 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -532,6 +532,11 @@ class VM(qtest.QEMUQtestMachine):
log(result, filters, indent=indent)
return result
+ def event_wait_log(self, names, **kwargs):
+ event = self.event_wait(names, **kwargs)
+ log(event, filters=[filter_qmp_event])
+ return event
+
# Returns None on success, and an error string on failure
def run_job(self, job, auto_finalize=True, auto_dismiss=False):
error = None
--
2.18.0
- [Qemu-block] [PATCH v2 0/9] qcow2-bitmaps: rewrite reopening logic, Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 2/9] python/qemu: improve event_wait method of vm,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-block] [PATCH v2 9/9] qcow2-bitmap: move bitmap reopen-rw code to qcow2_reopen_prepare, Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 7/9] block/qcow2-bitmap: fix and improve qcow2_reopen_bitmaps_rw, Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 3/9] iotests: add test 255 to check bitmap life after snapshot + commit, Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 5/9] block/qcow2-bitmap: drop qcow2_reopen_bitmaps_rw_hint(), Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 8/9] block/qcow2-bitmap: fix reopening bitmaps to RW, Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 4/9] block/qcow2-bitmap: get rid of bdrv_has_changed_persistent_bitmaps, Vladimir Sementsov-Ogievskiy, 2019/05/31
- [Qemu-block] [PATCH v2 6/9] block/qcow2-bitmap: do not remove bitmaps on reopen-ro, Vladimir Sementsov-Ogievskiy, 2019/05/31