From nobody Sun May 19 00:17:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646706110651226.6315408230605; Mon, 7 Mar 2022 18:21:50 -0800 (PST) Received: from localhost ([::1]:40090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRPTx-0004l4-BP for importer@patchew.org; Mon, 07 Mar 2022 21:21:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6f-0005U4-NG for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:57:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6e-0000I3-1L for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:57:45 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-538-d03IkE1KNMO6DM_J_E0DBg-1; Mon, 07 Mar 2022 20:57:40 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F3F51006AA5; Tue, 8 Mar 2022 01:57:38 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.10.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18CD41971B; Tue, 8 Mar 2022 01:57:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646704663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3+T19ZE3FUv+dLZnHEsRtDjfTL4lSuZZ5EcuZFA+/38=; b=TF+Q60DdJMDfGRo8cIhR4BmKeUjYayfGtG6vnT7zQ79J13n9rgOCUVZvU0vUknwswSlr5T wUxO1OIX68VUa+/hsOR9NokIhh4kBlKCqFrXvTTlQmvWEtMmZz6PvcVjRV458BoeQJ8adV e/bRIlgJaEpVmfM4u7fp30cSbvMqYgU= X-MC-Unique: d03IkE1KNMO6DM_J_E0DBg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 1/5] python/utils: add add_visual_margin() text decoration utility Date: Mon, 7 Mar 2022 20:57:24 -0500 Message-Id: <20220308015728.1269649-2-jsnow@redhat.com> In-Reply-To: <20220308015728.1269649-1-jsnow@redhat.com> References: <20220308015728.1269649-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Thomas Huth , Beraldo Leal , qemu-block@nongnu.org, John Snow , Hanna Reitz , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646706111677100001 >>> print(add_visual_margin(msg, width=3D72, name=3D"Commit Message")) =E2=94=8F=E2=94=81 Commit Message =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 =E2=94=83 add_visual_margin() takes a chunk of text and wraps it in a visual =E2=94=83 container that force-wraps to a specified width. An optional title =E2=94=83 label may be given, and any of the individual glyphs used to draw= the =E2=94=83 box may be replaced or specified as well. =E2=94=97=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 Signed-off-by: John Snow Reviewed-by: Eric Blake Acked-by: Hanna Reitz --- python/qemu/utils/__init__.py | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/python/qemu/utils/__init__.py b/python/qemu/utils/__init__.py index 7f1a5138c4..5babf40df2 100644 --- a/python/qemu/utils/__init__.py +++ b/python/qemu/utils/__init__.py @@ -15,7 +15,10 @@ # the COPYING file in the top-level directory. # =20 +import os import re +import shutil +import textwrap from typing import Optional =20 # pylint: disable=3Dimport-error @@ -23,6 +26,7 @@ =20 =20 __all__ =3D ( + 'add_visual_margin', 'get_info_usernet_hostfwd_port', 'kvm_available', 'list_accel', @@ -43,3 +47,77 @@ def get_info_usernet_hostfwd_port(info_usernet_output: s= tr) -> Optional[int]: if match is not None: return int(match[1]) return None + + +# pylint: disable=3Dtoo-many-arguments +def add_visual_margin( + content: str =3D '', + width: Optional[int] =3D None, + name: Optional[str] =3D None, + padding: int =3D 1, + upper_left: str =3D '=E2=94=8F', + lower_left: str =3D '=E2=94=97', + horizontal: str =3D '=E2=94=81', + vertical: str =3D '=E2=94=83', +) -> str: + """ + Decorate and wrap some text with a visual decoration around it. + + This function assumes that the text decoration characters are single + characters that display using a single monospace column. + + =E2=94=8F=E2=94=81 Example =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 + =E2=94=83 This is what this function looks like with text content that= 's + =E2=94=83 wrapped to 72 characters. The right-hand margin is left open= to + =E2=94=83 acommodate the occasional unicode character that might make + =E2=94=83 predicting the total "visual" width of a line difficult. This + =E2=94=83 provides a visual distinction that's good-enough, though. + =E2=94=97=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94= =81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 + + :param content: The text to wrap and decorate. + :param width: + The number of columns to use, including for the decoration + itself. The default (None) uses the the available width of the + current terminal, or a fallback of 72 lines. A negative number + subtracts a fixed-width from the default size. The default obeys + the COLUMNS environment variable, if set. + :param name: A label to apply to the upper-left of the box. + :param padding: How many columns of padding to apply inside. + :param upper_left: Upper-left single-width text decoration character. + :param lower_left: Lower-left single-width text decoration character. + :param horizontal: Horizontal single-width text decoration character. + :param vertical: Vertical single-width text decoration character. + """ + if width is None or width < 0: + avail =3D shutil.get_terminal_size(fallback=3D(72, 24))[0] + if width is None: + _width =3D avail + else: + _width =3D avail + width + else: + _width =3D width + + prefix =3D vertical + (' ' * padding) + + def _bar(name: Optional[str], top: bool =3D True) -> str: + ret =3D upper_left if top else lower_left + if name is not None: + ret +=3D f"{horizontal} {name} " + + filler_len =3D _width - len(ret) + ret +=3D f"{horizontal * filler_len}" + return ret + + def _wrap(line: str) -> str: + return os.linesep.join( + textwrap.wrap( + line, width=3D_width - padding, initial_indent=3Dprefix, + subsequent_indent=3Dprefix, replace_whitespace=3DFalse, + drop_whitespace=3DTrue, break_on_hyphens=3DFalse) + ) + + return os.linesep.join(( + _bar(name, top=3DTrue), + os.linesep.join(_wrap(line) for line in content.splitlines()), + _bar(None, top=3DFalse), + )) --=20 2.34.1 From nobody Sun May 19 00:17:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646705229375776.1978788577005; Mon, 7 Mar 2022 18:07:09 -0800 (PST) Received: from localhost ([::1]:43730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRPFk-0004Ld-DM for importer@patchew.org; Mon, 07 Mar 2022 21:07:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6n-0005zM-SG for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:57:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6l-0000JH-LZ for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:57:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-ymVmlfd6OcG-E2ZsET_2KA-1; Mon, 07 Mar 2022 20:57:48 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A3051006AA5; Tue, 8 Mar 2022 01:57:47 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.10.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B07D17A82; Tue, 8 Mar 2022 01:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646704671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=st6tTpBGO6+VOWAjFkrRaUu48mOFWD7d/5t5gAtjJws=; b=O3a+ERH07CJ+BZ86tnzGbLMBP4iOX4aJiEZGaVX1pfNRgznXfFXpx7Dk0IFxF/Her/QC/w WWtJ4kQkzdDSiLwbR4HB6unQDGdsYUUzrnWMLJudD7plMdXxeDG/cHnI6h+/Z4Q+fJvZj5 fGadUXAac5wfyA8Zr/UQKl47nYNgLtQ= X-MC-Unique: ymVmlfd6OcG-E2ZsET_2KA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 2/5] python/utils: add VerboseProcessError Date: Mon, 7 Mar 2022 20:57:25 -0500 Message-Id: <20220308015728.1269649-3-jsnow@redhat.com> In-Reply-To: <20220308015728.1269649-1-jsnow@redhat.com> References: <20220308015728.1269649-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Thomas Huth , Beraldo Leal , qemu-block@nongnu.org, John Snow , Hanna Reitz , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646705229793100001 Content-Type: text/plain; charset="utf-8" This adds an Exception that extends the Python stdlib subprocess.CalledProcessError. The difference is that the str() method of this exception also adds the stdout/stderr logs. In effect, if this exception goes unhandled, Python will print the output in a visually distinct wrapper to the terminal so that it's easy to spot in a sea of traceback information. Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- python/qemu/utils/__init__.py | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/python/qemu/utils/__init__.py b/python/qemu/utils/__init__.py index 5babf40df2..355ac550bc 100644 --- a/python/qemu/utils/__init__.py +++ b/python/qemu/utils/__init__.py @@ -18,6 +18,7 @@ import os import re import shutil +from subprocess import CalledProcessError import textwrap from typing import Optional =20 @@ -26,6 +27,7 @@ =20 =20 __all__ =3D ( + 'VerboseProcessError', 'add_visual_margin', 'get_info_usernet_hostfwd_port', 'kvm_available', @@ -121,3 +123,37 @@ def _wrap(line: str) -> str: os.linesep.join(_wrap(line) for line in content.splitlines()), _bar(None, top=3DFalse), )) + + +class VerboseProcessError(CalledProcessError): + """ + The same as CalledProcessError, but more verbose. + + This is useful for debugging failed calls during test executions. + The return code, signal (if any), and terminal output will be displayed + on unhandled exceptions. + """ + def summary(self) -> str: + """Return the normal CalledProcessError str() output.""" + return super().__str__() + + def __str__(self) -> str: + lmargin =3D ' ' + width =3D -len(lmargin) + sections =3D [] + + name =3D 'output' if self.stderr is None else 'stdout' + if self.stdout: + sections.append(add_visual_margin(self.stdout, width, name)) + else: + sections.append(f"{name}: N/A") + + if self.stderr: + sections.append(add_visual_margin(self.stderr, width, 'stderr'= )) + elif self.stderr is not None: + sections.append("stderr: N/A") + + return os.linesep.join(( + self.summary(), + textwrap.indent(os.linesep.join(sections), prefix=3Dlmargin), + )) --=20 2.34.1 From nobody Sun May 19 00:17:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646705457249909.7790391194602; Mon, 7 Mar 2022 18:10:57 -0800 (PST) Received: from localhost ([::1]:54230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRPJP-0002yg-QD for importer@patchew.org; Mon, 07 Mar 2022 21:10:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6n-0005xk-F7 for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:57:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6l-0000J9-3a for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:57:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-577-UOi5FVF8MKS5x57NynBbfg-1; Mon, 07 Mar 2022 20:57:49 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7845B801AFC; Tue, 8 Mar 2022 01:57:48 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.10.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44A1B18512; Tue, 8 Mar 2022 01:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646704670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3j5I/O3ezJYozam8+g/RMdljj1bSBl3g/d9y19HgXeI=; b=WXfUatGIyXRvxzBehI9/ezcqtPw/meOpWxXzm76qrN/MIHXWKpi3BCq2bPA1s7QtBs2Gxz RCLDZFpTrSXup6tOcyAY008/XZEURdhaDyhnoJaIDmcurNJNgbLUR5AGbdeGRzVngS5dFl KXsjB7FvEnXpQyyNzr9hqo1Gg9AUKFg= X-MC-Unique: UOi5FVF8MKS5x57NynBbfg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 3/5] iotests: Remove explicit checks for qemu_img() == 0 Date: Mon, 7 Mar 2022 20:57:26 -0500 Message-Id: <20220308015728.1269649-4-jsnow@redhat.com> In-Reply-To: <20220308015728.1269649-1-jsnow@redhat.com> References: <20220308015728.1269649-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Thomas Huth , Beraldo Leal , qemu-block@nongnu.org, John Snow , Hanna Reitz , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646705459489100001 Content-Type: text/plain; charset="utf-8" qemu_img() returning zero ought to be the rule, not the exception. Remove all explicit checks against the condition in preparation for making non-zero returns an Exception. Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- tests/qemu-iotests/163 | 9 +++------ tests/qemu-iotests/216 | 6 +++--- tests/qemu-iotests/218 | 2 +- tests/qemu-iotests/224 | 11 +++++------ tests/qemu-iotests/228 | 12 ++++++------ tests/qemu-iotests/257 | 3 +-- tests/qemu-iotests/258 | 4 ++-- tests/qemu-iotests/310 | 13 ++++++------- tests/qemu-iotests/tests/block-status-cache | 3 +-- tests/qemu-iotests/tests/graph-changes-while-io | 7 +++---- tests/qemu-iotests/tests/image-fleecing | 10 +++++----- tests/qemu-iotests/tests/mirror-ready-cancel-error | 6 ++---- tests/qemu-iotests/tests/mirror-top-perms | 3 +-- tests/qemu-iotests/tests/remove-bitmap-from-backing | 8 ++++---- tests/qemu-iotests/tests/stream-error-on-reset | 4 ++-- 15 files changed, 45 insertions(+), 56 deletions(-) diff --git a/tests/qemu-iotests/163 b/tests/qemu-iotests/163 index b8bfc95358..e4cd4b230f 100755 --- a/tests/qemu-iotests/163 +++ b/tests/qemu-iotests/163 @@ -107,8 +107,7 @@ class ShrinkBaseClass(iotests.QMPTestCase): =20 if iotests.imgfmt =3D=3D 'raw': return - self.assertEqual(qemu_img('check', test_img), 0, - "Verifying image corruption") + qemu_img('check', test_img) =20 def test_empty_image(self): qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, @@ -130,8 +129,7 @@ class ShrinkBaseClass(iotests.QMPTestCase): qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, self.shrink_size) =20 - self.assertEqual(qemu_img("compare", test_img, check_img), 0, - "Verifying image content") + qemu_img("compare", test_img, check_img) =20 self.image_verify() =20 @@ -146,8 +144,7 @@ class ShrinkBaseClass(iotests.QMPTestCase): qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, self.shrink_size) =20 - self.assertEqual(qemu_img("compare", test_img, check_img), 0, - "Verifying image content") + qemu_img("compare", test_img, check_img) =20 self.image_verify() =20 diff --git a/tests/qemu-iotests/216 b/tests/qemu-iotests/216 index c02f8d2880..88b385afa3 100755 --- a/tests/qemu-iotests/216 +++ b/tests/qemu-iotests/216 @@ -51,10 +51,10 @@ with iotests.FilePath('base.img') as base_img_path, \ log('--- Setting up images ---') log('') =20 - assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') =3D=3D 0 - assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, - '-F', iotests.imgfmt, top_img_path) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + '-F', iotests.imgfmt, top_img_path) assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') =3D=3D 0 =20 log('Done') diff --git a/tests/qemu-iotests/218 b/tests/qemu-iotests/218 index 4922b4d3b6..853ed52b34 100755 --- a/tests/qemu-iotests/218 +++ b/tests/qemu-iotests/218 @@ -145,7 +145,7 @@ log('') with iotests.VM() as vm, \ iotests.FilePath('src.img') as src_img_path: =20 - assert qemu_img('create', '-f', iotests.imgfmt, src_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, src_img_path, '64M') assert qemu_io_silent('-f', iotests.imgfmt, src_img_path, '-c', 'write -P 42 0M 64M') =3D=3D 0 =20 diff --git a/tests/qemu-iotests/224 b/tests/qemu-iotests/224 index 38dd153625..c31c55b49d 100755 --- a/tests/qemu-iotests/224 +++ b/tests/qemu-iotests/224 @@ -47,12 +47,11 @@ for filter_node_name in False, True: iotests.FilePath('top.img') as top_img_path, \ iotests.VM() as vm: =20 - assert qemu_img('create', '-f', iotests.imgfmt, - base_img_path, '64M') =3D=3D 0 - assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_pat= h, - '-F', iotests.imgfmt, mid_img_path) =3D=3D 0 - assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, - '-F', iotests.imgfmt, top_img_path) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') + qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + '-F', iotests.imgfmt, mid_img_path) + qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, + '-F', iotests.imgfmt, top_img_path) =20 # Something to commit assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') =3D= =3D 0 diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 index a5eda2e149..f79bae0267 100755 --- a/tests/qemu-iotests/228 +++ b/tests/qemu-iotests/228 @@ -54,11 +54,11 @@ with iotests.FilePath('base.img') as base_img_path, \ iotests.FilePath('top.img') as top_img_path, \ iotests.VM() as vm: =20 - assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') # Choose a funny way to describe the backing filename - assert qemu_img('create', '-f', iotests.imgfmt, '-b', - 'file:' + base_img_path, '-F', iotests.imgfmt, - top_img_path) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, '-b', + 'file:' + base_img_path, '-F', iotests.imgfmt, + top_img_path) =20 vm.launch() =20 @@ -172,8 +172,8 @@ with iotests.FilePath('base.img') as base_img_path, \ # (because qemu cannot "canonicalize"/"resolve" the backing # filename unless the backing file is opened implicitly with the # overlay) - assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, - '-F', iotests.imgfmt, top_img_path) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + '-F', iotests.imgfmt, top_img_path) =20 # You can only reliably override backing options by using a node # reference (or by specifying file.filename, but, well...) diff --git a/tests/qemu-iotests/257 b/tests/qemu-iotests/257 index c72c82a171..fb5359c581 100755 --- a/tests/qemu-iotests/257 +++ b/tests/qemu-iotests/257 @@ -240,8 +240,7 @@ def compare_images(image, reference, baseimg=3DNone, ex= pected_match=3DTrue): """ expected_ret =3D 0 if expected_match else 1 if baseimg: - assert qemu_img("rebase", "-u", "-b", baseimg, '-F', iotests.imgfm= t, - image) =3D=3D 0 + qemu_img("rebase", "-u", "-b", baseimg, '-F', iotests.imgfmt, imag= e) ret =3D qemu_img("compare", image, reference) log('qemu_img compare "{:s}" "{:s}" =3D=3D> {:s}, {:s}'.format( image, reference, diff --git a/tests/qemu-iotests/258 b/tests/qemu-iotests/258 index a6618208a8..7798a04d7d 100755 --- a/tests/qemu-iotests/258 +++ b/tests/qemu-iotests/258 @@ -75,13 +75,13 @@ def test_concurrent_finish(write_to_stream_node): =20 # It is important to use raw for the base layer (so that # permissions are just handed through to the protocol layer) - assert qemu_img('create', '-f', 'raw', node0_path, '64M') =3D=3D 0 + qemu_img('create', '-f', 'raw', node0_path, '64M') =20 stream_throttle=3DNone commit_throttle=3DNone =20 for path in [node1_path, node2_path, node3_path, node4_path]: - assert qemu_img('create', '-f', iotests.imgfmt, path, '64M') = =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, path, '64M') =20 if write_to_stream_node: # This is what (most of the time) makes commit finish diff --git a/tests/qemu-iotests/310 b/tests/qemu-iotests/310 index 33c3411869..e3bfedc7fd 100755 --- a/tests/qemu-iotests/310 +++ b/tests/qemu-iotests/310 @@ -43,15 +43,15 @@ with iotests.FilePath('base.img') as base_img_path, \ log('--- Setting up images ---') log('') =20 - assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') =3D=3D 0 assert qemu_io_silent(base_img_path, '-c', 'write -P 1 3M 1M') =3D=3D 0 - assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, - '-F', iotests.imgfmt, mid_img_path) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + '-F', iotests.imgfmt, mid_img_path) assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 2M 1M') =3D=3D 0 assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 4M 1M') =3D=3D 0 - assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, - '-F', iotests.imgfmt, top_img_path) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, + '-F', iotests.imgfmt, top_img_path) assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') =3D=3D 0 =20 # 0 1 2 3 4 @@ -105,8 +105,7 @@ with iotests.FilePath('base.img') as base_img_path, \ log('') =20 # Detach backing to check that we can read the data from the top level= now - assert qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, - top_img_path) =3D=3D 0 + qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, top_img_path) =20 assert qemu_io_silent(top_img_path, '-c', 'read -P 0 0 1M') =3D=3D 0 assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') =3D=3D 0 diff --git a/tests/qemu-iotests/tests/block-status-cache b/tests/qemu-iotes= ts/tests/block-status-cache index 6fa10bb8f8..40e648e251 100755 --- a/tests/qemu-iotests/tests/block-status-cache +++ b/tests/qemu-iotests/tests/block-status-cache @@ -35,8 +35,7 @@ nbd_sock =3D os.path.join(iotests.sock_dir, 'nbd.sock') class TestBscWithNbd(iotests.QMPTestCase): def setUp(self) -> None: """Just create an empty image with a read-only NBD server on it""" - assert qemu_img_create('-f', iotests.imgfmt, test_img, - str(image_size)) =3D=3D 0 + qemu_img_create('-f', iotests.imgfmt, test_img, str(image_size)) =20 # Pass --allocation-depth to enable the qemu:allocation-depth cont= ext, # which we are going to query to provoke a block-status inquiry wi= th diff --git a/tests/qemu-iotests/tests/graph-changes-while-io b/tests/qemu-i= otests/tests/graph-changes-while-io index 567e8cf21e..7664f33689 100755 --- a/tests/qemu-iotests/tests/graph-changes-while-io +++ b/tests/qemu-iotests/tests/graph-changes-while-io @@ -34,16 +34,15 @@ def do_qemu_img_bench() -> None: """ Do some I/O requests on `nbd_sock`. """ - assert qemu_img('bench', '-f', 'raw', '-c', '2000000', - f'nbd+unix:///node0?socket=3D{nbd_sock}') =3D=3D 0 + qemu_img('bench', '-f', 'raw', '-c', '2000000', + f'nbd+unix:///node0?socket=3D{nbd_sock}') =20 =20 class TestGraphChangesWhileIO(QMPTestCase): def setUp(self) -> None: # Create an overlay that can be added at runtime on top of the # null-co block node that will receive I/O - assert qemu_img_create('-f', imgfmt, '-F', 'raw', '-b', 'null-co:/= /', - top) =3D=3D 0 + qemu_img_create('-f', imgfmt, '-F', 'raw', '-b', 'null-co://', top) =20 # QSD instance with a null-co block node in an I/O thread, # exported over NBD (on `nbd_sock`, export name "node0") diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/t= ests/image-fleecing index c56278639c..b7e5076104 100755 --- a/tests/qemu-iotests/tests/image-fleecing +++ b/tests/qemu-iotests/tests/image-fleecing @@ -63,18 +63,18 @@ def do_test(vm, use_cbw, use_snapshot_access_filter, ba= se_img_path, log('--- Setting up images ---') log('') =20 - assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') if bitmap: - assert qemu_img('bitmap', '--add', base_img_path, 'bitmap0') =3D= =3D 0 + qemu_img('bitmap', '--add', base_img_path, 'bitmap0') =20 if use_snapshot_access_filter: assert use_cbw - assert qemu_img('create', '-f', 'raw', fleece_img_path, '64M') =3D= =3D 0 + qemu_img('create', '-f', 'raw', fleece_img_path, '64M') else: - assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') =20 if push_backup: - assert qemu_img('create', '-f', 'qcow2', target_img_path, '64M') = =3D=3D 0 + qemu_img('create', '-f', 'qcow2', target_img_path, '64M') =20 for p in patterns: qemu_io('-f', iotests.imgfmt, diff --git a/tests/qemu-iotests/tests/mirror-ready-cancel-error b/tests/qem= u-iotests/tests/mirror-ready-cancel-error index 770ffca379..1d0e333b5e 100755 --- a/tests/qemu-iotests/tests/mirror-ready-cancel-error +++ b/tests/qemu-iotests/tests/mirror-ready-cancel-error @@ -31,10 +31,8 @@ target =3D os.path.join(iotests.test_dir, 'target.img') =20 class TestMirrorReadyCancelError(iotests.QMPTestCase): def setUp(self) -> None: - assert iotests.qemu_img_create('-f', iotests.imgfmt, source, - str(image_size)) =3D=3D 0 - assert iotests.qemu_img_create('-f', iotests.imgfmt, target, - str(image_size)) =3D=3D 0 + iotests.qemu_img_create('-f', iotests.imgfmt, source, str(image_si= ze)) + iotests.qemu_img_create('-f', iotests.imgfmt, target, str(image_si= ze)) =20 # Ensure that mirror will copy something before READY so the # target format layer will forward the pre-READY flush to its diff --git a/tests/qemu-iotests/tests/mirror-top-perms b/tests/qemu-iotests= /tests/mirror-top-perms index b5849978c4..6ac8d5efcc 100755 --- a/tests/qemu-iotests/tests/mirror-top-perms +++ b/tests/qemu-iotests/tests/mirror-top-perms @@ -34,8 +34,7 @@ source =3D os.path.join(iotests.test_dir, 'source.img') =20 class TestMirrorTopPerms(iotests.QMPTestCase): def setUp(self): - assert qemu_img('create', '-f', iotests.imgfmt, source, - str(image_size)) =3D=3D 0 + qemu_img('create', '-f', iotests.imgfmt, source, str(image_size)) self.vm =3D iotests.VM() self.vm.add_drive(source) self.vm.add_blockdev(f'null-co,node-name=3Dnull,size=3D{image_size= }') diff --git a/tests/qemu-iotests/tests/remove-bitmap-from-backing b/tests/qe= mu-iotests/tests/remove-bitmap-from-backing index 3c397b08ea..fee3141340 100755 --- a/tests/qemu-iotests/tests/remove-bitmap-from-backing +++ b/tests/qemu-iotests/tests/remove-bitmap-from-backing @@ -27,11 +27,11 @@ iotests.script_initialize(supported_fmts=3D['qcow2'], top, base =3D iotests.file_path('top', 'base') size =3D '1M' =20 -assert qemu_img_create('-f', iotests.imgfmt, base, size) =3D=3D 0 -assert qemu_img_create('-f', iotests.imgfmt, '-b', base, - '-F', iotests.imgfmt, top, size) =3D=3D 0 +qemu_img_create('-f', iotests.imgfmt, base, size) +qemu_img_create('-f', iotests.imgfmt, '-b', base, + '-F', iotests.imgfmt, top, size) =20 -assert qemu_img('bitmap', '--add', base, 'bitmap0') =3D=3D 0 +qemu_img('bitmap', '--add', base, 'bitmap0') # Just assert that our method of checking bitmaps in the image works. assert 'bitmaps' in qemu_img_pipe('info', base) =20 diff --git a/tests/qemu-iotests/tests/stream-error-on-reset b/tests/qemu-io= tests/tests/stream-error-on-reset index 7eaedb24d7..389ae822b8 100755 --- a/tests/qemu-iotests/tests/stream-error-on-reset +++ b/tests/qemu-iotests/tests/stream-error-on-reset @@ -54,9 +54,9 @@ class TestStreamErrorOnReset(QMPTestCase): to it will result in an error - top image is attached to a virtio-scsi device """ - assert qemu_img_create('-f', imgfmt, base, str(image_size)) =3D=3D= 0 + qemu_img_create('-f', imgfmt, base, str(image_size)) assert qemu_io_silent('-c', f'write 0 {data_size}', base) =3D=3D 0 - assert qemu_img_create('-f', imgfmt, top, str(image_size)) =3D=3D 0 + qemu_img_create('-f', imgfmt, top, str(image_size)) =20 self.vm =3D iotests.VM() self.vm.add_args('-accel', 'tcg') # Make throttling work properly --=20 2.34.1 From nobody Sun May 19 00:17:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646705374931337.63660885677155; Mon, 7 Mar 2022 18:09:34 -0800 (PST) Received: from localhost ([::1]:50664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRPI5-0000bG-L4 for importer@patchew.org; Mon, 07 Mar 2022 21:09:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6u-0006R1-DB for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:58:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47291) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6s-0000LV-7h for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:58:00 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-134-edG1mJdTM0Gsr2vynnVYHg-1; Mon, 07 Mar 2022 20:57:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A955A801AFC; Tue, 8 Mar 2022 01:57:53 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.10.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5A4A17A82; Tue, 8 Mar 2022 01:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646704677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hxTgdsSDRN4czLy5LWlWCKJHXjjsXY1RCnzm06kvBHM=; b=C/kDYRdMxhlBiUf/ukin5rlNauArXvKBcMtzkMeK3KP7rM3f+pBPRmDRL8hdgMdbzeViNO TLDtzvYWdUfS/VhGkl9lVf8XvqQ34of6gJO6qpAX1Bnz4eCYcuUpSw4VUKI4eHuFN//mR+ usjJMjlgMP3yjMpEIJOLhtM/I2dK1IU= X-MC-Unique: edG1mJdTM0Gsr2vynnVYHg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 4/5] iotests: make qemu_img raise on non-zero rc by default Date: Mon, 7 Mar 2022 20:57:27 -0500 Message-Id: <20220308015728.1269649-5-jsnow@redhat.com> In-Reply-To: <20220308015728.1269649-1-jsnow@redhat.com> References: <20220308015728.1269649-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Thomas Huth , Beraldo Leal , qemu-block@nongnu.org, John Snow , Hanna Reitz , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646705376781100001 Content-Type: text/plain; charset="utf-8" re-write qemu_img() as a function that will by default raise a VerboseProcessException (extended from CalledProcessException) on non-zero return codes. This will produce a stack trace that will show the command line arguments and return code from the failed process run. Users that want something more flexible (there appears to be only one) can use check=3DFalse and manage the return themselves. However, when the return code is negative, the Exception will be raised no matter what. This is done under the belief that there's no legitimate reason, even in negative tests, to see a crash from qemu-img. Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- tests/qemu-iotests/257 | 8 +++-- tests/qemu-iotests/iotests.py | 56 ++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/tests/qemu-iotests/257 b/tests/qemu-iotests/257 index fb5359c581..e7e7a2317e 100755 --- a/tests/qemu-iotests/257 +++ b/tests/qemu-iotests/257 @@ -241,11 +241,13 @@ def compare_images(image, reference, baseimg=3DNone, = expected_match=3DTrue): expected_ret =3D 0 if expected_match else 1 if baseimg: qemu_img("rebase", "-u", "-b", baseimg, '-F', iotests.imgfmt, imag= e) - ret =3D qemu_img("compare", image, reference) + + sub =3D qemu_img("compare", image, reference, check=3DFalse) + log('qemu_img compare "{:s}" "{:s}" =3D=3D> {:s}, {:s}'.format( image, reference, - "Identical" if ret =3D=3D 0 else "Mismatch", - "OK!" if ret =3D=3D expected_ret else "ERROR!"), + "Identical" if sub.returncode =3D=3D 0 else "Mismatch", + "OK!" if sub.returncode =3D=3D expected_ret else "ERROR!"), filters=3D[iotests.filter_testfiles]) =20 def test_bitmap_sync(bsync_mode, msync_mode=3D'bitmap', failure=3DNone): diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 508adade9e..ec4568b24a 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -37,9 +37,10 @@ =20 from contextlib import contextmanager =20 +from qemu.aqmp.legacy import QEMUMonitorProtocol from qemu.machine import qtest from qemu.qmp import QMPMessage -from qemu.aqmp.legacy import QEMUMonitorProtocol +from qemu.utils import VerboseProcessError =20 # Use this logger for logging messages directly from the iotests module logger =3D logging.getLogger('qemu.iotests') @@ -215,9 +216,49 @@ def qemu_img_pipe_and_status(*args: str) -> Tuple[str,= int]: return qemu_tool_pipe_and_status('qemu-img', full_args, drop_successful_output=3Dis_create) =20 -def qemu_img(*args: str) -> int: - '''Run qemu-img and return the exit code''' - return qemu_img_pipe_and_status(*args)[1] +def qemu_img(*args: str, check: bool =3D True, combine_stdio: bool =3D True + ) -> subprocess.CompletedProcess[str]: + """ + Run qemu_img and return the status code and console output. + + This function always prepends QEMU_IMG_OPTIONS and may further alter + the args for 'create' commands. + + :param args: command-line arguments to qemu-img. + :param check: Enforce a return code of zero. + :param combine_stdio: set to False to keep stdout/stderr separated. + + :raise VerboseProcessError: + When the return code is negative, or on any non-zero exit code + when 'check=3DTrue' was provided (the default). This exception has + 'stdout', 'stderr', and 'returncode' properties that may be + inspected to show greater detail. If this exception is not + handled, the command-line, return code, and all console output + will be included at the bottom of the stack trace. + + :return: a CompletedProcess. This object has args, returncode, and + stdout properties. If streams are not combined, it will also + have a stderr property. + """ + full_args =3D qemu_img_args + qemu_img_create_prepare_args(list(args)) + + subp =3D subprocess.run( + full_args, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT if combine_stdio else subprocess.PIPE, + universal_newlines=3DTrue, + check=3DFalse + ) + + if check and subp.returncode or (subp.returncode < 0): + raise VerboseProcessError( + subp.returncode, full_args, + output=3Dsubp.stdout, + stderr=3Dsubp.stderr, + ) + + return subp + =20 def ordered_qmp(qmsg, conv_keys=3DTrue): # Dictionaries are not ordered prior to 3.6, therefore: @@ -232,7 +273,7 @@ def ordered_qmp(qmsg, conv_keys=3DTrue): return od return qmsg =20 -def qemu_img_create(*args): +def qemu_img_create(*args: str) -> subprocess.CompletedProcess[str]: return qemu_img('create', *args) =20 def qemu_img_measure(*args): @@ -467,8 +508,9 @@ def qemu_nbd_popen(*args): =20 def compare_images(img1, img2, fmt1=3Dimgfmt, fmt2=3Dimgfmt): '''Return True if two image files are identical''' - return qemu_img('compare', '-f', fmt1, - '-F', fmt2, img1, img2) =3D=3D 0 + res =3D qemu_img('compare', '-f', fmt1, + '-F', fmt2, img1, img2, check=3DFalse) + return res.returncode =3D=3D 0 =20 def create_image(name, size): '''Create a fully-allocated raw image with sector markers''' --=20 2.34.1 From nobody Sun May 19 00:17:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646705015101774.6028039515783; Mon, 7 Mar 2022 18:03:35 -0800 (PST) Received: from localhost ([::1]:33964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRPCI-000684-1q for importer@patchew.org; Mon, 07 Mar 2022 21:03:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6u-0006Sm-Q3 for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:58:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRP6t-0000Lg-Ca for qemu-devel@nongnu.org; Mon, 07 Mar 2022 20:58:00 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237-Aldbful5Op6toES9d0g8Iw-1; Mon, 07 Mar 2022 20:57:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDC3D8DCC46; Tue, 8 Mar 2022 01:57:54 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.10.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id D44AE17A82; Tue, 8 Mar 2022 01:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646704678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fx4oenMZmF6uFDpBrDaNapfMRvzIvzf215oOnlFJn4w=; b=HWN9dV4JNsBb7Sor6asBVajnuSaQS5A0p468pVb8rmMLXllsNt791p3mqXD38TUw2F98CE d/yBvNZzu/B7EFXOhClLJMw2o1KMV8qVsvVsx27FnsRe88s/mYqn89zrUjMFa/kFM1eqe7 516RIGpN1evMB2laOqipOrJ4tLQ7V7I= X-MC-Unique: Aldbful5Op6toES9d0g8Iw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 5/5] iotests: fortify compare_images() against crashes Date: Mon, 7 Mar 2022 20:57:28 -0500 Message-Id: <20220308015728.1269649-6-jsnow@redhat.com> In-Reply-To: <20220308015728.1269649-1-jsnow@redhat.com> References: <20220308015728.1269649-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Thomas Huth , Beraldo Leal , qemu-block@nongnu.org, John Snow , Hanna Reitz , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646705016497100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- 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() =20 -def compare_images(img1, img2, fmt1=3Dimgfmt, fmt2=3Dimgfmt): - '''Return True if two image files are identical''' - res =3D qemu_img('compare', '-f', fmt1, - '-F', fmt2, img1, img2, check=3DFalse) - return res.returncode =3D=3D 0 +def compare_images(img1: str, img2: str, + fmt1: str =3D imgfmt, fmt2: str =3D 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 =3D=3D 1: + return False + raise =20 def create_image(name, size): '''Create a fully-allocated raw image with sector markers''' --=20 2.34.1