diff mbox series

[20/22] tests/functional: generalize uncompress

Message ID 20241129173120.761728-21-berrange@redhat.com (mailing list archive)
State New
Headers show
Series tests/functional: various improvements wrt assets/scratch files | expand

Commit Message

Daniel P. Berrangé Nov. 29, 2024, 5:31 p.m. UTC
There are many types of compression that the tests deal with, and
it makes sense to have a single helper 'uncompress' that can deal
with all.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/qemu_test/utils.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/tests/functional/qemu_test/utils.py b/tests/functional/qemu_test/utils.py
index 8c1df8f8c2..90c87b3671 100644
--- a/tests/functional/qemu_test/utils.py
+++ b/tests/functional/qemu_test/utils.py
@@ -115,6 +115,23 @@  def lzma_uncompress(xz_path, output_path):
             os.remove(output_path)
             raise
 
+def uncompress(input_path, output_path, format=None):
+    if format == "xz":
+        lzma_uncompress(input_path, output_path)
+    elif format == "gz":
+        gzip_uncompress(input_path, output_path)
+    else:
+        raise Exception(f"Unknown compression format {format}")
+
+def guess_uncompress_format(path):
+    (name, ext) = os.path.splitext(path)
+    if ext == ".xz":
+        return "xz"
+    elif ext == ".gz":
+        return "gz"
+    else:
+        raise Exception(f"Unknown compression format for {path}")
+
 def cpio_extract(cpio_handle, output_path):
     cwd = os.getcwd()
     os.chdir(output_path)