summaryrefslogtreecommitdiffstats
path: root/tests/qemu-iotests/iotests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qemu-iotests/iotests.py')
-rw-r--r--tests/qemu-iotests/iotests.py69
1 files changed, 34 insertions, 35 deletions
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 33a44671aa..da7d6637e1 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):
@@ -343,34 +353,23 @@ def qemu_io_wrap_args(args: Sequence[str]) -> List[str]:
def qemu_io_popen(*args):
return qemu_tool_popen(qemu_io_wrap_args(args))
-def qemu_io(*args):
- '''Run qemu-io and return the stdout data'''
- return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args))[0]
+def qemu_io(*args: str, check: bool = True, combine_stdio: bool = True
+ ) -> 'subprocess.CompletedProcess[str]':
+ """
+ Run QEMU_IO_PROG and return the status code and console output.
-def qemu_io_pipe_and_status(*args):
- return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args))
+ This function always prepends either QEMU_IO_OPTIONS or
+ QEMU_IO_OPTIONS_NO_FMT.
+ """
+ return qemu_tool(*qemu_io_wrap_args(args),
+ check=check, combine_stdio=combine_stdio)
-def qemu_io_log(*args):
- result = qemu_io(*args)
- log(result, filters=[filter_testfiles, filter_qemu_io])
+def qemu_io_log(*args: str, check: bool = True
+ ) -> 'subprocess.CompletedProcess[str]':
+ result = qemu_io(*args, check=check)
+ log(result.stdout, filters=[filter_testfiles, filter_qemu_io])
return result
-def qemu_io_silent(*args):
- '''Run qemu-io and return the exit code, suppressing stdout'''
- args = qemu_io_wrap_args(args)
- result = subprocess.run(args, stdout=subprocess.DEVNULL, check=False)
- if result.returncode < 0:
- sys.stderr.write('qemu-io received signal %i: %s\n' %
- (-result.returncode, ' '.join(args)))
- return result.returncode
-
-def qemu_io_silent_check(*args):
- '''Run qemu-io and return the true if subprocess returned 0'''
- args = qemu_io_wrap_args(args)
- result = subprocess.run(args, stdout=subprocess.DEVNULL,
- stderr=subprocess.STDOUT, check=False)
- return result.returncode == 0
-
class QemuIoInteractive:
def __init__(self, *args):
self.args = qemu_io_wrap_args(args)