[PATCH 20/22] tests/functional: generalize uncompress

Daniel P. Berrangé posted 22 patches 3 weeks, 5 days ago
There is a newer version of this series
[PATCH 20/22] tests/functional: generalize uncompress
Posted by Daniel P. Berrangé 3 weeks, 5 days ago
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 --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)
-- 
2.46.0