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