[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest
From: |
Daniel P . Berrangé |
Subject: |
[PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest |
Date: |
Fri, 29 Nov 2024 17:31:16 +0000 |
This helper wrappers utils.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.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/tests/functional/qemu_test/testcase.py
b/tests/functional/qemu_test/testcase.py
index 2f32742387..31d06f0172 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -28,6 +28,8 @@
from .asset import Asset
from .cmd import run_cmd
from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract,
+ guess_archive_format)
class QemuBaseTest(unittest.TestCase):
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):
log = None
logdir = None
+ '''
+ @params archive: filename, Asset, or file-like object to extract
+ @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 @member is non-None, returns the fully qualified
+ path to @member
+ '''
+ def archive_extract(self, archive, format=None, sub_dir=None, member=None):
+ if type(archive) == Asset:
+ if format is None:
+ format = guess_archive_format(archive.url)
+ archive = archive.fetch()
+ elif format is None:
+ format = guess_archive_format(archive)
+
+ if member is not None:
+ if os.path.isabs(member):
+ member = os.path.relpath(member, '/')
+
+ if sub_dir is None:
+ utils_archive_extract(archive, self.scratch_file(), format, member)
+ else:
+ utils_archive_extract(archive, self.scratch_file(sub_dir),
+ format, member)
+
+ if member is not None:
+ return self.scratch_file(member)
+ return None
+
def socket_dir(self):
if self.socketdir is None:
self.socketdir = tempfile.TemporaryDirectory(
--
2.46.0
- [PATCH 08/22] tests/functional: add helpers for building file paths, (continued)
- [PATCH 08/22] tests/functional: add helpers for building file paths, Daniel P . Berrangé, 2024/11/29
- [PATCH 10/22] tests/functional: switch over to using self.build_file(...), Daniel P . Berrangé, 2024/11/29
- [PATCH 09/22] tests/functional: switch over to using self.log_file(...), Daniel P . Berrangé, 2024/11/29
- [PATCH 11/22] tests/functional: switch over to using self.data_file(...), Daniel P . Berrangé, 2024/11/29
- [PATCH 13/22] tests/functional: switch over to using self.socket_dir(...), Daniel P . Berrangé, 2024/11/29
- [PATCH 12/22] tests/functional: switch over to using self.scratch_file(), Daniel P . Berrangé, 2024/11/29
- [PATCH 15/22] tests/functional: add common zip_extract helper, Daniel P . Berrangé, 2024/11/29
- [PATCH 16/22] tests/functional: add common deb_extract helper, Daniel P . Berrangé, 2024/11/29
- [PATCH 14/22] tests/functional: remove redundant 'rmtree' call, Daniel P . Berrangé, 2024/11/29
- [PATCH 20/22] tests/functional: generalize uncompress, Daniel P . Berrangé, 2024/11/29
- [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest,
Daniel P . Berrangé <=
- [PATCH 22/22] tests/functional: convert tests to new uncompress helper, Daniel P . Berrangé, 2024/11/29
- [PATCH 21/22] tests/functional: add 'uncompress' to QemuBaseTest, Daniel P . Berrangé, 2024/11/29
- [PATCH 19/22] tests/functional: convert tests to new archive_extract helper, Daniel P . Berrangé, 2024/11/29
- [PATCH 17/22] tests/functional: generalize archive_extract, Daniel P . Berrangé, 2024/11/29