[PATCH 2/4] iotests.py: QemuIoInteractive: print output on failure

Vladimir Sementsov-Ogievskiy posted 4 patches 5 years, 7 months ago
Maintainers: Max Reitz <mreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Eric Blake <eblake@redhat.com>
There is a newer version of this series
[PATCH 2/4] iotests.py: QemuIoInteractive: print output on failure
Posted by Vladimir Sementsov-Ogievskiy 5 years, 7 months ago
Make it simpler to debug when qemu-io failes due to wrong arguments or
environment.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 tests/qemu-iotests/iotests.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index efe9958f5e..ac9d199a1e 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -216,7 +216,13 @@ class QemuIoInteractive:
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
                                    universal_newlines=True)
-        assert self._p.stdout.read(9) == 'qemu-io> '
+        out = self._p.stdout.read(9)
+        if out != 'qemu-io> ':
+            # Most probably qemu-io just failed to start.
+            # Let's collect the whole output and exit.
+            out += self._p.stdout.read()
+            self._p.wait(timeout=1)
+            raise ValueError(out)
 
     def close(self):
         self._p.communicate('q\n')
-- 
2.21.0


Re: [PATCH 2/4] iotests.py: QemuIoInteractive: print output on failure
Posted by Eric Blake 5 years, 7 months ago
On 6/25/20 9:25 AM, Vladimir Sementsov-Ogievskiy wrote:
> Make it simpler to debug when qemu-io failes due to wrong arguments or

fails

> environment.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>   tests/qemu-iotests/iotests.py | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index efe9958f5e..ac9d199a1e 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -216,7 +216,13 @@ class QemuIoInteractive:
>                                      stdout=subprocess.PIPE,
>                                      stderr=subprocess.STDOUT,
>                                      universal_newlines=True)
> -        assert self._p.stdout.read(9) == 'qemu-io> '
> +        out = self._p.stdout.read(9)
> +        if out != 'qemu-io> ':
> +            # Most probably qemu-io just failed to start.
> +            # Let's collect the whole output and exit.
> +            out += self._p.stdout.read()
> +            self._p.wait(timeout=1)
> +            raise ValueError(out)
>   

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

>       def close(self):
>           self._p.communicate('q\n')
> 

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