On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> This mirrors the existing archive_extract, cpio_extract and zip_extract
> helpers
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> tests/functional/qemu_test/linuxkernel.py | 15 +++++----------
> tests/functional/qemu_test/utils.py | 13 +++++++++++++
> 2 files changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/tests/functional/qemu_test/linuxkernel.py b/tests/functional/qemu_test/linuxkernel.py
> index a6525f9dd6..fb6a158d36 100644
> --- a/tests/functional/qemu_test/linuxkernel.py
> +++ b/tests/functional/qemu_test/linuxkernel.py
> @@ -6,8 +6,8 @@
> 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 .utils import deb_extract
>
> class LinuxKernelTest(QemuSystemTest):
> KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
> @@ -37,16 +37,11 @@ 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)
> + relpath = os.path.relpath(path, '/')
> + 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 'relative_to()' to turn it into a relative
> # path for joining to the scratch dir
> - return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))
> + return os.path.normpath(self.scratch_file(relpath))
>
> diff --git a/tests/functional/qemu_test/utils.py b/tests/functional/qemu_test/utils.py
> index 41bd1df666..bafe7fb80e 100644
> --- a/tests/functional/qemu_test/utils.py
> +++ b/tests/functional/qemu_test/utils.py
> @@ -15,6 +15,8 @@
> import subprocess
> import tarfile
>
> +from .cmd import run_cmd
> +
> """
> Round up to next power of 2
> """
> @@ -53,6 +55,17 @@ def zip_extract(archive, dest_dir, member=None):
> 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])
> + archive_extract(file_path, dest_dir, member)
> + finally:
> + os.chdir(cwd)
Not sure whether we really need this ... extracting .deb files is very
specific to running Linux kernels in the guest, so IMHO it should be
sufficient to have it in linuxkernel.py.
Anyway, if we add more and more *_extract functions, we should maybe
consider to move the extraction functions out of utils.py into an archive.py
file, what do you think?
Thomas