[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/38] tests/functional: add common deb_extract helper
From: |
Thomas Huth |
Subject: |
[PULL 19/38] tests/functional: add common deb_extract helper |
Date: |
Wed, 18 Dec 2024 12:09:39 +0100 |
From: Daniel P. Berrangé <berrange@redhat.com>
This mirrors the existing archive_extract, cpio_extract and zip_extract
helpers
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20241217155953.3950506-20-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/functional/qemu_test/archive.py | 13 +++++++++++++
tests/functional/qemu_test/linuxkernel.py | 13 ++++---------
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/tests/functional/qemu_test/archive.py
b/tests/functional/qemu_test/archive.py
index 06b66701c0..a6fc97a557 100644
--- a/tests/functional/qemu_test/archive.py
+++ b/tests/functional/qemu_test/archive.py
@@ -12,6 +12,8 @@
import tarfile
import zipfile
+from .cmd import run_cmd
+
def tar_extract(archive, dest_dir, member=None):
with tarfile.open(archive) as tf:
@@ -37,3 +39,14 @@ def zip_extract(archive, dest_dir, member=None):
zf.extract(member=member, path=dest_dir)
else:
zf.extractall(path=dest_dir)
+
+def deb_extract(archive, dest_dir, member=None):
+ cwd = os.getcwd()
+ os.chdir(dest_dir)
+ try:
+ (stdout, stderr, ret) = run_cmd(['ar', 't', archive])
+ file_path = stdout.split()[2]
+ run_cmd(['ar', 'x', archive, file_path])
+ tar_extract(file_path, dest_dir, member)
+ finally:
+ os.chdir(cwd)
diff --git a/tests/functional/qemu_test/linuxkernel.py
b/tests/functional/qemu_test/linuxkernel.py
index 2e4f4e35fd..8f2810f3af 100644
--- a/tests/functional/qemu_test/linuxkernel.py
+++ b/tests/functional/qemu_test/linuxkernel.py
@@ -6,8 +6,9 @@
import os
from .testcase import QemuSystemTest
-from .cmd import run_cmd, wait_for_console_pattern
-from .utils import archive_extract
+from .cmd import wait_for_console_pattern
+from .archive import deb_extract
+
class LinuxKernelTest(QemuSystemTest):
KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -37,13 +38,7 @@ def extract_from_deb(self, deb_path, path):
:param path: path within the deb archive of the file to be extracted
:returns: path of the extracted file
"""
- cwd = os.getcwd()
- os.chdir(self.workdir)
- (stdout, stderr, ret) = run_cmd(['ar', 't', deb_path])
- file_path = stdout.split()[2]
- run_cmd(['ar', 'x', deb_path, file_path])
- archive_extract(file_path, self.workdir)
- os.chdir(cwd)
+ deb_extract(deb_path, self.workdir, member="." + path)
# Return complete path to extracted file. Because callers to
# extract_from_deb() specify 'path' with a leading slash, it is
# necessary to use os.path.relpath() as otherwise scratch_file()
--
2.47.1
- [PULL 09/38] tests/functional: drop 'has_cmd' and 'has_cmds' helpers, (continued)
- [PULL 09/38] tests/functional: drop 'has_cmd' and 'has_cmds' helpers, Thomas Huth, 2024/12/18
- [PULL 11/38] tests/functional: switch over to using self.log_file(...), Thomas Huth, 2024/12/18
- [PULL 12/38] tests/functional: switch over to using self.build_file(...), Thomas Huth, 2024/12/18
- [PULL 13/38] tests/functional: switch over to using self.data_file(...), Thomas Huth, 2024/12/18
- [PULL 15/38] tests/functional: remove redundant 'rmtree' call, Thomas Huth, 2024/12/18
- [PULL 16/38] tests/functional: move archive handling into new archive.py file, Thomas Huth, 2024/12/18
- [PULL 17/38] tests/functional: move uncompress handling into new uncompress.py file, Thomas Huth, 2024/12/18
- [PULL 14/38] tests/functional: switch over to using self.scratch_file(), Thomas Huth, 2024/12/18
- [PULL 18/38] tests/functional: add common zip_extract helper, Thomas Huth, 2024/12/18
- [PULL 20/38] tests/functional: let cpio_extract accept filenames, Thomas Huth, 2024/12/18
- [PULL 19/38] tests/functional: add common deb_extract helper,
Thomas Huth <=
- [PULL 21/38] tests/functional: add a generalized archive_extract, Thomas Huth, 2024/12/18
- [PULL 22/38] tests/functional: add 'archive_extract' to QemuBaseTest, Thomas Huth, 2024/12/18
- [PULL 23/38] tests/functional: convert tests to new archive_extract helper, Thomas Huth, 2024/12/18
- [PULL 24/38] tests/functional: add a generalized uncompress helper, Thomas Huth, 2024/12/18
- [PULL 25/38] tests/functional: add 'uncompress' to QemuBaseTest, Thomas Huth, 2024/12/18
- [PULL 26/38] tests/functional: convert tests to new uncompress helper, Thomas Huth, 2024/12/18
- [PULL 28/38] tests/functional: replace 'run_cmd' with subprocess helpers, Thomas Huth, 2024/12/18
- [PULL 27/38] tests/functional: drop back compat imports from utils.py, Thomas Huth, 2024/12/18
- [PULL 29/38] tests/functional: remove now unused 'run_cmd' helper, Thomas Huth, 2024/12/18
- [PULL 30/38] tests/functional: skip tests if assets are not available, Thomas Huth, 2024/12/18