diff mbox series

[v2,4/6] tests/boot_linux_console: add extract_from_rpm method

Message ID 1580914565-19675-5-git-send-email-liam.merwick@oracle.com (mailing list archive)
State New, archived
Headers show
Series tests/boot_linux_console: add extra boot acceptance tests | expand

Commit Message

Liam Merwick Feb. 5, 2020, 2:56 p.m. UTC
Add a method to extract a specified file from an RPM to the test's
working directory and return the path to the extracted file.

Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 tests/acceptance/boot_linux_console.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Philippe Mathieu-Daudé Feb. 6, 2020, 2:27 p.m. UTC | #1
On 2/5/20 3:56 PM, Liam Merwick wrote:
> Add a method to extract a specified file from an RPM to the test's
> working directory and return the path to the extracted file.
> 
> Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   tests/acceptance/boot_linux_console.py | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index e9375590bc1c..6a473363a122 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -51,6 +51,22 @@ class BootLinuxConsole(Test):
>           os.chdir(cwd)
>           return self.workdir + path
>   
> +    def extract_from_rpm(self, rpm, path):
> +        """
> +        Extracts a file from an RPM package into the test workdir.
> +
> +        :param rpm: path to the rpm archive
> +        :param path: path within the rpm archive of the file to be extracted
> +                     needs to be a relative path (starting with './') because
> +                     cpio(1), which is used to extract the file, expects that.
> +        :returns: path of the extracted file
> +        """
> +        cwd = os.getcwd()
> +        os.chdir(self.workdir)
> +        process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True)
> +        os.chdir(cwd)
> +        return os.path.normpath(os.path.join(self.workdir, path))
> +
>       def do_test_x86_64_machine(self):
>           """
>           Common routine to boot an x86_64 guest.
> 

Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index e9375590bc1c..6a473363a122 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -51,6 +51,22 @@  class BootLinuxConsole(Test):
         os.chdir(cwd)
         return self.workdir + path
 
+    def extract_from_rpm(self, rpm, path):
+        """
+        Extracts a file from an RPM package into the test workdir.
+
+        :param rpm: path to the rpm archive
+        :param path: path within the rpm archive of the file to be extracted
+                     needs to be a relative path (starting with './') because
+                     cpio(1), which is used to extract the file, expects that.
+        :returns: path of the extracted file
+        """
+        cwd = os.getcwd()
+        os.chdir(self.workdir)
+        process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True)
+        os.chdir(cwd)
+        return os.path.normpath(os.path.join(self.workdir, path))
+
     def do_test_x86_64_machine(self):
         """
         Common routine to boot an x86_64 guest.