提交 62a94288 编写于 作者: K Kevin Wolf

iotests: Move qmp_to_opts() to VM

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: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NMax Reitz <mreitz@redhat.com>
上级 9f6bb4c0
......@@ -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):
......
......@@ -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()
......
......@@ -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'''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册