tests/avocado: Add a test for a little-endian microblaze machine
[qemu/ar7.git] / tests / avocado / migration.py
blob09b62f813eb7b1614cbdfe9536194ad62a143d27
1 # Migration test
3 # Copyright (c) 2019 Red Hat, Inc.
5 # Authors:
6 # Cleber Rosa <crosa@redhat.com>
7 # Caio Carrara <ccarrara@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2 or
10 # later. See the COPYING file in the top-level directory.
13 import tempfile
14 import os
16 from avocado_qemu import QemuSystemTest
17 from avocado import skipUnless
19 from avocado.utils.network import ports
20 from avocado.utils import wait
21 from avocado.utils.path import find_command
24 class MigrationTest(QemuSystemTest):
25 """
26 :avocado: tags=migration
27 """
29 timeout = 10
31 @staticmethod
32 def migration_finished(vm):
33 return vm.cmd('query-migrate')['status'] in ('completed', 'failed')
35 def assert_migration(self, src_vm, dst_vm):
36 wait.wait_for(self.migration_finished,
37 timeout=self.timeout,
38 step=0.1,
39 args=(src_vm,))
40 wait.wait_for(self.migration_finished,
41 timeout=self.timeout,
42 step=0.1,
43 args=(dst_vm,))
44 self.assertEqual(src_vm.cmd('query-migrate')['status'], 'completed')
45 self.assertEqual(dst_vm.cmd('query-migrate')['status'], 'completed')
46 self.assertEqual(dst_vm.cmd('query-status')['status'], 'running')
47 self.assertEqual(src_vm.cmd('query-status')['status'],'postmigrate')
49 def do_migrate(self, dest_uri, src_uri=None):
50 dest_vm = self.get_vm('-incoming', dest_uri)
51 dest_vm.add_args('-nodefaults')
52 dest_vm.launch()
53 if src_uri is None:
54 src_uri = dest_uri
55 source_vm = self.get_vm()
56 source_vm.add_args('-nodefaults')
57 source_vm.launch()
58 source_vm.qmp('migrate', uri=src_uri)
59 self.assert_migration(source_vm, dest_vm)
61 def _get_free_port(self):
62 port = ports.find_free_port()
63 if port is None:
64 self.cancel('Failed to find a free port')
65 return port
67 def migration_with_tcp_localhost(self):
68 dest_uri = 'tcp:localhost:%u' % self._get_free_port()
69 self.do_migrate(dest_uri)
71 def migration_with_unix(self):
72 with tempfile.TemporaryDirectory(prefix='socket_') as socket_path:
73 dest_uri = 'unix:%s/qemu-test.sock' % socket_path
74 self.do_migrate(dest_uri)
76 @skipUnless(find_command('nc', default=False), "'nc' command not found")
77 def migration_with_exec(self):
78 """The test works for both netcat-traditional and netcat-openbsd packages."""
79 free_port = self._get_free_port()
80 dest_uri = 'exec:nc -l localhost %u' % free_port
81 src_uri = 'exec:nc localhost %u' % free_port
82 self.do_migrate(dest_uri, src_uri)
85 @skipUnless('aarch64' in os.uname()[4], "host != target")
86 class Aarch64(MigrationTest):
87 """
88 :avocado: tags=arch:aarch64
89 :avocado: tags=machine:virt
90 :avocado: tags=cpu:max
91 """
93 def test_migration_with_tcp_localhost(self):
94 self.migration_with_tcp_localhost()
96 def test_migration_with_unix(self):
97 self.migration_with_unix()
99 def test_migration_with_exec(self):
100 self.migration_with_exec()
103 @skipUnless('x86_64' in os.uname()[4], "host != target")
104 class X86_64(MigrationTest):
106 :avocado: tags=arch:x86_64
107 :avocado: tags=machine:pc
108 :avocado: tags=cpu:qemu64
111 def test_migration_with_tcp_localhost(self):
112 self.migration_with_tcp_localhost()
114 def test_migration_with_unix(self):
115 self.migration_with_unix()
117 def test_migration_with_exec(self):
118 self.migration_with_exec()
121 @skipUnless('ppc64le' in os.uname()[4], "host != target")
122 class PPC64(MigrationTest):
124 :avocado: tags=arch:ppc64
125 :avocado: tags=machine:pseries
126 :avocado: tags=cpu:power9_v2.0
129 def test_migration_with_tcp_localhost(self):
130 self.migration_with_tcp_localhost()
132 def test_migration_with_unix(self):
133 self.migration_with_unix()
135 def test_migration_with_exec(self):
136 self.migration_with_exec()