All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic migration test
@ 2019-02-12 19:38 Caio Carrara
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests Caio Carrara
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Caio Carrara @ 2019-02-12 19:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Caio Carrara

This is the third attempt to add the multi vm capability to base class
of acceptance tests.

The difference from first version is that in this current version a
simple migration test was added (done by Cleber) so the new code that is
being added is properly used and we're not adding "new dead code".

The difference from the second version is that in this current version
the migration test being added was updated based on last reviews. It was
added more status to consider the migration as finished and also
assertions was added to check the migration success.

There are more tests and test cases that can be added, but I'm assuming
this patch is complete enough and other series can be sent after
covering the other cases.

Caio Carrara (2):
  tests.acceptance: adds multi vm capability for acceptance tests
  tests.acceptance: adds simple migration test

 docs/devel/testing.rst                    | 41 +++++++++++++++++-
 tests/acceptance/avocado_qemu/__init__.py | 25 +++++++++--
 tests/acceptance/migration.py             | 53 +++++++++++++++++++++++
 3 files changed, 114 insertions(+), 5 deletions(-)
 create mode 100644 tests/acceptance/migration.py

-- 
2.20.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests
  2019-02-12 19:38 [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic migration test Caio Carrara
@ 2019-02-12 19:38 ` Caio Carrara
  2019-02-18 17:55   ` Cleber Rosa
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 2/2] tests.acceptance: adds simple migration test Caio Carrara
  2019-02-21 14:14 ` [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic " Wainer dos Santos Moschetta
  2 siblings, 1 reply; 6+ messages in thread
From: Caio Carrara @ 2019-02-12 19:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Caio Carrara

This change adds the possibility to write acceptance tests with multi
virtual machine support. It's done keeping the virtual machines objects
stored in a test attribute (dictionary). This dictionary shouldn't be
accessed directly but through the new method added `get_vm`. This new
method accept a list of args (that will be added as virtual machine
arguments) and an optional name argument. The name is the key that
identify a single virtual machine along the test machines available. If
a name without a machine is informed a new machine will be instantiated.

The current usage of vm in tests will not be broken by this change since
it keeps a property called vm in the base test class. This property only
calls the new method `get_vm` with default parameters (no args and
'default' as machine name).

Signed-off-by: Caio Carrara <ccarrara@redhat.com>
---
 docs/devel/testing.rst                    | 41 ++++++++++++++++++++++-
 tests/acceptance/avocado_qemu/__init__.py | 25 +++++++++++---
 2 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 135743a2bf..9f86569b30 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -634,7 +634,46 @@ instance, available at ``self.vm``.  Because many tests will tweak the
 QEMU command line, launching the QEMUMachine (by using ``self.vm.launch()``)
 is left to the test writer.
 
-At test "tear down", ``avocado_qemu.Test`` handles the QEMUMachine
+The base test class has also support for tests with more than one
+QEMUMachine. The way to get machines is through the ``self.get_vm()``
+method which will return a QEMUMachine instance. The ``self.get_vm()``
+method accepts arguments that will be passed to the QEMUMachine creation
+and also an optional `name` attribute so you can identify a specific
+machine and get it more than once through the tests methods. A simple
+and hypothetical example follows:
+
+.. code::
+
+  from avocado_qemu import Test
+
+
+  class MultipleMachines(Test):
+      """
+      :avocado: enable
+      """
+      def test_multiple_machines(self):
+          first_machine = self.get_vm()
+          second_machine = self.get_vm()
+          self.get_vm(name='third_machine').launch()
+
+          first_machine.launch()
+          second_machine.launch()
+
+          first_res = first_machine.command(
+              'human-monitor-command',
+              command_line='info version')
+
+          second_res = second_machine.command(
+              'human-monitor-command',
+              command_line='info version')
+
+          third_res = self.get_vm(name='third_machine').command(
+              'human-monitor-command',
+              command_line='info version')
+
+          self.assertEquals(first_res, second_res, third_res)
+
+At test "tear down", ``avocado_qemu.Test`` handles all the QEMUMachines
 shutdown.
 
 QEMUMachine
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 1e54fd5932..4c9e27feda 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -10,6 +10,7 @@
 
 import os
 import sys
+import uuid
 
 import avocado
 
@@ -42,13 +43,29 @@ def pick_default_qemu_bin():
 
 class Test(avocado.Test):
     def setUp(self):
-        self.vm = None
+        self._vms = {}
         self.qemu_bin = self.params.get('qemu_bin',
                                         default=pick_default_qemu_bin())
         if self.qemu_bin is None:
             self.cancel("No QEMU binary defined or found in the source tree")
-        self.vm = QEMUMachine(self.qemu_bin)
+
+    def _new_vm(self, *args):
+        vm = QEMUMachine(self.qemu_bin)
+        if args:
+            vm.add_args(*args)
+        return vm
+
+    @property
+    def vm(self):
+        return self.get_vm(name='default')
+
+    def get_vm(self, *args, name=None):
+        if not name:
+            name = str(uuid.uuid4())
+        if self._vms.get(name) is None:
+            self._vms[name] = self._new_vm(*args)
+        return self._vms[name]
 
     def tearDown(self):
-        if self.vm is not None:
-            self.vm.shutdown()
+        for vm in self._vms.values():
+            vm.shutdown()
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v3 2/2] tests.acceptance: adds simple migration test
  2019-02-12 19:38 [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic migration test Caio Carrara
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests Caio Carrara
@ 2019-02-12 19:38 ` Caio Carrara
  2019-02-18 17:56   ` Cleber Rosa
  2019-02-21 14:14 ` [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic " Wainer dos Santos Moschetta
  2 siblings, 1 reply; 6+ messages in thread
From: Caio Carrara @ 2019-02-12 19:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Caio Carrara, Cleber Rosa

This change adds the simplest possible migration test. Beyond the test
purpose itself it's also useful to exercise the multi virtual machines
capabilities from base avocado qemu test class.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
Signed-off-by: Caio Carrara <ccarrara@redhat.com>
---
 tests/acceptance/migration.py | 53 +++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 tests/acceptance/migration.py

diff --git a/tests/acceptance/migration.py b/tests/acceptance/migration.py
new file mode 100644
index 0000000000..6115cf6c24
--- /dev/null
+++ b/tests/acceptance/migration.py
@@ -0,0 +1,53 @@
+# Migration test
+#
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# Authors:
+#  Cleber Rosa <crosa@redhat.com>
+#  Caio Carrara <ccarrara@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+
+
+from avocado_qemu import Test
+
+from avocado.utils import network
+from avocado.utils import wait
+
+
+class Migration(Test):
+    """
+    :avocado: enable
+    """
+
+    timeout = 10
+
+    @staticmethod
+    def migration_finished(vm):
+        return vm.command('query-migrate')['status'] in ('completed', 'failed')
+
+    def _get_free_port(self):
+        port = network.find_free_port()
+        if port is None:
+            self.cancel('Failed to find a free port')
+        return port
+
+
+    def test_migration_with_tcp_localhost(self):
+        source_vm = self.get_vm()
+        dest_uri = 'tcp:localhost:%u' % self._get_free_port()
+        dest_vm = self.get_vm('-incoming', dest_uri)
+        dest_vm.launch()
+        source_vm.launch()
+        source_vm.qmp('migrate', uri=dest_uri)
+        wait.wait_for(
+            self.migration_finished,
+            timeout=self.timeout,
+            step=0.1,
+            args=(source_vm,)
+        )
+        self.assertEqual(dest_vm.command('query-migrate')['status'], 'completed')
+        self.assertEqual(source_vm.command('query-migrate')['status'], 'completed')
+        self.assertEqual(dest_vm.command('query-status')['status'], 'running')
+        self.assertEqual(source_vm.command('query-status')['status'], 'postmigrate')
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests Caio Carrara
@ 2019-02-18 17:55   ` Cleber Rosa
  0 siblings, 0 replies; 6+ messages in thread
From: Cleber Rosa @ 2019-02-18 17:55 UTC (permalink / raw)
  To: Caio Carrara, qemu-devel



On 2/12/19 2:38 PM, Caio Carrara wrote:
> This change adds the possibility to write acceptance tests with multi
> virtual machine support. It's done keeping the virtual machines objects
> stored in a test attribute (dictionary). This dictionary shouldn't be
> accessed directly but through the new method added `get_vm`. This new
> method accept a list of args (that will be added as virtual machine
> arguments) and an optional name argument. The name is the key that
> identify a single virtual machine along the test machines available. If
> a name without a machine is informed a new machine will be instantiated.
> 
> The current usage of vm in tests will not be broken by this change since
> it keeps a property called vm in the base test class. This property only
> calls the new method `get_vm` with default parameters (no args and
> 'default' as machine name).
> 
> Signed-off-by: Caio Carrara <ccarrara@redhat.com>


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/2] tests.acceptance: adds simple migration test
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 2/2] tests.acceptance: adds simple migration test Caio Carrara
@ 2019-02-18 17:56   ` Cleber Rosa
  0 siblings, 0 replies; 6+ messages in thread
From: Cleber Rosa @ 2019-02-18 17:56 UTC (permalink / raw)
  To: Caio Carrara, qemu-devel



On 2/12/19 2:38 PM, Caio Carrara wrote:
> This change adds the simplest possible migration test. Beyond the test
> purpose itself it's also useful to exercise the multi virtual machines
> capabilities from base avocado qemu test class.
> 
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> Signed-off-by: Caio Carrara <ccarrara@redhat.com>

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic migration test
  2019-02-12 19:38 [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic migration test Caio Carrara
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests Caio Carrara
  2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 2/2] tests.acceptance: adds simple migration test Caio Carrara
@ 2019-02-21 14:14 ` Wainer dos Santos Moschetta
  2 siblings, 0 replies; 6+ messages in thread
From: Wainer dos Santos Moschetta @ 2019-02-21 14:14 UTC (permalink / raw)
  To: Caio Carrara, qemu-devel


On 02/12/2019 05:38 PM, Caio Carrara wrote:
> This is the third attempt to add the multi vm capability to base class
> of acceptance tests.
>
> The difference from first version is that in this current version a
> simple migration test was added (done by Cleber) so the new code that is
> being added is properly used and we're not adding "new dead code".
>
> The difference from the second version is that in this current version
> the migration test being added was updated based on last reviews. It was
> added more status to consider the migration as finished and also
> assertions was added to check the migration success.

The new implementation of the migration test is very good IMHO.

>
> There are more tests and test cases that can be added, but I'm assuming
> this patch is complete enough and other series can be sent after
> covering the other cases.
>
> Caio Carrara (2):
>    tests.acceptance: adds multi vm capability for acceptance tests
>    tests.acceptance: adds simple migration test
>
>   docs/devel/testing.rst                    | 41 +++++++++++++++++-
>   tests/acceptance/avocado_qemu/__init__.py | 25 +++++++++--
>   tests/acceptance/migration.py             | 53 +++++++++++++++++++++++
>   3 files changed, 114 insertions(+), 5 deletions(-)
>   create mode 100644 tests/acceptance/migration.py
>

Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-02-21 14:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-12 19:38 [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic migration test Caio Carrara
2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 1/2] tests.acceptance: adds multi vm capability for acceptance tests Caio Carrara
2019-02-18 17:55   ` Cleber Rosa
2019-02-12 19:38 ` [Qemu-devel] [PATCH v3 2/2] tests.acceptance: adds simple migration test Caio Carrara
2019-02-18 17:56   ` Cleber Rosa
2019-02-21 14:14 ` [Qemu-devel] [PATCH v3 0/2] tests.acceptance: adds multi vm capability and basic " Wainer dos Santos Moschetta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.