tests/functional: remove duplicated 'which' function impl
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 17 Dec 2024 15:59:25 +0000 (15:59 +0000)
committerThomas Huth <thuth@redhat.com>
Tue, 17 Dec 2024 18:39:53 +0000 (19:39 +0100)
Put the 'which' function into shared code.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20241217155953.3950506-5-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/functional/qemu_test/__init__.py
tests/functional/qemu_test/cmd.py
tests/functional/test_acpi_bits.py
tests/functional/test_ppc64_hv.py

index 67f87be9c4c00b5255d7c10595f6dc90ef40e0f0..8fddddbe675a3e50064f084ac66e703a75c1a15c 100644 (file)
@@ -10,6 +10,6 @@ from .asset import Asset
 from .config import BUILD_DIR
 from .cmd import has_cmd, has_cmds, 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
+    exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
 from .testcase import QemuBaseTest, QemuUserTest, QemuSystemTest
 from .linuxkernel import LinuxKernelTest
index 11c8334a7cecd58bf55e47b296b5bbb7d312ce5f..4106f1ee7cfe696cc8b5d6f0cabca5f7a40709cb 100644 (file)
@@ -18,6 +18,16 @@ import subprocess
 
 from .config import BUILD_DIR
 
+def which(tool):
+    """ looks up the full path for @tool, returns None if not found
+        or if @tool does not have executable permissions.
+    """
+    paths=os.getenv('PATH')
+    for p in paths.split(os.path.pathsep):
+        p = os.path.join(p, tool)
+        if os.path.exists(p) and os.access(p, os.X_OK):
+            return p
+    return None
 
 def has_cmd(name, args=None):
     """
index 3df956239476e0409d477ba922a4d0cf5491d976..1e6d082ecb6bb06681fb78ab7c8c45364b379f6b 100755 (executable)
@@ -47,7 +47,7 @@ from typing import (
 )
 from qemu.machine import QEMUMachine
 from unittest import skipIf
-from qemu_test import QemuSystemTest, Asset
+from qemu_test import QemuSystemTest, Asset, which
 
 deps = ["xorriso", "mformat"] # dependent tools needed in the test setup/box.
 supported_platforms = ['x86_64'] # supported test platforms.
@@ -55,17 +55,6 @@ supported_platforms = ['x86_64'] # supported test platforms.
 # default timeout of 120 secs is sometimes not enough for bits test.
 BITS_TIMEOUT = 200
 
-def which(tool):
-    """ looks up the full path for @tool, returns None if not found
-        or if @tool does not have executable permissions.
-    """
-    paths=os.getenv('PATH')
-    for p in paths.split(os.path.pathsep):
-        p = os.path.join(p, tool)
-        if os.path.exists(p) and os.access(p, os.X_OK):
-            return p
-    return None
-
 def missing_deps():
     """ returns True if any of the test dependent tools are absent.
     """
index d97b62e364fd6583f1a3631a173d6604869d6734..7c6f8234f5e9b04f00ac37d1ce8704bdae03fb84 100755 (executable)
@@ -11,7 +11,7 @@
 
 from unittest import skipIf, skipUnless
 from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern, exec_command
+from qemu_test import wait_for_console_pattern, exec_command, which
 import os
 import time
 import subprocess
@@ -19,17 +19,6 @@ from datetime import datetime
 
 deps = ["xorriso"] # dependent tools needed in the test setup/box.
 
-def which(tool):
-    """ looks up the full path for @tool, returns None if not found
-        or if @tool does not have executable permissions.
-    """
-    paths=os.getenv('PATH')
-    for p in paths.split(os.path.pathsep):
-        p = os.path.join(p, tool)
-        if os.path.exists(p) and os.access(p, os.X_OK):
-            return p
-    return None
-
 def missing_deps():
     """ returns True if any of the test dependent tools are absent.
     """