[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 17/22] iotests: Add VM.assert_block_path()
From: |
Max Reitz |
Subject: |
[PATCH 17/22] iotests: Add VM.assert_block_path() |
Date: |
Fri, 20 Sep 2019 17:27:59 +0200 |
Signed-off-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/iotests.py | 48 +++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index daed4ee013..e6fb46287d 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -670,6 +670,54 @@ class VM(qtest.QEMUQtestMachine):
return fields.items() <= ret.items()
+ '''
+ @path is a string whose components are separated by slashes.
+ The first component is a node name, the rest are child names.
+ Examples:
+ - "qcow2-node/backing/file"
+ - "quorum-node/children.2/file"
+
+ @expected_node may be None.
+
+ @graph may be None or the result of an x-debug-query-block-graph
+ call that has already been performed.
+ '''
+ def assert_block_path(self, path, expected_node, graph=None):
+ if graph is None:
+ graph = self.qmp('x-debug-query-block-graph')['return']
+
+ iter_path = iter(path.split('/'))
+ root = next(iter_path)
+ try:
+ node = next(node for node in graph['nodes'] if node['name'] ==
root)
+ except StopIteration:
+ node = None
+
+ for path_node in iter_path:
+ assert node is not None, 'Cannot follow path %s' % path
+
+ try:
+ node_id = next(edge['child'] for edge in graph['edges'] \
+ if edge['parent'] == node['id']
and
+ edge['name'] == path_node)
+
+ node = next(node for node in graph['nodes'] \
+ if node['id'] == node_id)
+ except StopIteration:
+ node = None
+
+ assert node is not None or expected_node is None, \
+ 'No node found under %s (but expected %s)' % \
+ (path, expected_node)
+
+ assert expected_node is not None or node is None, \
+ 'Found node %s under %s (but expected none)' % \
+ (node['name'], path)
+
+ if node is not None and expected_node is not None:
+ assert node['name'] == expected_node, \
+ 'Found node %s under %s (but expected %s)' % \
+ (node['name'], path, expected_node)
index_re = re.compile(r'([^\[]+)\[([^\]]+)\]')
--
2.21.0
- Re: [PATCH 14/22] quorum: Stop marking it as a filter, (continued)
- [PATCH 10/22] quorum: Implement .bdrv_recurse_can_replace(), Max Reitz, 2019/09/20
- [PATCH 13/22] mirror: Double-check immediately before replacing, Max Reitz, 2019/09/20
- [PATCH 16/22] iotests: Use complete_and_wait() in 155, Max Reitz, 2019/09/20
- [PATCH 17/22] iotests: Add VM.assert_block_path(),
Max Reitz <=
- [PATCH 15/22] mirror: Prevent loops, Max Reitz, 2019/09/20
- [PATCH 19/22] iotests: Use self.image_len in TestRepairQuorum, Max Reitz, 2019/09/20
- [PATCH 21/22] iotests: Check that @replaces can replace filters, Max Reitz, 2019/09/20
- [PATCH 20/22] iotests: Add tests for invalid Quorum @replaces, Max Reitz, 2019/09/20
- [PATCH 18/22] iotests: Resolve TODOs in 041, Max Reitz, 2019/09/20