[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/9] python/qemu: improve event_
From: |
John Snow |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/9] python/qemu: improve event_wait method of vm |
Date: |
Fri, 31 May 2019 19:33:41 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
On 5/31/19 12:31 PM, Vladimir Sementsov-Ogievskiy wrote:
> 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
>
There's something like this in the queue; see:
[Qemu-devel] [PATCH v3 3/5] QEMUMachine: add events_wait method.
Though yours is a lot shorter, actually, because I made separate
event_wait and events_wait calls instead of just throwing non-iterables
in a list.
--js
- [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, 2019/05/31
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/9] python/qemu: improve event_wait method of vm,
John Snow <=
- [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