aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2024-12-17 15:59:46 +0000
committerThomas Huth <thuth@redhat.com>2024-12-17 19:39:53 +0100
commitfd4abcb00839a310fc668d86177278e789f51688 (patch)
treef6afdd2cc948d823e7198746c10941169b87f134 /tests
parentdd66e65f055a0d8651afcf63460b1130487aeebb (diff)
downloadqemu-fd4abcb00839a310fc668d86177278e789f51688.zip
qemu-fd4abcb00839a310fc668d86177278e789f51688.tar.gz
qemu-fd4abcb00839a310fc668d86177278e789f51688.tar.bz2
tests/functional: add 'uncompress' to QemuBaseTest
This helper wrappers utils.uncompress, forcing the use of the scratch directory, to ensure any uncompressed files are cleaned at test termination. Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20241217155953.3950506-26-berrange@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/qemu_test/testcase.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 19fb1d0..d0bb314 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -29,6 +29,7 @@ from .archive import archive_extract
from .asset import Asset
from .cmd import run_cmd
from .config import BUILD_DIR
+from .uncompress import uncompress
class QemuBaseTest(unittest.TestCase):
@@ -41,6 +42,30 @@ class QemuBaseTest(unittest.TestCase):
logdir = None
'''
+ @params compressed: filename, Asset, or file-like object to uncompress
+ @params format: optional compression format (gzip, lzma)
+
+ Uncompresses @compressed into the scratch directory.
+
+ If @format is None, heuristics will be applied to guess the format
+ from the filename or Asset URL. @format must be non-None if @uncompressed
+ is a file-like object.
+
+ Returns the fully qualified path to the uncompressed file
+ '''
+ def uncompress(self, compressed, format=None):
+ self.log.debug(f"Uncompress {compressed} format={format}")
+ if type(compressed) == Asset:
+ compressed.fetch()
+
+ (name, ext) = os.path.splitext(str(compressed))
+ uncompressed = self.scratch_file(os.path.basename(name))
+
+ uncompress(compressed, uncompressed, format)
+
+ return uncompressed
+
+ '''
@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