|
|
7711c0 |
From 2a6c4e6212c3f342132a2aca22c84bbf886dc79b Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Date: Wed, 20 Mar 2019 16:16:22 +0100
|
|
|
7711c0 |
Subject: [PATCH 024/163] iotests: change qmp_log filters to expect QMP objects
|
|
|
7711c0 |
only
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-id: <20190320161631.14841-11-jsnow@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 84946
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 10/19] iotests: change qmp_log filters to expect QMP objects only
|
|
|
7711c0 |
Bugzilla: 1668956
|
|
|
7711c0 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
As laid out in the previous commit's message:
|
|
|
7711c0 |
|
|
|
7711c0 |
```
|
|
|
7711c0 |
Several places in iotests deal with serializing objects into JSON
|
|
|
7711c0 |
strings, but to add pretty-printing it seems desirable to localize
|
|
|
7711c0 |
all of those cases.
|
|
|
7711c0 |
|
|
|
7711c0 |
log() seems like a good candidate for that centralized behavior.
|
|
|
7711c0 |
log() can already serialize json objects, but when it does so,
|
|
|
7711c0 |
it assumes filters=[] operates on QMP objects, not strings.
|
|
|
7711c0 |
|
|
|
7711c0 |
qmp_log currently operates by dumping outgoing and incoming QMP
|
|
|
7711c0 |
objects into strings and filtering them assuming that filters=[]
|
|
|
7711c0 |
are string filters.
|
|
|
7711c0 |
```
|
|
|
7711c0 |
|
|
|
7711c0 |
Therefore:
|
|
|
7711c0 |
|
|
|
7711c0 |
Change qmp_log to treat filters as if they're always qmp object filters,
|
|
|
7711c0 |
then change the logging call to rely on log()'s ability to serialize QMP
|
|
|
7711c0 |
objects, so we're not duplicating that effort.
|
|
|
7711c0 |
|
|
|
7711c0 |
Add a qmp version of filter_testfiles and adjust the only caller using
|
|
|
7711c0 |
it for qmp_log to use the qmp version.
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-Id: <20181221093529.23855-10-jsnow@redhat.com>
|
|
|
7711c0 |
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
7711c0 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit 08fcd6111e1949f456e1b232ebeeb0cc17019a92)
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
tests/qemu-iotests/206 | 4 ++--
|
|
|
7711c0 |
tests/qemu-iotests/iotests.py | 28 +++++++++++++++++++++++++---
|
|
|
7711c0 |
2 files changed, 27 insertions(+), 5 deletions(-)
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/tests/qemu-iotests/206 b/tests/qemu-iotests/206
|
|
|
7711c0 |
index e92550f..5bb738b 100755
|
|
|
7711c0 |
--- a/tests/qemu-iotests/206
|
|
|
7711c0 |
+++ b/tests/qemu-iotests/206
|
|
|
7711c0 |
@@ -27,7 +27,7 @@ iotests.verify_image_format(supported_fmts=['qcow2'])
|
|
|
7711c0 |
|
|
|
7711c0 |
def blockdev_create(vm, options):
|
|
|
7711c0 |
result = vm.qmp_log('blockdev-create',
|
|
|
7711c0 |
- filters=[iotests.filter_testfiles],
|
|
|
7711c0 |
+ filters=[iotests.filter_qmp_testfiles],
|
|
|
7711c0 |
job_id='job0', options=options)
|
|
|
7711c0 |
|
|
|
7711c0 |
if 'return' in result:
|
|
|
7711c0 |
@@ -55,7 +55,7 @@ with iotests.FilePath('t.qcow2') as disk_path, \
|
|
|
7711c0 |
'size': 0 })
|
|
|
7711c0 |
|
|
|
7711c0 |
vm.qmp_log('blockdev-add',
|
|
|
7711c0 |
- filters=[iotests.filter_testfiles],
|
|
|
7711c0 |
+ filters=[iotests.filter_qmp_testfiles],
|
|
|
7711c0 |
driver='file', filename=disk_path,
|
|
|
7711c0 |
node_name='imgfile')
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
|
|
|
7711c0 |
index 30d198a..d2a8fbd 100644
|
|
|
7711c0 |
--- a/tests/qemu-iotests/iotests.py
|
|
|
7711c0 |
+++ b/tests/qemu-iotests/iotests.py
|
|
|
7711c0 |
@@ -240,10 +240,33 @@ def filter_qmp_event(event):
|
|
|
7711c0 |
event['timestamp']['microseconds'] = 'USECS'
|
|
|
7711c0 |
return event
|
|
|
7711c0 |
|
|
|
7711c0 |
+def filter_qmp(qmsg, filter_fn):
|
|
|
7711c0 |
+ '''Given a string filter, filter a QMP object's values.
|
|
|
7711c0 |
+ filter_fn takes a (key, value) pair.'''
|
|
|
7711c0 |
+ # Iterate through either lists or dicts;
|
|
|
7711c0 |
+ if isinstance(qmsg, list):
|
|
|
7711c0 |
+ items = enumerate(qmsg)
|
|
|
7711c0 |
+ else:
|
|
|
7711c0 |
+ items = qmsg.items()
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ for k, v in items:
|
|
|
7711c0 |
+ if isinstance(v, list) or isinstance(v, dict):
|
|
|
7711c0 |
+ qmsg[k] = filter_qmp(v, filter_fn)
|
|
|
7711c0 |
+ else:
|
|
|
7711c0 |
+ qmsg[k] = filter_fn(k, v)
|
|
|
7711c0 |
+ return qmsg
|
|
|
7711c0 |
+
|
|
|
7711c0 |
def filter_testfiles(msg):
|
|
|
7711c0 |
prefix = os.path.join(test_dir, "%s-" % (os.getpid()))
|
|
|
7711c0 |
return msg.replace(prefix, 'TEST_DIR/PID-')
|
|
|
7711c0 |
|
|
|
7711c0 |
+def filter_qmp_testfiles(qmsg):
|
|
|
7711c0 |
+ def _filter(key, value):
|
|
|
7711c0 |
+ if key == 'filename' or key == 'backing-file':
|
|
|
7711c0 |
+ return filter_testfiles(value)
|
|
|
7711c0 |
+ return value
|
|
|
7711c0 |
+ return filter_qmp(qmsg, _filter)
|
|
|
7711c0 |
+
|
|
|
7711c0 |
def filter_generated_node_ids(msg):
|
|
|
7711c0 |
return re.sub("#block[0-9]+", "NODE_NAME", msg)
|
|
|
7711c0 |
|
|
|
7711c0 |
@@ -459,10 +482,9 @@ class VM(qtest.QEMUQtestMachine):
|
|
|
7711c0 |
("execute", cmd),
|
|
|
7711c0 |
("arguments", ordered_kwargs(kwargs))
|
|
|
7711c0 |
))
|
|
|
7711c0 |
- logmsg = json.dumps(full_cmd)
|
|
|
7711c0 |
- log(logmsg, filters)
|
|
|
7711c0 |
+ log(full_cmd, filters)
|
|
|
7711c0 |
result = self.qmp(cmd, **kwargs)
|
|
|
7711c0 |
- log(json.dumps(result, sort_keys=True), filters)
|
|
|
7711c0 |
+ log(result, filters)
|
|
|
7711c0 |
return result
|
|
|
7711c0 |
|
|
|
7711c0 |
def run_job(self, job, auto_finalize=True, auto_dismiss=False):
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|