[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 45/46] iotests: Move qmp_to_opts() to VM
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 45/46] iotests: Move qmp_to_opts() to VM |
Date: |
Wed, 23 May 2018 15:11:54 +0200 |
qmp_to_opts() used to be a method of QMPTestCase, but recently we
started to add more Python test cases that don't make use of
QMPTestCase. In order to make the method usable there, move it to VM.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/041 | 6 +++---
tests/qemu-iotests/155 | 2 +-
tests/qemu-iotests/iotests.py | 45 ++++++++++++++++++++++---------------------
3 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index e94587950c..c20ac7da87 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -1030,9 +1030,9 @@ class TestOrphanedSource(iotests.QMPTestCase):
'read-only': 'on' }
self.vm = iotests.VM()
- self.vm.add_blockdev(self.qmp_to_opts(blk0))
- self.vm.add_blockdev(self.qmp_to_opts(blk1))
- self.vm.add_blockdev(self.qmp_to_opts(blk2))
+ self.vm.add_blockdev(self.vm.qmp_to_opts(blk0))
+ self.vm.add_blockdev(self.vm.qmp_to_opts(blk1))
+ self.vm.add_blockdev(self.vm.qmp_to_opts(blk2))
self.vm.launch()
def tearDown(self):
diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
index 42dae04c83..63a5b5e2c0 100755
--- a/tests/qemu-iotests/155
+++ b/tests/qemu-iotests/155
@@ -63,7 +63,7 @@ class BaseClass(iotests.QMPTestCase):
'driver': iotests.imgfmt,
'file': {'driver': 'file',
'filename': source_img}}
- self.vm.add_blockdev(self.qmp_to_opts(blockdev))
+ self.vm.add_blockdev(self.vm.qmp_to_opts(blockdev))
self.vm.add_device('virtio-blk,id=qdev0,drive=source')
self.vm.launch()
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index ed08e06e1f..28159d837a 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -363,6 +363,27 @@ class VM(qtest.QEMUQtestMachine):
return self.qmp('human-monitor-command',
command_line='qemu-io %s "%s"' % (drive, cmd))
+ def flatten_qmp_object(self, obj, output=None, basestr=''):
+ if output is None:
+ output = dict()
+ if isinstance(obj, list):
+ for i in range(len(obj)):
+ self.flatten_qmp_object(obj[i], output, basestr + str(i) + '.')
+ elif isinstance(obj, dict):
+ for key in obj:
+ self.flatten_qmp_object(obj[key], output, basestr + key + '.')
+ else:
+ output[basestr[:-1]] = obj # Strip trailing '.'
+ return output
+
+ def qmp_to_opts(self, obj):
+ obj = self.flatten_qmp_object(obj)
+ output_list = list()
+ for key in obj:
+ output_list += [key + '=' + obj[key]]
+ return ','.join(output_list)
+
+
index_re = re.compile(r'([^\[]+)\[([^\]]+)\]')
@@ -390,26 +411,6 @@ class QMPTestCase(unittest.TestCase):
self.fail('invalid index "%s" in path "%s" in "%s"' %
(idx, path, str(d)))
return d
- def flatten_qmp_object(self, obj, output=None, basestr=''):
- if output is None:
- output = dict()
- if isinstance(obj, list):
- for i in range(len(obj)):
- self.flatten_qmp_object(obj[i], output, basestr + str(i) + '.')
- elif isinstance(obj, dict):
- for key in obj:
- self.flatten_qmp_object(obj[key], output, basestr + key + '.')
- else:
- output[basestr[:-1]] = obj # Strip trailing '.'
- return output
-
- def qmp_to_opts(self, obj):
- obj = self.flatten_qmp_object(obj)
- output_list = list()
- for key in obj:
- output_list += [key + '=' + obj[key]]
- return ','.join(output_list)
-
def assert_qmp_absent(self, d, path):
try:
result = self.dictpath(d, path)
@@ -444,8 +445,8 @@ class QMPTestCase(unittest.TestCase):
'''Asserts that the given filename is a json: filename and that its
content is equal to the given reference object'''
self.assertEqual(json_filename[:5], 'json:')
-
self.assertEqual(self.flatten_qmp_object(json.loads(json_filename[5:])),
- self.flatten_qmp_object(reference))
+
self.assertEqual(self.vm.flatten_qmp_object(json.loads(json_filename[5:])),
+ self.vm.flatten_qmp_object(reference))
def cancel_and_wait(self, drive='drive0', force=False, resume=False):
'''Cancel a block job and wait for it to finish, returning the event'''
--
2.13.6
- [Qemu-devel] [PULL 34/46] block: Cancel job in bdrv_close_all() callers, (continued)
- [Qemu-devel] [PULL 34/46] block: Cancel job in bdrv_close_all() callers, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 30/46] job: Move job_finish_sync() to Job, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 37/46] job: Add job_is_ready(), Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 39/46] job: Move progress fields to Job, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 33/46] job: Move completion and cancellation to Job, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 36/46] job: Add job_dismiss(), Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 31/46] job: Switch transactions to JobTxn, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 43/46] job: Add query-jobs QMP command, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 44/46] blockjob: Remove BlockJob.driver, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 42/46] job: Add lifecycle QMP commands, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 45/46] iotests: Move qmp_to_opts() to VM,
Kevin Wolf <=
- [Qemu-devel] [PULL 35/46] job: Add job_yield(), Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 40/46] job: Introduce qapi/job.json, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 32/46] job: Move transactions to Job, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 46/46] qemu-iotests: Test job-* with block jobs, Kevin Wolf, 2018/05/23
- [Qemu-devel] [PULL 41/46] job: Add JOB_STATUS_CHANGE QMP event, Kevin Wolf, 2018/05/23
- Re: [Qemu-devel] [PULL 00/46] Block layer patches, no-reply, 2018/05/23
- Re: [Qemu-devel] [PULL 00/46] Block layer patches, Peter Maydell, 2018/05/24