[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/31] iotests.py: Add qemu_img_pipe_and_status()
From: |
Max Reitz |
Subject: |
[PULL 06/31] iotests.py: Add qemu_img_pipe_and_status() |
Date: |
Mon, 6 Jul 2020 12:04:07 +0200 |
This function will be used by the next patch, which intends to check
both the exit code and qemu-img's output.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200625125548.870061-5-mreitz@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
[mreitz: Rebased on 49438972b8c2e]
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
tests/qemu-iotests/iotests.py | 40 +++++++++++++++++------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index ef739dd1e3..423974d3f6 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -29,7 +29,7 @@ import struct
import subprocess
import sys
from typing import (Any, Callable, Dict, Iterable,
- List, Optional, Sequence, TypeVar)
+ List, Optional, Sequence, Tuple, TypeVar)
import unittest
# pylint: disable=import-error, wrong-import-position
@@ -90,15 +90,24 @@ luks_default_secret_object = 'secret,id=keysec0,data=' + \
luks_default_key_secret_opt = 'key-secret=keysec0'
-def qemu_img(*args):
- '''Run qemu-img and return the exit code'''
- devnull = open('/dev/null', 'r+')
- exitcode = subprocess.call(qemu_img_args + list(args),
- stdin=devnull, stdout=devnull)
- if exitcode < 0:
+def qemu_img_pipe_and_status(*args: str) -> Tuple[str, int]:
+ """
+ Run qemu-img and return both its output and its exit code
+ """
+ subp = subprocess.Popen(qemu_img_args + list(args),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ universal_newlines=True)
+ output = subp.communicate()[0]
+ if subp.returncode < 0:
sys.stderr.write('qemu-img received signal %i: %s\n'
- % (-exitcode, ' '.join(qemu_img_args + list(args))))
- return exitcode
+ % (-subp.returncode,
+ ' '.join(qemu_img_args + list(args))))
+ return (output, subp.returncode)
+
+def qemu_img(*args: str) -> int:
+ '''Run qemu-img and return the exit code'''
+ return qemu_img_pipe_and_status(*args)[1]
def ordered_qmp(qmsg, conv_keys=True):
# Dictionaries are not ordered prior to 3.6, therefore:
@@ -140,18 +149,9 @@ def qemu_img_verbose(*args):
% (-exitcode, ' '.join(qemu_img_args + list(args))))
return exitcode
-def qemu_img_pipe(*args):
+def qemu_img_pipe(*args: str) -> str:
'''Run qemu-img and return its output'''
- subp = subprocess.Popen(qemu_img_args + list(args),
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- universal_newlines=True)
- output = subp.communicate()[0]
- if subp.returncode < 0:
- sys.stderr.write('qemu-img received signal %i: %s\n'
- % (-subp.returncode,
- ' '.join(qemu_img_args + list(args))))
- return output
+ return qemu_img_pipe_and_status(*args)[0]
def qemu_img_log(*args):
result = qemu_img_pipe(*args)
--
2.26.2
- [PULL 00/31] Block patches, Max Reitz, 2020/07/06
- [PULL 01/31] block/block-copy: block_copy_dirty_clusters: fix failure check, Max Reitz, 2020/07/06
- [PULL 02/31] qcow2: Fix preallocation on images with unaligned sizes, Max Reitz, 2020/07/06
- [PULL 03/31] iotests: Make _filter_img_create more active, Max Reitz, 2020/07/06
- [PULL 04/31] iotests: filter few more luks specific create options, Max Reitz, 2020/07/06
- [PULL 05/31] iotests/common.rc: Add _require_working_luks, Max Reitz, 2020/07/06
- [PULL 07/31] iotests.py: Add (verify|has)_working_luks(), Max Reitz, 2020/07/06
- [PULL 06/31] iotests.py: Add qemu_img_pipe_and_status(),
Max Reitz <=
- [PULL 08/31] iotests: Check whether luks works, Max Reitz, 2020/07/06
- [PULL 09/31] qcrypto/core: add generic infrastructure for crypto options amendment, Max Reitz, 2020/07/06
- [PULL 10/31] qcrypto/luks: implement encryption key management, Max Reitz, 2020/07/06
- [PULL 11/31] block/amend: add 'force' option, Max Reitz, 2020/07/06
- [PULL 12/31] block/amend: separate amend and create options for qemu-img, Max Reitz, 2020/07/06
- [PULL 14/31] block/crypto: rename two functions, Max Reitz, 2020/07/06
- [PULL 13/31] block/amend: refactor qcow2 amend options, Max Reitz, 2020/07/06
- [PULL 15/31] block/crypto: implement the encryption key management, Max Reitz, 2020/07/06
- [PULL 16/31] block/qcow2: extend qemu-img amend interface with crypto options, Max Reitz, 2020/07/06
- [PULL 17/31] iotests: qemu-img tests for luks key management, Max Reitz, 2020/07/06