[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/20] event_match: always match on None value
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PULL 06/20] event_match: always match on None value |
Date: |
Fri, 14 Jun 2019 15:40:07 +0200 |
From: John Snow <address@hidden>
Before, event_match didn't always recurse if the event value was not a
dictionary, and would instead check for equality immediately.
By delaying equality checking to post-recursion, we can allow leaf
values like "5" to match "None" and take advantage of the generic
None-returns-True clause.
This makes the matching a little more obviously consistent at the
expense of being able to check for explicit None values, which is
probably not that important given what this function is used for.
Signed-off-by: John Snow <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
python/qemu/__init__.py | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py
index 98ed8a2e28..dbaf8a5311 100644
--- a/python/qemu/__init__.py
+++ b/python/qemu/__init__.py
@@ -409,27 +409,31 @@ class QEMUMachine(object):
The match criteria takes the form of a matching subdict. The event is
checked to be a superset of the subdict, recursively, with matching
- values whenever those values are not None.
+ values whenever the subdict values are not None.
+
+ This has a limitation that you cannot explicitly check for None values.
Examples, with the subdict queries on the left:
- None matches any object.
- {"foo": None} matches {"foo": {"bar": 1}}
- - {"foo": {"baz": None}} does not match {"foo": {"bar": 1}}
- - {"foo": {"baz": 2}} matches {"foo": {"bar": 1, "baz": 2}}
+ - {"foo": None} matches {"foo": 5}
+ - {"foo": {"abc": None}} does not match {"foo": {"bar": 1}}
+ - {"foo": {"rab": 2}} matches {"foo": {"bar": 1, "rab": 2}}
"""
if match is None:
return True
- for key in match:
- if key in event:
- if isinstance(event[key], dict):
+ try:
+ for key in match:
+ if key in event:
if not QEMUMachine.event_match(event[key], match[key]):
return False
- elif event[key] != match[key]:
+ else:
return False
- else:
- return False
- return True
+ return True
+ except TypeError:
+ # either match or event wasn't iterable (not a dict)
+ return match == event
def event_wait(self, name, timeout=60.0, match=None):
"""
--
2.21.0
- [Qemu-devel] [PULL 00/20] Block patches, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 01/20] blockdev-backup: don't check aio_context too early, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 04/20] iotests.py: rewrite run_job to be pickier, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 02/20] iotests.py: do not use infinite waits, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 06/20] event_match: always match on None value,
Max Reitz <=
- [Qemu-devel] [PULL 03/20] QEMUMachine: add events_wait method, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 09/20] hw/block/fdc: floppy command FIFO memory initialization, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 08/20] iotests: Fix intermittent failure in 219, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 05/20] iotests: add iotest 256 for testing blockdev-backup across iothread contexts, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 07/20] iotests: Filter 175's allocation information, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 10/20] iotests: restrict 254 to support only qcow2, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 11/20] qemu-img: Fix options leakage in img_rebase(), Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 12/20] qapi/block-core: Overlays are not snapshots, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 13/20] blockdev: Overlays are not snapshots, Max Reitz, 2019/06/14
- [Qemu-devel] [PULL 14/20] qemu-img: Move quiet into ImgConvertState, Max Reitz, 2019/06/14