From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Thomas Huth <thuth@redhat.com>,
Beraldo Leal <bleal@redhat.com>,
qemu-block@nongnu.org, John Snow <jsnow@redhat.com>,
Hanna Reitz <hreitz@redhat.com>, Cleber Rosa <crosa@redhat.com>,
Eric Blake <eblake@redhat.com>
Subject: [PATCH v3 5/5] iotests: fortify compare_images() against crashes
Date: Mon, 7 Mar 2022 20:57:28 -0500 [thread overview]
Message-ID: <20220308015728.1269649-6-jsnow@redhat.com> (raw)
In-Reply-To: <20220308015728.1269649-1-jsnow@redhat.com>
Fortify compare_images() to be more discerning about the status codes it
receives. If qemu_img() returns an exit code that implies it didn't
actually perform the comparison, treat that as an exceptional
circumstance and force the caller to be aware of the peril.
If a negative test is desired (perhaps to test how qemu_img compare
behaves on malformed images, for instance), it is still possible to
catch the exception in the test and deal with that circumstance
manually.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
tests/qemu-iotests/iotests.py | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index ec4568b24a..7057db0686 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -506,11 +506,22 @@ def qemu_nbd_popen(*args):
p.kill()
p.wait()
-def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt):
- '''Return True if two image files are identical'''
- res = qemu_img('compare', '-f', fmt1,
- '-F', fmt2, img1, img2, check=False)
- return res.returncode == 0
+def compare_images(img1: str, img2: str,
+ fmt1: str = imgfmt, fmt2: str = imgfmt) -> bool:
+ """
+ Compare two images with QEMU_IMG; return True if they are identical.
+
+ :raise CalledProcessError:
+ when qemu-img crashes or returns a status code of anything other
+ than 0 (identical) or 1 (different).
+ """
+ try:
+ qemu_img('compare', '-f', fmt1, '-F', fmt2, img1, img2)
+ return True
+ except subprocess.CalledProcessError as exc:
+ if exc.returncode == 1:
+ return False
+ raise
def create_image(name, size):
'''Create a fully-allocated raw image with sector markers'''
--
2.34.1
next prev parent reply other threads:[~2022-03-08 2:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 1:57 [PATCH v3 0/5] iotests: add enhanced debugging info to qemu-img failures John Snow
2022-03-08 1:57 ` [PATCH v3 1/5] python/utils: add add_visual_margin() text decoration utility John Snow
2022-03-17 10:29 ` Hanna Reitz
2022-03-08 1:57 ` [PATCH v3 2/5] python/utils: add VerboseProcessError John Snow
2022-03-17 9:23 ` Hanna Reitz
2022-03-17 15:13 ` John Snow
2022-03-17 15:56 ` Hanna Reitz
2022-03-17 16:31 ` John Snow
2022-03-17 16:34 ` Hanna Reitz
2022-03-17 16:48 ` John Snow
2022-03-08 1:57 ` [PATCH v3 3/5] iotests: Remove explicit checks for qemu_img() == 0 John Snow
2022-03-08 15:15 ` Eric Blake
2022-03-08 17:04 ` John Snow
2022-03-17 10:28 ` Hanna Reitz
2022-03-08 1:57 ` [PATCH v3 4/5] iotests: make qemu_img raise on non-zero rc by default John Snow
2022-03-17 10:25 ` Hanna Reitz
2022-03-17 10:41 ` Hanna Reitz
2022-03-17 14:23 ` John Snow
2022-03-17 15:24 ` John Snow
2022-03-17 15:58 ` Hanna Reitz
2022-03-17 16:06 ` Hanna Reitz
2022-03-08 1:57 ` John Snow [this message]
2022-03-17 10:28 ` [PATCH v3 5/5] iotests: fortify compare_images() against crashes 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=20220308015728.1269649-6-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/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).