diff mbox series

[v9,07/31] iotests.py: Add node_info()

Message ID 20180628000745.4477-8-mreitz@redhat.com
State New
Headers show
Series block: Fix some filename generation issues | expand

Commit Message

Max Reitz June 28, 2018, 12:07 a.m. UTC
This function queries a node; since we cannot do that right now, it
executes query-named-block-nodes and returns the matching node's object.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/iotests.py | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Alberto Garcia Aug. 7, 2018, 2:49 p.m. UTC | #1
On Thu 28 Jun 2018 02:07:21 AM CEST, Max Reitz wrote:
> This function queries a node; since we cannot do that right now, it
> executes query-named-block-nodes and returns the matching node's object.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 5c45788dac..3b18907f6a 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -465,6 +465,13 @@ class VM(qtest.QEMUQtestMachine):
>                  else:
>                      iotests.log(ev)
>  
> +    def node_info(self, node_name):
> +        nodes = self.qmp('query-named-block-nodes')
> +        for x in nodes['return']:
> +            if x['node-name'] == node_name:
> +                return x
> +        assert False
> +

There are cases in which you want to verify that a node doesn't exist
anymore (e.g. after you have removed it), so it would be nice to return
None if the node doesn't exist.

I actually have a similar function (minus the "return None" part) in one
of my tests from the blockdev-reopen series, so I could make use of this
one instead.

Berto
Max Reitz Aug. 9, 2018, 5:53 p.m. UTC | #2
On 2018-08-07 16:49, Alberto Garcia wrote:
> On Thu 28 Jun 2018 02:07:21 AM CEST, Max Reitz wrote:
>> This function queries a node; since we cannot do that right now, it
>> executes query-named-block-nodes and returns the matching node's object.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  tests/qemu-iotests/iotests.py | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
>> index 5c45788dac..3b18907f6a 100644
>> --- a/tests/qemu-iotests/iotests.py
>> +++ b/tests/qemu-iotests/iotests.py
>> @@ -465,6 +465,13 @@ class VM(qtest.QEMUQtestMachine):
>>                  else:
>>                      iotests.log(ev)
>>  
>> +    def node_info(self, node_name):
>> +        nodes = self.qmp('query-named-block-nodes')
>> +        for x in nodes['return']:
>> +            if x['node-name'] == node_name:
>> +                return x
>> +        assert False
>> +
> 
> There are cases in which you want to verify that a node doesn't exist
> anymore (e.g. after you have removed it), so it would be nice to return
> None if the node doesn't exist.

Can do (and then maybe add a wrapper function that aborts if the node
doesn't exist).

Thanks for reviewing!

Max

> I actually have a similar function (minus the "return None" part) in one
> of my tests from the blockdev-reopen series, so I could make use of this
> one instead.
> 
> Berto
>
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 5c45788dac..3b18907f6a 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -465,6 +465,13 @@  class VM(qtest.QEMUQtestMachine):
                 else:
                     iotests.log(ev)
 
+    def node_info(self, node_name):
+        nodes = self.qmp('query-named-block-nodes')
+        for x in nodes['return']:
+            if x['node-name'] == node_name:
+                return x
+        assert False
+
 
 index_re = re.compile(r'([^\[]+)\[([^\]]+)\]')