diff mbox series

[3/4] Acceptance Tests: introduce method to require a feature and option

Message ID 20210608140938.863580-4-crosa@redhat.com (mailing list archive)
State New, archived
Headers show
Series Jobs based on custom runners: add CentOS Stream 8 | expand

Commit Message

Cleber Rosa June 8, 2021, 2:09 p.m. UTC
In this context, and according to the qemu.utils.list_feature() utility
function, a feature is something is available as a QEMU command line
option that can take the "help" value.

This builds on top of that utility function, and allows test writers
to require, for instance, the "x-remote" (option) machine type
(feature).

This example is actually applied here to the reespective test, given
that the option is conditionally built, and the test will ERROR
without it.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 29 ++++++++++++++++++++++-
 tests/acceptance/multiprocess.py          |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)

Comments

Willian Rampazzo June 10, 2021, 7:46 p.m. UTC | #1
On Tue, Jun 8, 2021 at 11:09 AM Cleber Rosa <crosa@redhat.com> wrote:
>
> In this context, and according to the qemu.utils.list_feature() utility
> function, a feature is something is available as a QEMU command line
> option that can take the "help" value.
>
> This builds on top of that utility function, and allows test writers
> to require, for instance, the "x-remote" (option) machine type
> (feature).
>
> This example is actually applied here to the reespective test, given
> that the option is conditionally built, and the test will ERROR
> without it.
>
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 29 ++++++++++++++++++++++-
>  tests/acceptance/multiprocess.py          |  1 +
>  2 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 93c4b9851f..432caff4e6 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -11,6 +11,7 @@
>  import logging
>  import os
>  import shutil
> +import subprocess
>  import sys
>  import uuid
>  import tempfile
> @@ -45,7 +46,8 @@
>  from qemu.utils import (
>      get_info_usernet_hostfwd_port,
>      kvm_available,
> -    tcg_available,
> +    list_feature,
> +    tcg_available
>  )
>
>  def is_readable_executable_file(path):
> @@ -182,6 +184,31 @@ def _get_unique_tag_val(self, tag_name):
>              return vals.pop()
>          return None
>
> +    def require_feature(self, feature, option=None):
> +        """
> +        Requires a feature to be available for the test to continue
> +
> +        It takes into account the currently set qemu binary, and only checks
> +        for by running a "qemu -$feature help" command.  If the specific option
> +        is given, it checks if it's listed for the given feature.
> +
> +        If the check fails, the test is canceled.
> +
> +        :param feature: name of a QEMU feature, such as "accel" or "machine"
> +        :type feature: str
> +        :param option: the specific value for the feature.  For instance,
> +                       if feature is "machine", option can be "q35".
> +        type option: str
> +        """
> +        try:
> +            options_available = list_feature(self.qemu_bin, feature)

Looking at this code, the previous patch makes more sense the way it is now :)

Maybe, splitting it into multiple `list_` functions will make the code
here more complex.

Anyway, I'll let you decide.

Reviewed-by: Willian Rampazzo <willianr@redhat.com>
diff mbox series

Patch

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 93c4b9851f..432caff4e6 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -11,6 +11,7 @@ 
 import logging
 import os
 import shutil
+import subprocess
 import sys
 import uuid
 import tempfile
@@ -45,7 +46,8 @@ 
 from qemu.utils import (
     get_info_usernet_hostfwd_port,
     kvm_available,
-    tcg_available,
+    list_feature,
+    tcg_available
 )
 
 def is_readable_executable_file(path):
@@ -182,6 +184,31 @@  def _get_unique_tag_val(self, tag_name):
             return vals.pop()
         return None
 
+    def require_feature(self, feature, option=None):
+        """
+        Requires a feature to be available for the test to continue
+
+        It takes into account the currently set qemu binary, and only checks
+        for by running a "qemu -$feature help" command.  If the specific option
+        is given, it checks if it's listed for the given feature.
+
+        If the check fails, the test is canceled.
+
+        :param feature: name of a QEMU feature, such as "accel" or "machine"
+        :type feature: str
+        :param option: the specific value for the feature.  For instance,
+                       if feature is "machine", option can be "q35".
+        type option: str
+        """
+        try:
+            options_available = list_feature(self.qemu_bin, feature)
+        except subprocess.CalledProcessError:
+            self.cancel('Feature "%s" does not appear to be present.' % feature)
+        if option is not None:
+            if option not in options_available:
+                self.cancel('Feature "%s" does not have "%s" as an option' %
+                            (feature, option))
+
     def require_accelerator(self, accelerator):
         """
         Requires an accelerator to be available for the test to continue
diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
index 96627f022a..4d8a40a510 100644
--- a/tests/acceptance/multiprocess.py
+++ b/tests/acceptance/multiprocess.py
@@ -22,6 +22,7 @@  def do_test(self, kernel_url, initrd_url, kernel_command_line,
                 machine_type):
         """Main test method"""
         self.require_accelerator('kvm')
+        self.require_feature('machine', 'x-remote')
 
         # Create socketpair to connect proxy and remote processes
         proxy_sock, remote_sock = socket.socketpair(socket.AF_UNIX,