[Qemu-devel] [PATCH 1/3] iotests.py: Add qemu_nbd_pipe()

Max Reitz posted 3 patches 6 years, 10 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
[Qemu-devel] [PATCH 1/3] iotests.py: Add qemu_nbd_pipe()
Posted by Max Reitz 6 years, 10 months ago
In some cases, we may want to deal with qemu-nbd errors (e.g. by
launching it in a different configuration until it no longer throws
any).  In that case, we do not want its output ending up in the test
output.

It may still be useful for handling the error, though, so add a new
function that works basically like qemu_nbd(), only that it returns the
qemu-nbd output instead of making it end up in the log.  In contrast to
qemu_img_pipe(), it does still return the exit code as well, though,
because that is even more important for error handling.

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

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index d537538ba0..9c3eb9e2f8 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -190,6 +190,20 @@ def qemu_nbd(*args):
     '''Run qemu-nbd in daemon mode and return the parent's exit code'''
     return subprocess.call(qemu_nbd_args + ['--fork'] + list(args))
 
+def qemu_nbd_pipe(*args):
+    '''Run qemu-nbd in daemon mode and return both the parent's exit code
+       and its output'''
+    subp = subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args),
+                            stdout=subprocess.PIPE,
+                            stderr=subprocess.STDOUT,
+                            universal_newlines=True)
+    exitcode = subp.wait()
+    if exitcode < 0:
+        sys.stderr.write('qemu-nbd received signal %i: %s\n' %
+                         (-exitcode,
+                          ' '.join(qemu_nbd_args + ['--fork'] + list(args))))
+    return exitcode, subp.communicate()[0]
+
 def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt):
     '''Return True if two image files are identical'''
     return qemu_img('compare', '-f', fmt1,
-- 
2.19.2


Re: [Qemu-devel] [PATCH 1/3] iotests.py: Add qemu_nbd_pipe()
Posted by Eric Blake 6 years, 9 months ago
On 12/21/18 5:47 PM, Max Reitz wrote:
> In some cases, we may want to deal with qemu-nbd errors (e.g. by
> launching it in a different configuration until it no longer throws
> any).  In that case, we do not want its output ending up in the test
> output.
> 
> It may still be useful for handling the error, though, so add a new
> function that works basically like qemu_nbd(), only that it returns the
> qemu-nbd output instead of making it end up in the log.  In contrast to
> qemu_img_pipe(), it does still return the exit code as well, though,

In contrast to qemu_nbd(),

> because that is even more important for error handling.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index d537538ba0..9c3eb9e2f8 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -190,6 +190,20 @@ def qemu_nbd(*args):
>      '''Run qemu-nbd in daemon mode and return the parent's exit code'''
>      return subprocess.call(qemu_nbd_args + ['--fork'] + list(args))
>  
> +def qemu_nbd_pipe(*args):
> +    '''Run qemu-nbd in daemon mode and return both the parent's exit code
> +       and its output'''
> +    subp = subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args),
> +                            stdout=subprocess.PIPE,
> +                            stderr=subprocess.STDOUT,
> +                            universal_newlines=True)
> +    exitcode = subp.wait()
> +    if exitcode < 0:
> +        sys.stderr.write('qemu-nbd received signal %i: %s\n' %
> +                         (-exitcode,
> +                          ' '.join(qemu_nbd_args + ['--fork'] + list(args))))
> +    return exitcode, subp.communicate()[0]
> +

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 1/3] iotests.py: Add qemu_nbd_pipe()
Posted by Max Reitz 6 years, 9 months ago
On 21.01.19 21:55, Eric Blake wrote:
> On 12/21/18 5:47 PM, Max Reitz wrote:
>> In some cases, we may want to deal with qemu-nbd errors (e.g. by
>> launching it in a different configuration until it no longer throws
>> any).  In that case, we do not want its output ending up in the test
>> output.
>>
>> It may still be useful for handling the error, though, so add a new
>> function that works basically like qemu_nbd(), only that it returns the
>> qemu-nbd output instead of making it end up in the log.  In contrast to
>> qemu_img_pipe(), it does still return the exit code as well, though,
> 
> In contrast to qemu_nbd(),

But qemu_nbd() does return the exit code.  qemu_img_pipe() doesn't.

>> because that is even more important for error handling.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  tests/qemu-iotests/iotests.py | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
>> index d537538ba0..9c3eb9e2f8 100644
>> --- a/tests/qemu-iotests/iotests.py
>> +++ b/tests/qemu-iotests/iotests.py
>> @@ -190,6 +190,20 @@ def qemu_nbd(*args):
>>      '''Run qemu-nbd in daemon mode and return the parent's exit code'''
>>      return subprocess.call(qemu_nbd_args + ['--fork'] + list(args))
>>  
>> +def qemu_nbd_pipe(*args):
>> +    '''Run qemu-nbd in daemon mode and return both the parent's exit code
>> +       and its output'''
>> +    subp = subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args),
>> +                            stdout=subprocess.PIPE,
>> +                            stderr=subprocess.STDOUT,
>> +                            universal_newlines=True)
>> +    exitcode = subp.wait()
>> +    if exitcode < 0:
>> +        sys.stderr.write('qemu-nbd received signal %i: %s\n' %
>> +                         (-exitcode,
>> +                          ' '.join(qemu_nbd_args + ['--fork'] + list(args))))
>> +    return exitcode, subp.communicate()[0]
>> +
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks for reviewing!

Max

Re: [Qemu-devel] [PATCH 1/3] iotests.py: Add qemu_nbd_pipe()
Posted by Eric Blake 6 years, 9 months ago
On 1/23/19 7:06 AM, Max Reitz wrote:
> On 21.01.19 21:55, Eric Blake wrote:
>> On 12/21/18 5:47 PM, Max Reitz wrote:
>>> In some cases, we may want to deal with qemu-nbd errors (e.g. by
>>> launching it in a different configuration until it no longer throws
>>> any).  In that case, we do not want its output ending up in the test
>>> output.
>>>
>>> It may still be useful for handling the error, though, so add a new
>>> function that works basically like qemu_nbd(), only that it returns the
>>> qemu-nbd output instead of making it end up in the log.  In contrast to
>>> qemu_img_pipe(), it does still return the exit code as well, though,
>>
>> In contrast to qemu_nbd(),
> 
> But qemu_nbd() does return the exit code.  qemu_img_pipe() doesn't.
> 

Oh, I see where I got confused. I thought you were comparing the new
code [qemu_nbd_pipe] to itself; not to the pre-existing qemu_img_pipe
that is not touched by this patch, but which served as the model you
copied after.

>>> because that is even more important for error handling.
>>>
>>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>>> ---
>>>  tests/qemu-iotests/iotests.py | 14 ++++++++++++++
>>>  1 file changed, 14 insertions(+)
>>>

>> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> Thanks for reviewing!

Although my questions on patch 3 call into question whether you even
need this patch, if your only use of it was to find a free port.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org