[Qemu-devel] [PATCH v2 2/2] Acceptance tests: add simple migration test

Caio Carrara posted 2 patches 6 years, 9 months ago
[Qemu-devel] [PATCH v2 2/2] Acceptance tests: add simple migration test
Posted by Caio Carrara 6 years, 9 months ago
From: Cleber Rosa <crosa@redhat.com>

This is the simplest possible migration test, exercising the multi
VM capabilities of the test class.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 tests/acceptance/migration.py | 45 +++++++++++++++++++++++++++++++++++
 1 file changed, 45 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..973ae0ab4b
--- /dev/null
+++ b/tests/acceptance/migration.py
@@ -0,0 +1,45 @@
+# Migration test
+#
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# Author:
+#  Cleber Rosa <crosa@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_completed(vm):
+        cmd_result = vm.qmp('query-migrate')
+        if cmd_result is not None:
+            result = cmd_result.get('return')
+            if result is not None:
+                return result.get('status') == 'completed'
+        return False
+
+    def test_tcp(self):
+        source = self.get_vm()
+        port = network.find_free_port()
+        if port is None:
+            self.cancel('Failed to find a free port')
+        dest_uri = 'tcp:localhost:%u' % port
+        dest = self.get_vm('-incoming', dest_uri)
+        dest.launch()
+        source.launch()
+        source.qmp('migrate', uri=dest_uri)
+        wait.wait_for(self.migration_completed, timeout=self.timeout,
+                      step=0.1, args=(source,))
-- 
2.20.1


Re: [Qemu-devel] [PATCH v2 2/2] Acceptance tests: add simple migration test
Posted by Wainer dos Santos Moschetta 6 years, 9 months ago
On 01/28/2019 03:47 PM, Caio Carrara wrote:
> From: Cleber Rosa <crosa@redhat.com>
>
> This is the simplest possible migration test, exercising the multi
> VM capabilities of the test class.
>
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>   tests/acceptance/migration.py | 45 +++++++++++++++++++++++++++++++++++
>   1 file changed, 45 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..973ae0ab4b
> --- /dev/null
> +++ b/tests/acceptance/migration.py
> @@ -0,0 +1,45 @@
> +# Migration test
> +#
> +# Copyright (c) 2019 Red Hat, Inc.
> +#
> +# Author:
> +#  Cleber Rosa <crosa@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_completed(vm):
> +        cmd_result = vm.qmp('query-migrate')
> +        if cmd_result is not None:
> +            result = cmd_result.get('return')
> +            if result is not None:
> +                return result.get('status') == 'completed'

You could verify other status that indicate failure on the migration to 
nicely fail the test, because the printed messaged on timeout does not 
help much to identify what went wrong.

It could be something like:

-    @staticmethod
-    def migration_completed(vm):
+    def migration_completed(self, vm):
          cmd_result = vm.qmp('query-migrate')
          if cmd_result is not None:
              result = cmd_result.get('return')
              if result is not None:
+                self.assertNotEqual(result.get('status'), 'failed')
                  return result.get('status') == 'completed'
          return False


> +        return False
> +
> +    def test_tcp(self):

What if you rename it to something like "test_with_tcp_on_localhost" to 
better represent the test scenario?

- Wainer

> +        source = self.get_vm()
> +        port = network.find_free_port()
> +        if port is None:
> +            self.cancel('Failed to find a free port')
> +        dest_uri = 'tcp:localhost:%u' % port
> +        dest = self.get_vm('-incoming', dest_uri)
> +        dest.launch()
> +        source.launch()
> +        source.qmp('migrate', uri=dest_uri)
> +        wait.wait_for(self.migration_completed, timeout=self.timeout,
> +                      step=0.1, args=(source,))