|
|
383d26 |
From ec929cb5c98bd8148bff965f80cd0472348199ba Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Date: Wed, 20 Mar 2019 16:16:23 +0100
|
|
|
383d26 |
Subject: [PATCH 025/163] iotests: implement pretty-print for log and qmp_log
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Message-id: <20190320161631.14841-12-jsnow@redhat.com>
|
|
|
383d26 |
Patchwork-id: 84952
|
|
|
383d26 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 11/19] iotests: implement pretty-print for log and qmp_log
|
|
|
383d26 |
Bugzilla: 1668956
|
|
|
383d26 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
If iotests have lines exceeding >998 characters long, git doesn't
|
|
|
383d26 |
want to send it plaintext to the list. We can solve this by allowing
|
|
|
383d26 |
the iotests to use pretty printed QMP output that we can match against
|
|
|
383d26 |
instead.
|
|
|
383d26 |
|
|
|
383d26 |
As a bonus, it's much nicer for human eyes too.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
383d26 |
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
383d26 |
Message-Id: <20181221093529.23855-11-jsnow@redhat.com>
|
|
|
383d26 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
383d26 |
(cherry picked from commit 55cd64eab5cb7958c629edbf5f2233b87dfbd1b0)
|
|
|
383d26 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
tests/qemu-iotests/iotests.py | 15 ++++++++++-----
|
|
|
383d26 |
1 file changed, 10 insertions(+), 5 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
|
|
|
383d26 |
index d2a8fbd..d178469 100644
|
|
|
383d26 |
--- a/tests/qemu-iotests/iotests.py
|
|
|
383d26 |
+++ b/tests/qemu-iotests/iotests.py
|
|
|
383d26 |
@@ -282,13 +282,18 @@ def filter_img_info(output, filename):
|
|
|
383d26 |
lines.append(line)
|
|
|
383d26 |
return '\n'.join(lines)
|
|
|
383d26 |
|
|
|
383d26 |
-def log(msg, filters=[]):
|
|
|
383d26 |
+def log(msg, filters=[], indent=None):
|
|
|
383d26 |
+ '''Logs either a string message or a JSON serializable message (like QMP).
|
|
|
383d26 |
+ If indent is provided, JSON serializable messages are pretty-printed.'''
|
|
|
383d26 |
for flt in filters:
|
|
|
383d26 |
msg = flt(msg)
|
|
|
383d26 |
if isinstance(msg, dict) or isinstance(msg, list):
|
|
|
383d26 |
+ # Python < 3.4 needs to know not to add whitespace when pretty-printing:
|
|
|
383d26 |
+ separators = (', ', ': ') if indent is None else (',', ': ')
|
|
|
383d26 |
# Don't sort if it's already sorted
|
|
|
383d26 |
do_sort = not isinstance(msg, OrderedDict)
|
|
|
383d26 |
- print(json.dumps(msg, sort_keys=do_sort))
|
|
|
383d26 |
+ print(json.dumps(msg, sort_keys=do_sort,
|
|
|
383d26 |
+ indent=indent, separators=separators))
|
|
|
383d26 |
else:
|
|
|
383d26 |
print(msg)
|
|
|
383d26 |
|
|
|
383d26 |
@@ -477,14 +482,14 @@ class VM(qtest.QEMUQtestMachine):
|
|
|
383d26 |
result.append(filter_qmp_event(ev))
|
|
|
383d26 |
return result
|
|
|
383d26 |
|
|
|
383d26 |
- def qmp_log(self, cmd, filters=[], **kwargs):
|
|
|
383d26 |
+ def qmp_log(self, cmd, filters=[], indent=None, **kwargs):
|
|
|
383d26 |
full_cmd = OrderedDict((
|
|
|
383d26 |
("execute", cmd),
|
|
|
383d26 |
("arguments", ordered_kwargs(kwargs))
|
|
|
383d26 |
))
|
|
|
383d26 |
- log(full_cmd, filters)
|
|
|
383d26 |
+ log(full_cmd, filters, indent=indent)
|
|
|
383d26 |
result = self.qmp(cmd, **kwargs)
|
|
|
383d26 |
- log(result, filters)
|
|
|
383d26 |
+ log(result, filters, indent=indent)
|
|
|
383d26 |
return result
|
|
|
383d26 |
|
|
|
383d26 |
def run_job(self, job, auto_finalize=True, auto_dismiss=False):
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|