aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2018-12-21 04:35:28 -0500
committerEric Blake <eblake@redhat.com>2019-01-14 10:09:46 -0600
commit55cd64eab5cb7958c629edbf5f2233b87dfbd1b0 (patch)
tree7676ead47b53de931fd1761c20378a674fba021a /tests
parent08fcd6111e1949f456e1b232ebeeb0cc17019a92 (diff)
downloadqemu-55cd64eab5cb7958c629edbf5f2233b87dfbd1b0.zip
qemu-55cd64eab5cb7958c629edbf5f2233b87dfbd1b0.tar.gz
qemu-55cd64eab5cb7958c629edbf5f2233b87dfbd1b0.tar.bz2
iotests: implement pretty-print for log and qmp_log
If iotests have lines exceeding >998 characters long, git doesn't want to send it plaintext to the list. We can solve this by allowing the iotests to use pretty printed QMP output that we can match against instead. As a bonus, it's much nicer for human eyes too. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20181221093529.23855-11-jsnow@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qemu-iotests/iotests.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index a96a701..cbedfaf 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -288,13 +288,18 @@ def filter_img_info(output, filename):
lines.append(line)
return '\n'.join(lines)
-def log(msg, filters=[]):
+def log(msg, filters=[], indent=None):
+ '''Logs either a string message or a JSON serializable message (like QMP).
+ If indent is provided, JSON serializable messages are pretty-printed.'''
for flt in filters:
msg = flt(msg)
if isinstance(msg, dict) or isinstance(msg, list):
+ # Python < 3.4 needs to know not to add whitespace when pretty-printing:
+ separators = (', ', ': ') if indent is None else (',', ': ')
# Don't sort if it's already sorted
do_sort = not isinstance(msg, OrderedDict)
- print(json.dumps(msg, sort_keys=do_sort))
+ print(json.dumps(msg, sort_keys=do_sort,
+ indent=indent, separators=separators))
else:
print(msg)
@@ -483,14 +488,14 @@ class VM(qtest.QEMUQtestMachine):
result.append(filter_qmp_event(ev))
return result
- def qmp_log(self, cmd, filters=[], **kwargs):
+ def qmp_log(self, cmd, filters=[], indent=None, **kwargs):
full_cmd = OrderedDict((
("execute", cmd),
("arguments", ordered_kwargs(kwargs))
))
- log(full_cmd, filters)
+ log(full_cmd, filters, indent=indent)
result = self.qmp(cmd, **kwargs)
- log(result, filters)
+ log(result, filters, indent=indent)
return result
def run_job(self, job, auto_finalize=True, auto_dismiss=False):