Blame SOURCES/kvm-iotests-Move-qmp_to_opts-to-VM.patch

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