diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2024-12-17 15:59:30 +0000 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2024-12-17 19:39:53 +0100 |
commit | 9132fff802431438a2805389e74402321fb9afed (patch) | |
tree | 034a9573892b4fbcc960e0c1c1cf206385f97b03 /tests/functional/qemu_test | |
parent | 3d5938607e05c4f8ac6df046a92fad19b681c23b (diff) | |
download | qemu-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')
-rw-r--r-- | tests/functional/qemu_test/__init__.py | 2 | ||||
-rw-r--r-- | tests/functional/qemu_test/cmd.py | 54 | ||||
-rw-r--r-- | tests/functional/qemu_test/tuxruntest.py | 10 |
3 files changed, 9 insertions, 57 deletions
diff --git a/tests/functional/qemu_test/__init__.py b/tests/functional/qemu_test/__init__.py index 7dee3522..fe6cbe3 100644 --- a/tests/functional/qemu_test/__init__.py +++ b/tests/functional/qemu_test/__init__.py @@ -8,7 +8,7 @@ from .asset import Asset from .config import BUILD_DIR -from .cmd import has_cmd, has_cmds, run_cmd, is_readable_executable_file, \ +from .cmd import run_cmd, is_readable_executable_file, \ interrupt_interactive_console_until_pattern, wait_for_console_pattern, \ exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which from .testcase import QemuBaseTest, QemuUserTest, QemuSystemTest 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'") diff --git a/tests/functional/qemu_test/tuxruntest.py b/tests/functional/qemu_test/tuxruntest.py index d375f27..2e5c6d1 100644 --- a/tests/functional/qemu_test/tuxruntest.py +++ b/tests/functional/qemu_test/tuxruntest.py @@ -15,7 +15,7 @@ import stat from qemu_test import QemuSystemTest from qemu_test import exec_command_and_wait_for_pattern from qemu_test import wait_for_console_pattern -from qemu_test import has_cmd, run_cmd, get_qemu_img +from qemu_test import which, run_cmd, get_qemu_img class TuxRunBaselineTest(QemuSystemTest): @@ -38,10 +38,8 @@ class TuxRunBaselineTest(QemuSystemTest): super().setUp() # We need zstd for all the tuxrun tests - (has_zstd, msg) = has_cmd('zstd') - if has_zstd is False: - self.skipTest(msg) - self.zstd = 'zstd' + if which('zstd') is None: + self.skipTest("zstd not found in $PATH") # Pre-init TuxRun specific settings: Most machines work with # reasonable defaults but we sometimes need to tweak the @@ -78,7 +76,7 @@ class TuxRunBaselineTest(QemuSystemTest): disk_image = self.workdir + "/rootfs.ext4" - run_cmd([self.zstd, "-f", "-d", disk_image_zst, + run_cmd(['zstd', "-f", "-d", disk_image_zst, "-o", disk_image]) # zstd copies source archive permissions for the output # file, so must make this writable for QEMU |