qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hanna Reitz <hreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Hanna Reitz <hreitz@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org
Subject: [PULL 07/14] iotests: create generic qemu_tool() function
Date: Mon, 25 Apr 2022 16:08:14 +0200	[thread overview]
Message-ID: <20220425140821.957511-8-hreitz@redhat.com> (raw)
In-Reply-To: <20220425140821.957511-1-hreitz@redhat.com>

From: John Snow <jsnow@redhat.com>

reimplement qemu_img() in terms of qemu_tool() in preparation for doing
the same with qemu_io().

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220418211504.943969-7-jsnow@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
 tests/qemu-iotests/iotests.py | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 33a44671aa..6800c67bea 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -206,15 +206,13 @@ def qemu_img_create_prepare_args(args: List[str]) -> List[str]:
 
     return result
 
-def qemu_img(*args: str, check: bool = True, combine_stdio: bool = 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.
+def qemu_tool(*args: str, check: bool = True, combine_stdio: bool = True
+              ) -> 'subprocess.CompletedProcess[str]':
+    """
+    Run a qemu tool and return its status code and console output.
 
-    :param args: command-line arguments to qemu-img.
+    :param args: full command line to run.
     :param check: Enforce a return code of zero.
     :param combine_stdio: set to False to keep stdout/stderr separated.
 
@@ -231,10 +229,8 @@ def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True
         properties. If streams are not combined, it will also have a
         stderr property.
     """
-    full_args = qemu_img_args + qemu_img_create_prepare_args(list(args))
-
     subp = subprocess.run(
-        full_args,
+        args,
         stdout=subprocess.PIPE,
         stderr=subprocess.STDOUT if combine_stdio else subprocess.PIPE,
         universal_newlines=True,
@@ -243,7 +239,7 @@ def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True
 
     if check and subp.returncode or (subp.returncode < 0):
         raise VerboseProcessError(
-            subp.returncode, full_args,
+            subp.returncode, args,
             output=subp.stdout,
             stderr=subp.stderr,
         )
@@ -251,6 +247,20 @@ def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True
     return subp
 
 
+def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True
+             ) -> 'subprocess.CompletedProcess[str]':
+    """
+    Run QEMU_IMG_PROG and return its status code and console output.
+
+    This function always prepends QEMU_IMG_OPTIONS and may further alter
+    the args for 'create' commands.
+
+    See `qemu_tool()` for greater detail.
+    """
+    full_args = qemu_img_args + qemu_img_create_prepare_args(list(args))
+    return qemu_tool(*full_args, check=check, combine_stdio=combine_stdio)
+
+
 def ordered_qmp(qmsg, conv_keys=True):
     # Dictionaries are not ordered prior to 3.6, therefore:
     if isinstance(qmsg, list):
-- 
2.35.1



  parent reply	other threads:[~2022-04-25 14:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25 14:08 [PULL 00/14] Block patches Hanna Reitz
2022-04-25 14:08 ` [PULL 01/14] block: add 'force' parameter to 'blockdev-change-medium' command Hanna Reitz
2022-04-25 14:08 ` [PULL 02/14] iotests: replace calls to log(qemu_io(...)) with qemu_io_log() Hanna Reitz
2022-04-25 14:08 ` [PULL 03/14] iotests/163: Fix broken qemu-io invocation Hanna Reitz
2022-04-25 14:08 ` [PULL 04/14] iotests: Don't check qemu_io() output for specific error strings Hanna Reitz
2022-04-25 14:08 ` [PULL 05/14] iotests/040: Don't check image pattern on zero-length image Hanna Reitz
2022-04-25 14:08 ` [PULL 06/14] iotests/040: Fix TestCommitWithFilters test Hanna Reitz
2022-04-25 14:08 ` Hanna Reitz [this message]
2022-04-25 14:08 ` [PULL 08/14] iotests: rebase qemu_io() on top of qemu_tool() Hanna Reitz
2022-04-25 14:08 ` [PULL 09/14] iotests/migration-permissions: use assertRaises() for qemu_io() negative test Hanna Reitz
2022-04-25 14:08 ` [PULL 10/14] iotests/image-fleecing: switch to qemu_io() Hanna Reitz
2022-04-25 14:08 ` [PULL 11/14] iotests: remove qemu_io_pipe_and_status() Hanna Reitz
2022-04-25 14:08 ` [PULL 12/14] iotests: remove qemu_io_silent() and qemu_io_silent_check() Hanna Reitz
2022-04-25 14:08 ` [PULL 13/14] iotests: make qemu_io_log() check return codes by default Hanna Reitz
2022-04-25 14:08 ` [PULL 14/14] iotests/108: Fix when missing user_allow_other Hanna Reitz
2022-04-25 23:32 ` [PULL 00/14] Block patches Richard Henderson

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=20220425140821.957511-8-hreitz@redhat.com \
    --to=hreitz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).