[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 20/97] QEMUMachine: add events_wait method
From: |
Michael Roth |
Subject: |
[PATCH 20/97] QEMUMachine: add events_wait method |
Date: |
Tue, 1 Oct 2019 18:44:59 -0500 |
From: John Snow <address@hidden>
Instead of event_wait which looks for a single event, add an events_wait
which can look for any number of events simultaneously. However, it
will still only return one at a time, whichever happens first.
Signed-off-by: John Snow <address@hidden>
Message-id: address@hidden
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
(cherry picked from commit f6f4b3f045ea18e3fa93a50cd0462236c428d62e)
Signed-off-by: Michael Roth <address@hidden>
---
python/qemu/__init__.py | 69 +++++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 20 deletions(-)
diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py
index fd144c0006..4cb8eb2f01 100644
--- a/python/qemu/__init__.py
+++ b/python/qemu/__init__.py
@@ -408,42 +408,71 @@ class QEMUMachine(object):
self._qmp.clear_events()
return events
- def event_wait(self, name, timeout=60.0, match=None):
+ @staticmethod
+ def event_match(event, match=None):
"""
- Wait for specified timeout on named event in QMP; optionally filter
- results by match.
+ Check if an event matches optional match criteria.
- The 'match' is checked to be a recursive subset of the 'event'; skips
- branch processing on match's value None
- {"foo": {"bar": 1}} matches {"foo": None}
- {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
+ 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.
+
+ 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}}
"""
- def event_match(event, match=None):
- if match is None:
- return True
+ if match is None:
+ return True
- for key in match:
- if key in event:
- if isinstance(event[key], dict):
- if not event_match(event[key], match[key]):
- return False
- elif event[key] != match[key]:
+ for key in match:
+ if key in event:
+ if isinstance(event[key], dict):
+ if not QEMUMachine.event_match(event[key], match[key]):
return False
- else:
+ elif event[key] != match[key]:
return False
+ else:
+ return False
+ return True
- return True
+ def event_wait(self, name, timeout=60.0, match=None):
+ """
+ event_wait waits for and returns a named event from QMP with a timeout.
+
+ name: The event to wait for.
+ timeout: QEMUMonitorProtocol.pull_event timeout parameter.
+ match: Optional match criteria. See event_match for details.
+ """
+ return self.events_wait([(name, match)], timeout)
+
+ def events_wait(self, events, timeout=60.0):
+ """
+ events_wait waits for and returns a named event from QMP with a
timeout.
+
+ events: a sequence of (name, match_criteria) tuples.
+ The match criteria are optional and may be None.
+ See event_match for details.
+ timeout: QEMUMonitorProtocol.pull_event timeout parameter.
+ """
+ def _match(event):
+ for name, match in events:
+ if (event['event'] == name and
+ self.event_match(event, match)):
+ return True
+ return False
# Search cached events
for event in self._events:
- if (event['event'] == name) and event_match(event, match):
+ if _match(event):
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 _match(event):
return event
self._events.append(event)
--
2.17.1
- [PATCH 15/97] s390x/cpumodel: ignore csske for expansion, (continued)
- [PATCH 15/97] s390x/cpumodel: ignore csske for expansion, Michael Roth, 2019/10/01
- [PATCH 24/97] migration/dirty-bitmaps: change bitmap enumeration method, Michael Roth, 2019/10/01
- [PATCH 18/97] iotests: Test commit job start with concurrent I/O, Michael Roth, 2019/10/01
- [PATCH 28/97] target/ppc: Fix xxbrq, xxbrw, Michael Roth, 2019/10/01
- [PATCH 01/97] qcow2: Avoid COW during metadata preallocation, Michael Roth, 2019/10/01
- [PATCH 30/97] target/ppc: Fix lxvw4x, lxvh8x and lxvb16x, Michael Roth, 2019/10/01
- [PATCH 13/97] block/file-posix: Unaligned O_DIRECT block-status, Michael Roth, 2019/10/01
- [PATCH 29/97] target/ppc: Fix vsum2sws, Michael Roth, 2019/10/01
- [PATCH 34/97] target/i386: define md-clear bit, Michael Roth, 2019/10/01
- [PATCH 14/97] iotests: Test unaligned raw images with O_DIRECT, Michael Roth, 2019/10/01
- [PATCH 20/97] QEMUMachine: add events_wait method,
Michael Roth <=
- [PATCH 33/97] target/i386: add MDS-NO feature, Michael Roth, 2019/10/01
- [PATCH 25/97] vhost: fix vhost_log size overflow during migration, Michael Roth, 2019/10/01
- [PATCH 02/97] qcow2: Add errp to preallocate_co(), Michael Roth, 2019/10/01
- [PATCH 37/97] usbredir: fix buffer-overflow on vmload, Michael Roth, 2019/10/01
- [PATCH 40/97] sphinx: add qmp_lexer, Michael Roth, 2019/10/01
- [PATCH 31/97] q35: Revert to kernel irqchip, Michael Roth, 2019/10/01
- [PATCH 27/97] target/ppc: Fix xvxsigdp, Michael Roth, 2019/10/01
- [PATCH 26/97] target/ppc: Fix xvabs[sd]p, xvnabs[sd]p, xvneg[sd]p, xvcpsgn[sd]p, Michael Roth, 2019/10/01
- [PATCH 46/97] i386/acpi: show PCI Express bus on pxb-pcie expanders, Michael Roth, 2019/10/01
- [PATCH 56/97] tpm: Exit in reset when backend indicates failure, Michael Roth, 2019/10/01