26ba25
From 1f4ca318d904030aeaee0905b724335b3346acc3 Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Tue, 26 Jun 2018 09:48:35 +0200
26ba25
Subject: [PATCH 127/268] iotests: Move qmp_to_opts() to VM
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20180626094856.6924-53-kwolf@redhat.com>
26ba25
Patchwork-id: 81085
26ba25
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 52/73] iotests: Move qmp_to_opts() to VM
26ba25
Bugzilla: 1513543
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Fam Zheng <famz@redhat.com>
26ba25
26ba25
qmp_to_opts() used to be a method of QMPTestCase, but recently we
26ba25
started to add more Python test cases that don't make use of
26ba25
QMPTestCase. In order to make the method usable there, move it to VM.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Reviewed-by: Max Reitz <mreitz@redhat.com>
26ba25
(cherry picked from commit 62a9428812c0f4aacbf2f7fdf449fa4f4ab3775c)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 tests/qemu-iotests/041        |  6 +++---
26ba25
 tests/qemu-iotests/155        |  2 +-
26ba25
 tests/qemu-iotests/iotests.py | 45 ++++++++++++++++++++++---------------------
26ba25
 3 files changed, 27 insertions(+), 26 deletions(-)
26ba25
26ba25
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
26ba25
index e945879..c20ac7d 100755
26ba25
--- a/tests/qemu-iotests/041
26ba25
+++ b/tests/qemu-iotests/041
26ba25
@@ -1030,9 +1030,9 @@ class TestOrphanedSource(iotests.QMPTestCase):
26ba25
                  'read-only': 'on' }
26ba25
 
26ba25
         self.vm = iotests.VM()
26ba25
-        self.vm.add_blockdev(self.qmp_to_opts(blk0))
26ba25
-        self.vm.add_blockdev(self.qmp_to_opts(blk1))
26ba25
-        self.vm.add_blockdev(self.qmp_to_opts(blk2))
26ba25
+        self.vm.add_blockdev(self.vm.qmp_to_opts(blk0))
26ba25
+        self.vm.add_blockdev(self.vm.qmp_to_opts(blk1))
26ba25
+        self.vm.add_blockdev(self.vm.qmp_to_opts(blk2))
26ba25
         self.vm.launch()
26ba25
 
26ba25
     def tearDown(self):
26ba25
diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
26ba25
index 42dae04..63a5b5e 100755
26ba25
--- a/tests/qemu-iotests/155
26ba25
+++ b/tests/qemu-iotests/155
26ba25
@@ -63,7 +63,7 @@ class BaseClass(iotests.QMPTestCase):
26ba25
                     'driver': iotests.imgfmt,
26ba25
                     'file': {'driver': 'file',
26ba25
                              'filename': source_img}}
26ba25
-        self.vm.add_blockdev(self.qmp_to_opts(blockdev))
26ba25
+        self.vm.add_blockdev(self.vm.qmp_to_opts(blockdev))
26ba25
         self.vm.add_device('virtio-blk,id=qdev0,drive=source')
26ba25
         self.vm.launch()
26ba25
 
26ba25
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
26ba25
index 824f87d..d190ce7 100644
26ba25
--- a/tests/qemu-iotests/iotests.py
26ba25
+++ b/tests/qemu-iotests/iotests.py
26ba25
@@ -373,6 +373,27 @@ class VM(qtest.QEMUQtestMachine):
26ba25
         return self.qmp('human-monitor-command',
26ba25
                         command_line='qemu-io %s "%s"' % (drive, cmd))
26ba25
 
26ba25
+    def flatten_qmp_object(self, obj, output=None, basestr=''):
26ba25
+        if output is None:
26ba25
+            output = dict()
26ba25
+        if isinstance(obj, list):
26ba25
+            for i in range(len(obj)):
26ba25
+                self.flatten_qmp_object(obj[i], output, basestr + str(i) + '.')
26ba25
+        elif isinstance(obj, dict):
26ba25
+            for key in obj:
26ba25
+                self.flatten_qmp_object(obj[key], output, basestr + key + '.')
26ba25
+        else:
26ba25
+            output[basestr[:-1]] = obj # Strip trailing '.'
26ba25
+        return output
26ba25
+
26ba25
+    def qmp_to_opts(self, obj):
26ba25
+        obj = self.flatten_qmp_object(obj)
26ba25
+        output_list = list()
26ba25
+        for key in obj:
26ba25
+            output_list += [key + '=' + obj[key]]
26ba25
+        return ','.join(output_list)
26ba25
+
26ba25
+
26ba25
 
26ba25
 index_re = re.compile(r'([^\[]+)\[([^\]]+)\]')
26ba25
 
26ba25
@@ -400,26 +421,6 @@ class QMPTestCase(unittest.TestCase):
26ba25
                     self.fail('invalid index "%s" in path "%s" in "%s"' % (idx, path, str(d)))
26ba25
         return d
26ba25
 
26ba25
-    def flatten_qmp_object(self, obj, output=None, basestr=''):
26ba25
-        if output is None:
26ba25
-            output = dict()
26ba25
-        if isinstance(obj, list):
26ba25
-            for i in range(len(obj)):
26ba25
-                self.flatten_qmp_object(obj[i], output, basestr + str(i) + '.')
26ba25
-        elif isinstance(obj, dict):
26ba25
-            for key in obj:
26ba25
-                self.flatten_qmp_object(obj[key], output, basestr + key + '.')
26ba25
-        else:
26ba25
-            output[basestr[:-1]] = obj # Strip trailing '.'
26ba25
-        return output
26ba25
-
26ba25
-    def qmp_to_opts(self, obj):
26ba25
-        obj = self.flatten_qmp_object(obj)
26ba25
-        output_list = list()
26ba25
-        for key in obj:
26ba25
-            output_list += [key + '=' + obj[key]]
26ba25
-        return ','.join(output_list)
26ba25
-
26ba25
     def assert_qmp_absent(self, d, path):
26ba25
         try:
26ba25
             result = self.dictpath(d, path)
26ba25
@@ -454,8 +455,8 @@ class QMPTestCase(unittest.TestCase):
26ba25
         '''Asserts that the given filename is a json: filename and that its
26ba25
            content is equal to the given reference object'''
26ba25
         self.assertEqual(json_filename[:5], 'json:')
26ba25
-        self.assertEqual(self.flatten_qmp_object(json.loads(json_filename[5:])),
26ba25
-                         self.flatten_qmp_object(reference))
26ba25
+        self.assertEqual(self.vm.flatten_qmp_object(json.loads(json_filename[5:])),
26ba25
+                         self.vm.flatten_qmp_object(reference))
26ba25
 
26ba25
     def cancel_and_wait(self, drive='drive0', force=False, resume=False):
26ba25
         '''Cancel a block job and wait for it to finish, returning the event'''
26ba25
-- 
26ba25
1.8.3.1
26ba25