mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-31 22:11:53 -06:00
iotests.py: Filters for VM.run_job()
Allow filters for VM.run_job(), and pass the filters given to VM.blockdev_create() to it. (Use this opportunity to annotate VM.run_job()'s parameter types; unfortunately, for the filter, I could not come up with anything better than Callable[[Any], Any] that would pass mypy's scrutiny.) At one point, a plain string is logged, so the filters passed to it must work fine with plain strings. The only filters passed to it at this point are the ones from VM.blockdev_create(), which are filter_qmp_test_files() (by default) and 207's filter_hash(). Both cannot handle plain strings yet, but we can make them by amending filter_qmp() to treat them as plain values with a None key. Signed-off-by: Hanna Reitz <hreitz@redhat.com> Message-Id: <20220318125304.66131-2-hreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
This commit is contained in:
parent
8f685ac391
commit
da9d88d8e6
1 changed files with 16 additions and 10 deletions
|
@ -607,8 +607,10 @@ def filter_qmp(qmsg, filter_fn):
|
||||||
# Iterate through either lists or dicts;
|
# Iterate through either lists or dicts;
|
||||||
if isinstance(qmsg, list):
|
if isinstance(qmsg, list):
|
||||||
items = enumerate(qmsg)
|
items = enumerate(qmsg)
|
||||||
else:
|
elif isinstance(qmsg, dict):
|
||||||
items = qmsg.items()
|
items = qmsg.items()
|
||||||
|
else:
|
||||||
|
return filter_fn(None, qmsg)
|
||||||
|
|
||||||
for k, v in items:
|
for k, v in items:
|
||||||
if isinstance(v, (dict, list)):
|
if isinstance(v, (dict, list)):
|
||||||
|
@ -944,8 +946,12 @@ class VM(qtest.QEMUQtestMachine):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Returns None on success, and an error string on failure
|
# Returns None on success, and an error string on failure
|
||||||
def run_job(self, job, auto_finalize=True, auto_dismiss=False,
|
def run_job(self, job: str, auto_finalize: bool = True,
|
||||||
pre_finalize=None, cancel=False, wait=60.0):
|
auto_dismiss: bool = False,
|
||||||
|
pre_finalize: Optional[Callable[[], None]] = None,
|
||||||
|
cancel: bool = False, wait: float = 60.0,
|
||||||
|
filters: Iterable[Callable[[Any], Any]] = (),
|
||||||
|
) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
run_job moves a job from creation through to dismissal.
|
run_job moves a job from creation through to dismissal.
|
||||||
|
|
||||||
|
@ -975,7 +981,7 @@ class VM(qtest.QEMUQtestMachine):
|
||||||
while True:
|
while True:
|
||||||
ev = filter_qmp_event(self.events_wait(events, timeout=wait))
|
ev = filter_qmp_event(self.events_wait(events, timeout=wait))
|
||||||
if ev['event'] != 'JOB_STATUS_CHANGE':
|
if ev['event'] != 'JOB_STATUS_CHANGE':
|
||||||
log(ev)
|
log(ev, filters=filters)
|
||||||
continue
|
continue
|
||||||
status = ev['data']['status']
|
status = ev['data']['status']
|
||||||
if status == 'aborting':
|
if status == 'aborting':
|
||||||
|
@ -983,18 +989,18 @@ class VM(qtest.QEMUQtestMachine):
|
||||||
for j in result['return']:
|
for j in result['return']:
|
||||||
if j['id'] == job:
|
if j['id'] == job:
|
||||||
error = j['error']
|
error = j['error']
|
||||||
log('Job failed: %s' % (j['error']))
|
log('Job failed: %s' % (j['error']), filters=filters)
|
||||||
elif status == 'ready':
|
elif status == 'ready':
|
||||||
self.qmp_log('job-complete', id=job)
|
self.qmp_log('job-complete', id=job, filters=filters)
|
||||||
elif status == 'pending' and not auto_finalize:
|
elif status == 'pending' and not auto_finalize:
|
||||||
if pre_finalize:
|
if pre_finalize:
|
||||||
pre_finalize()
|
pre_finalize()
|
||||||
if cancel:
|
if cancel:
|
||||||
self.qmp_log('job-cancel', id=job)
|
self.qmp_log('job-cancel', id=job, filters=filters)
|
||||||
else:
|
else:
|
||||||
self.qmp_log('job-finalize', id=job)
|
self.qmp_log('job-finalize', id=job, filters=filters)
|
||||||
elif status == 'concluded' and not auto_dismiss:
|
elif status == 'concluded' and not auto_dismiss:
|
||||||
self.qmp_log('job-dismiss', id=job)
|
self.qmp_log('job-dismiss', id=job, filters=filters)
|
||||||
elif status == 'null':
|
elif status == 'null':
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
@ -1007,7 +1013,7 @@ class VM(qtest.QEMUQtestMachine):
|
||||||
|
|
||||||
if 'return' in result:
|
if 'return' in result:
|
||||||
assert result['return'] == {}
|
assert result['return'] == {}
|
||||||
job_result = self.run_job(job_id)
|
job_result = self.run_job(job_id, filters=filters)
|
||||||
else:
|
else:
|
||||||
job_result = result['error']
|
job_result = result['error']
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue