diff mbox series

[v2,1/7] tests/acceptance: Automatic set -cpu to the test vm

Message ID 20210408195237.3489296-2-wainersm@redhat.com (mailing list archive)
State New, archived
Headers show
Series tests/acceptance: Handle tests with "cpu" tag | expand

Commit Message

Wainer dos Santos Moschetta April 8, 2021, 7:52 p.m. UTC
This introduces a new feature to the functional tests: automatic setting of
the '-cpu VALUE' option to the created vm if the test is tagged with
'cpu:VALUE'. The 'cpu' property is made available to the test object as well.

For example, for a simple test as:

    def test(self):
        """
        :avocado: tags=cpu:host
        """
        self.assertEqual(self.cpu, "host")
        self.vm.launch()

The resulting QEMU evocation will be like:

    qemu-system-x86_64 -display none -vga none -chardev socket,id=mon,path=/var/tmp/avo_qemu_sock_pdgzbgd_/qemu-1135557-monitor.sock -mon chardev=mon,mode=control -cpu host

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 docs/devel/testing.rst                    | 17 +++++++++++++++++
 tests/acceptance/avocado_qemu/__init__.py |  5 +++++
 2 files changed, 22 insertions(+)

Comments

Cleber Rosa April 21, 2021, 8:16 p.m. UTC | #1
On Thu, Apr 08, 2021 at 04:52:31PM -0300, Wainer dos Santos Moschetta wrote:
> This introduces a new feature to the functional tests: automatic setting of
> the '-cpu VALUE' option to the created vm if the test is tagged with
> 'cpu:VALUE'. The 'cpu' property is made available to the test object as well.
> 
> For example, for a simple test as:
> 
>     def test(self):
>         """
>         :avocado: tags=cpu:host
>         """
>         self.assertEqual(self.cpu, "host")
>         self.vm.launch()
>

So I tried a few tests with different CPU models and it works as
expected.  One minor caveat is that using "host" has side effects
in some cases, causing tests to fail because they may also require
KVM to be enabled.

But this is a generic mechanism so I don't think it should be
concerned with that.

> The resulting QEMU evocation will be like:
> 
>     qemu-system-x86_64 -display none -vga none -chardev socket,id=mon,path=/var/tmp/avo_qemu_sock_pdgzbgd_/qemu-1135557-monitor.sock -mon chardev=mon,mode=control -cpu host

Only thing is: can we please just break this line (I could not ignore
a 174 character line :).

> 
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  docs/devel/testing.rst                    | 17 +++++++++++++++++
>  tests/acceptance/avocado_qemu/__init__.py |  5 +++++
>  2 files changed, 22 insertions(+)

With the line broken mentioned above (which I can take care of when
queueing this patch):

Reviewed-by: Cleber Rosa <crosa@redhat.com>
Tested-by: Cleber Rosa <crosa@redhat.com>
Willian Rampazzo April 23, 2021, 4:55 p.m. UTC | #2
On Thu, Apr 8, 2021 at 5:01 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This introduces a new feature to the functional tests: automatic setting of
> the '-cpu VALUE' option to the created vm if the test is tagged with
> 'cpu:VALUE'. The 'cpu' property is made available to the test object as well.
>
> For example, for a simple test as:
>
>     def test(self):
>         """
>         :avocado: tags=cpu:host
>         """
>         self.assertEqual(self.cpu, "host")
>         self.vm.launch()
>
> The resulting QEMU evocation will be like:
>
>     qemu-system-x86_64 -display none -vga none -chardev socket,id=mon,path=/var/tmp/avo_qemu_sock_pdgzbgd_/qemu-1135557-monitor.sock -mon chardev=mon,mode=control -cpu host
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  docs/devel/testing.rst                    | 17 +++++++++++++++++
>  tests/acceptance/avocado_qemu/__init__.py |  5 +++++
>  2 files changed, 22 insertions(+)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>
Wainer dos Santos Moschetta April 28, 2021, 5:36 p.m. UTC | #3
Hi,

On 4/21/21 5:16 PM, Cleber Rosa wrote:
> On Thu, Apr 08, 2021 at 04:52:31PM -0300, Wainer dos Santos Moschetta wrote:
>> This introduces a new feature to the functional tests: automatic setting of
>> the '-cpu VALUE' option to the created vm if the test is tagged with
>> 'cpu:VALUE'. The 'cpu' property is made available to the test object as well.
>>
>> For example, for a simple test as:
>>
>>      def test(self):
>>          """
>>          :avocado: tags=cpu:host
>>          """
>>          self.assertEqual(self.cpu, "host")
>>          self.vm.launch()
>>
> So I tried a few tests with different CPU models and it works as
> expected.  One minor caveat is that using "host" has side effects
> in some cases, causing tests to fail because they may also require
> KVM to be enabled.
>
> But this is a generic mechanism so I don't think it should be
> concerned with that.


Good point. Certainly I will consider this when reviewing new tests.


>
>> The resulting QEMU evocation will be like:
>>
>>      qemu-system-x86_64 -display none -vga none -chardev socket,id=mon,path=/var/tmp/avo_qemu_sock_pdgzbgd_/qemu-1135557-monitor.sock -mon chardev=mon,mode=control -cpu host
> Only thing is: can we please just break this line (I could not ignore
> a 174 character line :).
>
>> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
>> ---
>>   docs/devel/testing.rst                    | 17 +++++++++++++++++
>>   tests/acceptance/avocado_qemu/__init__.py |  5 +++++
>>   2 files changed, 22 insertions(+)
> With the line broken mentioned above (which I can take care of when
> queueing this patch):


I will send a v3 to address your review for patch 06, so I can take care 
of it.


>
> Reviewed-by: Cleber Rosa <crosa@redhat.com>
> Tested-by: Cleber Rosa <crosa@redhat.com>


Thanks for the reviews!

- Wainer
diff mbox series

Patch

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 1da4c4e4c4..e139a618f5 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -878,6 +878,17 @@  name.  If one is not given explicitly, it will either be set to
 ``None``, or, if the test is tagged with one (and only one)
 ``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``.
 
+cpu
+~~~
+
+The cpu model that will be set to all QEMUMachine instances created
+by the test.
+
+The ``cpu`` attribute will be set to the test parameter of the same
+name. If one is not given explicitly, it will either be set to
+``None ``, or, if the test is tagged with one (and only one)
+``:avocado: tags=cpu:VALUE`` tag, it will be set to ``VALUE``.
+
 machine
 ~~~~~~~
 
@@ -924,6 +935,12 @@  architecture of a kernel or disk image to boot a VM with.
 This parameter has a direct relation with the ``arch`` attribute.  If
 not given, it will default to None.
 
+cpu
+~~~
+
+The cpu model that will be set to all QEMUMachine instances created
+by the test.
+
 machine
 ~~~~~~~
 
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 83b1741ec8..7f8e703757 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -206,6 +206,9 @@  def setUp(self):
         self.arch = self.params.get('arch',
                                     default=self._get_unique_tag_val('arch'))
 
+        self.cpu = self.params.get('cpu',
+                                   default=self._get_unique_tag_val('cpu'))
+
         self.machine = self.params.get('machine',
                                        default=self._get_unique_tag_val('machine'))
 
@@ -231,6 +234,8 @@  def get_vm(self, *args, name=None):
             name = str(uuid.uuid4())
         if self._vms.get(name) is None:
             self._vms[name] = self._new_vm(*args)
+            if self.cpu is not None:
+                self._vms[name].add_args('-cpu', self.cpu)
             if self.machine is not None:
                 self._vms[name].set_machine(self.machine)
         return self._vms[name]