diff mbox series

[for-3.1,v10,07/31] iotests.py: Add node_info()

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

Commit Message

Max Reitz Aug. 9, 2018, 9:35 p.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 | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Alberto Garcia Aug. 28, 2018, 12:48 p.m. UTC | #1
On Thu 09 Aug 2018 11:35:04 PM 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 | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 5c45788dac..6583001ac8 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -465,6 +465,16 @@ class VM(qtest.QEMUQtestMachine):
>                  else:
>                      iotests.log(ev)
>  
> +    def node_info(self, node_name, require_existence=True):
> +        nodes = self.qmp('query-named-block-nodes')
> +        for x in nodes['return']:
> +            if x['node-name'] == node_name:
> +                return x
> +        if require_existence:
> +            assert False
> +        else:
> +            return None
> +

I don't think you need the require_existence parameter here... if you
simply return None you'll get an error as soon as you try to use the
return value.

Berto
Max Reitz Aug. 29, 2018, 9:45 a.m. UTC | #2
On 2018-08-28 14:48, Alberto Garcia wrote:
> On Thu 09 Aug 2018 11:35:04 PM 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 | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
>> index 5c45788dac..6583001ac8 100644
>> --- a/tests/qemu-iotests/iotests.py
>> +++ b/tests/qemu-iotests/iotests.py
>> @@ -465,6 +465,16 @@ class VM(qtest.QEMUQtestMachine):
>>                  else:
>>                      iotests.log(ev)
>>  
>> +    def node_info(self, node_name, require_existence=True):
>> +        nodes = self.qmp('query-named-block-nodes')
>> +        for x in nodes['return']:
>> +            if x['node-name'] == node_name:
>> +                return x
>> +        if require_existence:
>> +            assert False
>> +        else:
>> +            return None
>> +
> 
> I don't think you need the require_existence parameter here... if you
> simply return None you'll get an error as soon as you try to use the
> return value.

Hm!  True.  I'm not sure I like the non-verbosity of "Did not find key X
in None" (or whatever error Python's going to throw), but then again,
"assert False" is not really any better.  So, yep, will change.

Thanks for reviewing,

Max
diff mbox series

Patch

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