[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 22/23] iotests: Add assert_json_filename_equal() meth
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 22/23] iotests: Add assert_json_filename_equal() method |
Date: |
Thu, 27 Oct 2016 20:09:06 +0200 |
From: Max Reitz <address@hidden>
Since the order of keys in JSON filenames is not necessarily fixed, they
should not be compared to fixed strings. This method takes a Python dict
as a reference, parses a given JSON filename and compares both.
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
tests/qemu-iotests/iotests.py | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index c589deb..1f30cfc 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -222,6 +222,19 @@ 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 assert_qmp_absent(self, d, path):
try:
result = self.dictpath(d, path)
@@ -252,6 +265,13 @@ class QMPTestCase(unittest.TestCase):
self.assertTrue(False, "Cannot find %s %s in result:\n%s" % \
(node_name, file_name, result))
+ def assert_json_filename_equal(self, json_filename, reference):
+ '''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))
+
def cancel_and_wait(self, drive='drive0', force=False, resume=False):
'''Cancel a block job and wait for it to finish, returning the event'''
result = self.vm.qmp('block-job-cancel', device=drive, force=force)
--
1.8.3.1
- [Qemu-devel] [PULL 13/23] block/nbd: Default port in nbd_refresh_filename(), (continued)
- [Qemu-devel] [PULL 13/23] block/nbd: Default port in nbd_refresh_filename(), Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 10/23] qemu-iotests: Fix typo for NFS with IMGOPTSSYNTAX, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 15/23] block/nbd: Add nbd_has_filename_options_conflict(), Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 14/23] block/nbd: Use qdict_put(), Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 18/23] qapi: Allow blockdev-add for NBD, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 16/23] block/nbd: Accept SocketAddress, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 17/23] block/nbd: Use SocketAddress options, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 21/23] socket_scm_helper: Accept fd directly, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 19/23] iotests.py: Add qemu_nbd function, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 20/23] iotests.py: Allow concurrent qemu instances, Kevin Wolf, 2016/10/27
- [Qemu-devel] [PULL 22/23] iotests: Add assert_json_filename_equal() method,
Kevin Wolf <=
- [Qemu-devel] [PULL 23/23] iotests: Add test for NBD's blockdev-add interface, Kevin Wolf, 2016/10/27
- Re: [Qemu-devel] [PULL 00/23] Block layer patches, Peter Maydell, 2016/10/28