[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/3] iotests.py: Add helper for running commands
From: |
Nir Soffer |
Subject: |
[Qemu-devel] [PATCH 2/3] iotests.py: Add helper for running commands |
Date: |
Fri, 13 Apr 2018 22:26:04 +0300 |
Add few helpers for running external commands:
- CommandFailed: exception, keeping all the info related to a failed
command, and providing a useful error message. (Unfortunately
subprocess.CalledProcessError does not).
- run(): run a command collecting output from the underlying process
stdout and stderr, returning the command output or raising
CommandFailed.
These helpers will be used by new qemu-nbd tests. And later can be used
to cleanup helpers for running qemu-* tools in iotests.py.
Signed-off-by: Nir Soffer <address@hidden>
---
tests/qemu-iotests/iotests.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index b25d48a91b..0f8abf99cb 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -64,6 +64,24 @@ luks_default_secret_object = 'secret,id=keysec0,data=' + \
os.environ['IMGKEYSECRET']
luks_default_key_secret_opt = 'key-secret=keysec0'
+class CommandFailed(Exception):
+
+ def __init__(self, cmd, rc, out, err):
+ self.cmd = cmd
+ self.rc = rc
+ self.out = out
+ self.err = err
+
+ def __str__(self):
+ return ("Command {self.cmd} failed: rc={self.rc}, out={self.out!r}, "
+ "err={self.err!r}").format(self=self)
+
+def run(*args):
+ p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ if p.returncode != 0:
+ raise CommandFailed(args, p.returncode, out, err)
+ return out
def qemu_img(*args):
'''Run qemu-img and return the exit code'''
--
2.14.3
[Qemu-devel] [PATCH 2/3] iotests.py: Add helper for running commands,
Nir Soffer <=
[Qemu-devel] [PATCH 3/3] qemu-iotests: Test new qemu-nbd --nolist option, Nir Soffer, 2018/04/13