diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2024-12-17 15:59:43 +0000 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2024-12-17 19:39:53 +0100 |
commit | 239fd29d6f82724c95a7a7f840c9f9244bcbe6d4 (patch) | |
tree | 9b6f52fa24c1265199ccfe1c13ed5cd54972e9eb | |
parent | c283afbf658cdc2156250a84be433fc0bdd002ac (diff) | |
download | qemu-239fd29d6f82724c95a7a7f840c9f9244bcbe6d4.zip qemu-239fd29d6f82724c95a7a7f840c9f9244bcbe6d4.tar.gz qemu-239fd29d6f82724c95a7a7f840c9f9244bcbe6d4.tar.bz2 |
tests/functional: add 'archive_extract' to QemuBaseTest
This helper wrappers archive.archive_extract, forcing the use of the
scratch directory, to ensure any extracted files are cleaned at test
termination. If a specific member is requested, then the path to the
extracted file is also returned.
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20241217155953.3950506-23-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
-rw-r--r-- | tests/functional/qemu_test/testcase.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py index 4939382..19fb1d0 100644 --- a/tests/functional/qemu_test/testcase.py +++ b/tests/functional/qemu_test/testcase.py @@ -25,6 +25,7 @@ import uuid from qemu.machine import QEMUMachine from qemu.utils import kvm_available, tcg_available +from .archive import archive_extract from .asset import Asset from .cmd import run_cmd from .config import BUILD_DIR @@ -40,6 +41,37 @@ class QemuBaseTest(unittest.TestCase): logdir = None ''' + @params archive: filename, Asset, or file-like object to extract + @params format: optional archive format (tar, zip, deb, cpio) + @params sub_dir: optional sub-directory to extract into + @params member: optional member file to limit extraction to + + Extracts @archive into the scratch directory, or a directory beneath + named by @sub_dir. All files are extracted unless @member specifies + a limit. + + If @format is None, heuristics will be applied to guess the format + from the filename or Asset URL. @format must be non-None if @archive + is a file-like object. + + If @member is non-None, returns the fully qualified path to @member + ''' + def archive_extract(self, archive, format=None, sub_dir=None, member=None): + self.log.debug(f"Extract {archive} format={format}" + + f"sub_dir={sub_dir} member={member}") + if type(archive) == Asset: + archive.fetch() + if sub_dir is None: + archive_extract(archive, self.scratch_file(), format, member) + else: + archive_extract(archive, self.scratch_file(sub_dir), + format, member) + + if member is not None: + return self.scratch_file(member) + return None + + ''' Create a temporary directory suitable for storing UNIX socket paths. |