Blame SOURCES/kvm-iotests-implement-pretty-print-for-log-and-qmp_log.patch

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