[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 22/32] tests/functional: add 'archive_extract' to QemuBaseTest
From: |
Daniel P . Berrangé |
Subject: |
[PATCH v3 22/32] tests/functional: add 'archive_extract' to QemuBaseTest |
Date: |
Tue, 17 Dec 2024 15:59:43 +0000 |
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>
---
tests/functional/qemu_test/testcase.py | 32 ++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tests/functional/qemu_test/testcase.py
b/tests/functional/qemu_test/testcase.py
index 493938240c..19fb1d0c07 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -25,6 +25,7 @@
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
@@ -39,6 +40,37 @@ class QemuBaseTest(unittest.TestCase):
log = None
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.
--
2.46.0
- [PATCH v3 10/32] tests/functional: add helpers for building file paths, (continued)
- [PATCH v3 10/32] tests/functional: add helpers for building file paths, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 09/32] tests/functional: drop 'has_cmd' and 'has_cmds' helpers, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 11/32] tests/functional: switch over to using self.log_file(...), Daniel P . Berrangé, 2024/12/17
- [PATCH v3 12/32] tests/functional: switch over to using self.build_file(...), Daniel P . Berrangé, 2024/12/17
- [PATCH v3 13/32] tests/functional: switch over to using self.data_file(...), Daniel P . Berrangé, 2024/12/17
- [PATCH v3 14/32] tests/functional: switch over to using self.scratch_file(), Daniel P . Berrangé, 2024/12/17
- [PATCH v3 17/32] tests/functional: move uncompress handling into new uncompress.py file, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 18/32] tests/functional: add common zip_extract helper, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 16/32] tests/functional: move archive handling into new archive.py file, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 20/32] tests/functional: let cpio_extract accept filenames, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 22/32] tests/functional: add 'archive_extract' to QemuBaseTest,
Daniel P . Berrangé <=
- [PATCH v3 23/32] tests/functional: convert tests to new archive_extract helper, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 15/32] tests/functional: remove redundant 'rmtree' call, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 19/32] tests/functional: add common deb_extract helper, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 24/32] tests/functional: add a generalized uncompress helper, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 21/32] tests/functional: add a generalized archive_extract, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 25/32] tests/functional: add 'uncompress' to QemuBaseTest, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 26/32] tests/functional: convert tests to new uncompress helper, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 27/32] tests/functional: drop back compat imports from utils.py, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 28/32] tests/functional: replace 'run_cmd' with subprocess helpers, Daniel P . Berrangé, 2024/12/17
- [PATCH v3 29/32] tests/functional: remove now unused 'run_cmd' helper, Daniel P . Berrangé, 2024/12/17