From: Eric Blake <eblake@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH 12/15] iotests/migration-permissions: use assertRaises() for qemu_io() negative test
Date: Mon, 21 Mar 2022 13:07:51 -0500 [thread overview]
Message-ID: <20220321180751.75zixieer72aahcw@redhat.com> (raw)
In-Reply-To: <20220318203655.676907-13-jsnow@redhat.com>
On Fri, Mar 18, 2022 at 04:36:52PM -0400, John Snow wrote:
> Modify this test to use assertRaises for its negative testing of
> qemu_io. If the exception raised does not match the one we tell it to
> expect, we get *that* exception unhandled. If we get no exception, we
> get a unittest assertion failure and the provided emsg printed to
> screen.
>
> If we get the CalledProcessError exception but the output is not what we
> expect, we re-raise the original CalledProcessError.
>
> Tidy.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> .../qemu-iotests/tests/migration-permissions | 28 +++++++++----------
> 1 file changed, 14 insertions(+), 14 deletions(-)
The 11/15 patch is also included in my R-b of the squashed patch.
For this patch, it's a wash on lines of code, but certainly a more
robust test now than with the hack of the fixup patch 11/15.
>
> diff --git a/tests/qemu-iotests/tests/migration-permissions b/tests/qemu-iotests/tests/migration-permissions
> index c7afb1bd2c..4e1da369c9 100755
> --- a/tests/qemu-iotests/tests/migration-permissions
> +++ b/tests/qemu-iotests/tests/migration-permissions
> @@ -18,6 +18,8 @@
> #
>
> import os
> +from subprocess import CalledProcessError
> +
> import iotests
> from iotests import imgfmt, qemu_img_create, qemu_io
>
> @@ -69,13 +71,12 @@ class TestMigrationPermissions(iotests.QMPTestCase):
> def test_post_migration_permissions(self):
> # Try to access the image R/W, which should fail because virtio-blk
> # has not been configured with share-rw=on
> - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout
> - if not log.strip():
> - print('ERROR (pre-migration): qemu-io should not be able to '
> - 'access this image, but it reported no error')
> - else:
> - # This is the expected output
> - assert 'Is another process using the image' in log
> + emsg = ('ERROR (pre-migration): qemu-io should not be able to '
> + 'access this image, but it reported no error')
> + with self.assertRaises(CalledProcessError, msg=emsg) as ctx:
> + qemu_io('-f', imgfmt, '-c', 'quit', test_img)
> + if 'Is another process using the image' not in ctx.exception.stdout:
Wait a minute - is 'ctx' still in scope after the 'with ... as ctx:'
with scope ends? Python continues to surprise me.
> + raise ctx.exception
>
> # Now migrate the VM
> self.vm_s.qmp('migrate', uri=f'unix:{mig_sock}')
> @@ -84,13 +85,12 @@ class TestMigrationPermissions(iotests.QMPTestCase):
>
> # Try the same qemu-io access again, verifying that the WRITE
> # permission remains unshared
> - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout
> - if not log.strip():
> - print('ERROR (post-migration): qemu-io should not be able to '
> - 'access this image, but it reported no error')
> - else:
> - # This is the expected output
> - assert 'Is another process using the image' in log
> + emsg = ('ERROR (post-migration): qemu-io should not be able to '
> + 'access this image, but it reported no error')
> + with self.assertRaises(CalledProcessError, msg=emsg) as ctx:
> + qemu_io('-f', imgfmt, '-c', 'quit', test_img)
> + if 'Is another process using the image' not in ctx.exception.stdout:
> + raise ctx.exception
The cover letter didn't mention a Based-on: tag, and so my first
attempt to reproduce this hit a rebase error on 5/15 followed by
'./check -raw migration-permissions' on this patch failing with:
+Traceback (most recent call last):
+ File "/home/eblake/qemu/tests/qemu-iotests/tests/migration-permissions", line 77, in test_post_migration_permissions
+ qemu_io('-f', imgfmt, '-c', 'quit', test_img)
+ File "/home/eblake/qemu/tests/qemu-iotests/iotests.py", line 334, in qemu_io
+ return qemu_tool(*qemu_io_wrap_args(args),
+ File "/home/eblake/qemu/tests/qemu-iotests/iotests.py", line 249, in qemu_tool
+ raise VerboseProcessError(
+NameError: name 'VerboseProcessError' is not defined
so it's pretty obvious I didn't apply the pre-requisite patch that
introduced VerboseProcessError in order to fix qemu_img() first. But
with more churn on my end (applying your v4 qemu_img series first), it
looks like accessing ctx.exception after the with clause ends (even
though the with clause is what brought ctx into existance) works, so:
Reviewed-by: Eric Blake <eblake@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2022-03-21 18:08 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 20:36 [PATCH 00/15] iotests: add enhanced debugging info to qemu-io failures John Snow
2022-03-18 20:36 ` [PATCH 01/15] iotests: replace calls to log(qemu_io(...)) with qemu_io_log() John Snow
2022-03-21 13:35 ` Eric Blake
2022-03-22 13:51 ` Hanna Reitz
2022-03-18 20:36 ` [PATCH 02/15] iotests/163: Fix broken qemu-io invocation John Snow
2022-03-21 13:44 ` Eric Blake
2022-03-22 14:07 ` Hanna Reitz
2022-03-18 20:36 ` [PATCH 03/15] iotests: Don't check qemu_io() output for specific error strings John Snow
2022-03-21 13:48 ` Eric Blake
2022-03-22 14:16 ` Hanna Reitz
2022-03-18 20:36 ` [PATCH 04/15] iotests/040: Don't check image pattern on zero-length image John Snow
2022-03-21 14:58 ` Eric Blake
2022-03-22 14:22 ` Hanna Reitz
2022-03-22 16:19 ` John Snow
2022-03-22 17:12 ` Hanna Reitz
2022-03-18 20:36 ` [PATCH 05/15] iotests: create generic qemu_tool() function John Snow
2022-03-21 15:13 ` Eric Blake
2022-03-21 16:20 ` John Snow
2022-03-22 14:49 ` Hanna Reitz
2022-03-22 16:25 ` John Snow
2022-03-18 20:36 ` [PATCH 06/15] iotests: rebase qemu_io() on top of qemu_tool() John Snow
2022-03-21 15:29 ` Eric Blake
2022-03-21 16:57 ` John Snow
2022-03-22 15:04 ` Hanna Reitz
2022-03-22 16:30 ` John Snow
2022-03-18 20:36 ` [PATCH 07/15] iotests/030: fixup John Snow
2022-03-18 20:36 ` [PATCH 08/15] iotests/149: fixup John Snow
2022-03-22 16:29 ` Hanna Reitz
2022-03-18 20:36 ` [PATCH 09/15] iotests/205: fixup John Snow
2022-03-18 20:36 ` [PATCH 10/15] iotests/245: fixup John Snow
2022-03-21 17:42 ` Eric Blake
2022-03-22 16:30 ` Hanna Reitz
2022-03-22 16:36 ` John Snow
2022-03-22 16:38 ` Hanna Reitz
2022-03-22 17:00 ` John Snow
2022-03-18 20:36 ` [PATCH 11/15] iotests/migration-permissions: fixup John Snow
2022-03-18 20:36 ` [PATCH 12/15] iotests/migration-permissions: use assertRaises() for qemu_io() negative test John Snow
2022-03-21 18:07 ` Eric Blake [this message]
2022-03-22 16:37 ` Hanna Reitz
2022-03-22 17:12 ` John Snow
2022-03-18 20:36 ` [PATCH 13/15] iotests: remove qemu_io_pipe_and_status() John Snow
2022-03-21 18:09 ` Eric Blake
2022-03-22 16:39 ` Hanna Reitz
2022-03-22 19:28 ` John Snow
2022-03-18 20:36 ` [PATCH 14/15] iotests: remove qemu_io_silent() and qemu_io_silent_check() John Snow
2022-03-21 18:16 ` Eric Blake
2022-03-21 20:07 ` John Snow
2022-03-22 16:59 ` Hanna Reitz
2022-03-22 17:16 ` John Snow
2022-03-18 20:36 ` [PATCH 15/15] iotests: make qemu_io_log() check return codes by default John Snow
2022-03-21 18:22 ` Eric Blake
2022-03-21 20:09 ` John Snow
2022-03-22 17:03 ` Hanna Reitz
2022-03-22 17:18 ` [PATCH 00/15] iotests: add enhanced debugging info to qemu-io failures Hanna Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220321180751.75zixieer72aahcw@redhat.com \
--to=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).