diff mbox series

[v4,1/2] avocado_qemu/__init__.py: factor out the qemu-img finding

Message ID 20230421042322.684093-2-kconsul@linux.vnet.ibm.com
State New
Headers show
Series Improve code coverage for ppc64 | expand

Commit Message

Kautuk Consul April 21, 2023, 4:23 a.m. UTC
Factor out the code that finds the qemu-img binary in the
QemuSystemTest class and create a new get_qemu_img() function
with it. This function will get called also from the new code
in tuxrun_baselines.py avocado test-case.

Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
---
 tests/avocado/avocado_qemu/__init__.py | 27 +++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

Comments

Philippe Mathieu-Daudé April 21, 2023, 6:03 a.m. UTC | #1
On 21/4/23 06:23, Kautuk Consul wrote:
> Factor out the code that finds the qemu-img binary in the
> QemuSystemTest class and create a new get_qemu_img() function
> with it. This function will get called also from the new code
> in tuxrun_baselines.py avocado test-case.
> 
> Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
> ---
>   tests/avocado/avocado_qemu/__init__.py | 27 +++++++++++++++-----------
>   1 file changed, 16 insertions(+), 11 deletions(-)

Suggested-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Kautuk Consul April 21, 2023, 6:37 a.m. UTC | #2
Adding Harsh Prateel Bora.

On 2023-04-20 23:23:21, Kautuk Consul wrote:
> Factor out the code that finds the qemu-img binary in the
> QemuSystemTest class and create a new get_qemu_img() function
> with it. This function will get called also from the new code
> in tuxrun_baselines.py avocado test-case.
> 
> Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
> ---
>  tests/avocado/avocado_qemu/__init__.py | 27 +++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
> index cb71f50db9..d8f390e27a 100644
> --- a/tests/avocado/avocado_qemu/__init__.py
> +++ b/tests/avocado/avocado_qemu/__init__.py
> @@ -330,6 +330,19 @@ def _new_vm(self, name, *args):
>              vm.add_args(*args)
>          return vm
>  
> +    def get_qemu_img(self):
> +        self.log.debug('Looking for and selecting a qemu-img binary')
> +
> +        # If qemu-img has been built, use it, otherwise the system wide one
> +        # will be used.
> +        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
> +        if not os.path.exists(qemu_img):
> +            qemu_img = find_command('qemu-img', False)
> +        if qemu_img is False:
> +            self.cancel('Could not find "qemu-img"')
> +
> +        return qemu_img
> +
>      @property
>      def vm(self):
>          return self.get_vm(name='default')
> @@ -594,17 +607,9 @@ def set_up_existing_ssh_keys(self):
>          return (ssh_public_key, ssh_private_key)
>  
>      def download_boot(self):
> -        self.log.debug('Looking for and selecting a qemu-img binary to be '
> -                       'used to create the bootable snapshot image')
> -        # If qemu-img has been built, use it, otherwise the system wide one
> -        # will be used.  If none is available, the test will cancel.
> -        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
> -        if not os.path.exists(qemu_img):
> -            qemu_img = find_command('qemu-img', False)
> -        if qemu_img is False:
> -            self.cancel('Could not find "qemu-img", which is required to '
> -                        'create the bootable image')
> -        vmimage.QEMU_IMG = qemu_img
> +        # Set the qemu-img binary.
> +        # If none is available, the test will cancel.
> +        vmimage.QEMU_IMG = super().get_qemu_img()
>  
>          self.log.info('Downloading/preparing boot image')
>          # Fedora 31 only provides ppc64le images
> -- 
> 2.25.1
> 
>
Harsh Prateek Bora April 21, 2023, 6:55 a.m. UTC | #3
Kautuk Consul wrote:
> Adding Harsh Prateek Bora.
> 
> On 2023-04-20 23:23:21, Kautuk Consul wrote:
> > Factor out the code that finds the qemu-img binary in the
> > QemuSystemTest class and create a new get_qemu_img() function
> > with it. This function will get called also from the new code
> > in tuxrun_baselines.py avocado test-case.
> > 
> > Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
> > ---
> >  tests/avocado/avocado_qemu/__init__.py | 27 +++++++++++++++-----------
> >  1 file changed, 16 insertions(+), 11 deletions(-)
> > 
> > diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
> > index cb71f50db9..d8f390e27a 100644
> > --- a/tests/avocado/avocado_qemu/__init__.py
> > +++ b/tests/avocado/avocado_qemu/__init__.py
> > @@ -330,6 +330,19 @@ def _new_vm(self, name, *args):
> >              vm.add_args(*args)
> >          return vm
> >  
> > +    def get_qemu_img(self):
> > +        self.log.debug('Looking for and selecting a qemu-img binary')
> > +
> > +        # If qemu-img has been built, use it, otherwise the system wide one
> > +        # will be used.
> > +        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
> > +        if not os.path.exists(qemu_img):
> > +            qemu_img = find_command('qemu-img', False)
> > +        if qemu_img is False:
> > +            self.cancel('Could not find "qemu-img"')
> > +
> > +        return qemu_img
> > +
> >      @property
> >      def vm(self):
> >          return self.get_vm(name='default')
> > @@ -594,17 +607,9 @@ def set_up_existing_ssh_keys(self):
> >          return (ssh_public_key, ssh_private_key)
> >  
> >      def download_boot(self):
> > -        self.log.debug('Looking for and selecting a qemu-img binary to be '
> > -                       'used to create the bootable snapshot image')
> > -        # If qemu-img has been built, use it, otherwise the system wide one
> > -        # will be used.  If none is available, the test will cancel.
> > -        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
> > -        if not os.path.exists(qemu_img):
> > -            qemu_img = find_command('qemu-img', False)
> > -        if qemu_img is False:
> > -            self.cancel('Could not find "qemu-img", which is required to '
> > -                        'create the bootable image')
> > -        vmimage.QEMU_IMG = qemu_img
> > +        # Set the qemu-img binary.
> > +        # If none is available, the test will cancel.
> > +        vmimage.QEMU_IMG = super().get_qemu_img()
> > 
Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

> >          self.log.info('Downloading/preparing boot image')
> >          # Fedora 31 only provides ppc64le images
> > -- 
> > 2.25.1
> > 
> > 
>
diff mbox series

Patch

diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
index cb71f50db9..d8f390e27a 100644
--- a/tests/avocado/avocado_qemu/__init__.py
+++ b/tests/avocado/avocado_qemu/__init__.py
@@ -330,6 +330,19 @@  def _new_vm(self, name, *args):
             vm.add_args(*args)
         return vm
 
+    def get_qemu_img(self):
+        self.log.debug('Looking for and selecting a qemu-img binary')
+
+        # If qemu-img has been built, use it, otherwise the system wide one
+        # will be used.
+        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
+        if not os.path.exists(qemu_img):
+            qemu_img = find_command('qemu-img', False)
+        if qemu_img is False:
+            self.cancel('Could not find "qemu-img"')
+
+        return qemu_img
+
     @property
     def vm(self):
         return self.get_vm(name='default')
@@ -594,17 +607,9 @@  def set_up_existing_ssh_keys(self):
         return (ssh_public_key, ssh_private_key)
 
     def download_boot(self):
-        self.log.debug('Looking for and selecting a qemu-img binary to be '
-                       'used to create the bootable snapshot image')
-        # If qemu-img has been built, use it, otherwise the system wide one
-        # will be used.  If none is available, the test will cancel.
-        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
-        if not os.path.exists(qemu_img):
-            qemu_img = find_command('qemu-img', False)
-        if qemu_img is False:
-            self.cancel('Could not find "qemu-img", which is required to '
-                        'create the bootable image')
-        vmimage.QEMU_IMG = qemu_img
+        # Set the qemu-img binary.
+        # If none is available, the test will cancel.
+        vmimage.QEMU_IMG = super().get_qemu_img()
 
         self.log.info('Downloading/preparing boot image')
         # Fedora 31 only provides ppc64le images