aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/qemu_test/cmd.py
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2024-12-17 15:59:30 +0000
committerThomas Huth <thuth@redhat.com>2024-12-17 19:39:53 +0100
commit9132fff802431438a2805389e74402321fb9afed (patch)
tree034a9573892b4fbcc960e0c1c1cf206385f97b03 /tests/functional/qemu_test/cmd.py
parent3d5938607e05c4f8ac6df046a92fad19b681c23b (diff)
downloadqemu-9132fff802431438a2805389e74402321fb9afed.zip
qemu-9132fff802431438a2805389e74402321fb9afed.tar.gz
qemu-9132fff802431438a2805389e74402321fb9afed.tar.bz2
tests/functional: drop 'has_cmd' and 'has_cmds' helpers
The 'which' helper is simpler, not depending on the external 'which' binary, and is sufficient for test needs. Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20241217155953.3950506-10-berrange@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/functional/qemu_test/cmd.py')
-rw-r--r--tests/functional/qemu_test/cmd.py54
1 files changed, 4 insertions, 50 deletions
diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test/cmd.py
index 600e050..bebcd46 100644
--- a/tests/functional/qemu_test/cmd.py
+++ b/tests/functional/qemu_test/cmd.py
@@ -29,52 +29,6 @@ def which(tool):
return p
return None
-def has_cmd(name, args=None):
- """
- This function is for use in a @skipUnless decorator, e.g.:
-
- @skipUnless(*has_cmd('sudo -n', ('sudo', '-n', 'true')))
- def test_something_that_needs_sudo(self):
- ...
- """
-
- if args is None:
- args = ('which', name)
-
- try:
- _, stderr, exitcode = run_cmd(args)
- except Exception as e:
- exitcode = -1
- stderr = str(e)
-
- if exitcode != 0:
- cmd_line = ' '.join(args)
- err = f'{name} required, but "{cmd_line}" failed: {stderr.strip()}'
- return (False, err)
- else:
- return (True, '')
-
-def has_cmds(*cmds):
- """
- This function is for use in a @skipUnless decorator and
- allows checking for the availability of multiple commands, e.g.:
-
- @skipUnless(*has_cmds(('cmd1', ('cmd1', '--some-parameter')),
- 'cmd2', 'cmd3'))
- def test_something_that_needs_cmd1_and_cmd2(self):
- ...
- """
-
- for cmd in cmds:
- if isinstance(cmd, str):
- cmd = (cmd,)
-
- ok, errstr = has_cmd(*cmd)
- if not ok:
- return (False, errstr)
-
- return (True, '')
-
def run_cmd(args):
subp = subprocess.Popen(args,
stdout=subprocess.PIPE,
@@ -254,7 +208,7 @@ def get_qemu_img(test):
qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
if os.path.exists(qemu_img):
return qemu_img
- (has_system_qemu_img, errmsg) = has_cmd('qemu-img')
- if has_system_qemu_img:
- return 'qemu-img'
- test.skipTest(errmsg)
+ qemu_img = which('qemu-img')
+ if qemu_img is not None:
+ return qemu_img
+ test.skipTest(f"qemu-img not found in {BUILD_DIR} or '$PATH'")