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

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