]>
Commit | Line | Data |
---|---|---|
a7abb537 CC |
1 | # Migration test |
2 | # | |
3 | # Copyright (c) 2019 Red Hat, Inc. | |
4 | # | |
5 | # Authors: | |
6 | # Cleber Rosa <crosa@redhat.com> | |
7 | # Caio Carrara <ccarrara@redhat.com> | |
8 | # | |
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. | |
11 | ||
12 | ||
b2cf8d47 | 13 | import tempfile |
43dc139c FR |
14 | import os |
15 | ||
2283b627 | 16 | from avocado_qemu import QemuSystemTest |
2e768cb6 | 17 | from avocado import skipUnless |
a7abb537 | 18 | |
da55be56 | 19 | from avocado.utils.network import ports |
a7abb537 | 20 | from avocado.utils import wait |
2e768cb6 | 21 | from avocado.utils.path import find_command |
a7abb537 CC |
22 | |
23 | ||
43dc139c | 24 | class MigrationTest(QemuSystemTest): |
a0918649 PMD |
25 | """ |
26 | :avocado: tags=migration | |
27 | """ | |
a7abb537 CC |
28 | |
29 | timeout = 10 | |
30 | ||
31 | @staticmethod | |
32 | def migration_finished(vm): | |
684750ab | 33 | return vm.cmd('query-migrate')['status'] in ('completed', 'failed') |
a7abb537 | 34 | |
d7c9a833 OV |
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,)) | |
2c9120a2 DDAG |
40 | wait.wait_for(self.migration_finished, |
41 | timeout=self.timeout, | |
42 | step=0.1, | |
43 | args=(dst_vm,)) | |
684750ab VSO |
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') | |
d7c9a833 | 48 | |
63adf16d | 49 | def do_migrate(self, dest_uri, src_uri=None): |
63adf16d | 50 | dest_vm = self.get_vm('-incoming', dest_uri) |
5427ecd4 | 51 | dest_vm.add_args('-nodefaults') |
63adf16d OV |
52 | dest_vm.launch() |
53 | if src_uri is None: | |
54 | src_uri = dest_uri | |
5427ecd4 PMD |
55 | source_vm = self.get_vm() |
56 | source_vm.add_args('-nodefaults') | |
63adf16d OV |
57 | source_vm.launch() |
58 | source_vm.qmp('migrate', uri=src_uri) | |
59 | self.assert_migration(source_vm, dest_vm) | |
60 | ||
a7abb537 | 61 | def _get_free_port(self): |
da55be56 | 62 | port = ports.find_free_port() |
a7abb537 CC |
63 | if port is None: |
64 | self.cancel('Failed to find a free port') | |
65 | return port | |
66 | ||
43dc139c | 67 | def migration_with_tcp_localhost(self): |
a7abb537 | 68 | dest_uri = 'tcp:localhost:%u' % self._get_free_port() |
63adf16d | 69 | self.do_migrate(dest_uri) |
b2cf8d47 | 70 | |
43dc139c | 71 | def migration_with_unix(self): |
b2cf8d47 OV |
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) | |
2e768cb6 OV |
75 | |
76 | @skipUnless(find_command('nc', default=False), "'nc' command not found") | |
43dc139c | 77 | def migration_with_exec(self): |
002b24c0 | 78 | """The test works for both netcat-traditional and netcat-openbsd packages.""" |
2e768cb6 OV |
79 | free_port = self._get_free_port() |
80 | dest_uri = 'exec:nc -l localhost %u' % free_port | |
002b24c0 OV |
81 | src_uri = 'exec:nc localhost %u' % free_port |
82 | self.do_migrate(dest_uri, src_uri) | |
43dc139c FR |
83 | |
84 | ||
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 | """ | |
92 | ||
93 | def test_migration_with_tcp_localhost(self): | |
94 | self.migration_with_tcp_localhost() | |
95 | ||
96 | def test_migration_with_unix(self): | |
97 | self.migration_with_unix() | |
98 | ||
99 | def test_migration_with_exec(self): | |
100 | self.migration_with_exec() | |
101 | ||
102 | ||
103 | @skipUnless('x86_64' in os.uname()[4], "host != target") | |
104 | class X86_64(MigrationTest): | |
105 | """ | |
106 | :avocado: tags=arch:x86_64 | |
107 | :avocado: tags=machine:pc | |
108 | :avocado: tags=cpu:qemu64 | |
109 | """ | |
110 | ||
111 | def test_migration_with_tcp_localhost(self): | |
112 | self.migration_with_tcp_localhost() | |
113 | ||
114 | def test_migration_with_unix(self): | |
115 | self.migration_with_unix() | |
116 | ||
117 | def test_migration_with_exec(self): | |
118 | self.migration_with_exec() | |
119 | ||
120 | ||
121 | @skipUnless('ppc64le' in os.uname()[4], "host != target") | |
122 | class PPC64(MigrationTest): | |
123 | """ | |
124 | :avocado: tags=arch:ppc64 | |
125 | :avocado: tags=machine:pseries | |
126 | :avocado: tags=cpu:power9_v2.0 | |
127 | """ | |
128 | ||
129 | def test_migration_with_tcp_localhost(self): | |
130 | self.migration_with_tcp_localhost() | |
131 | ||
132 | def test_migration_with_unix(self): | |
133 | self.migration_with_unix() | |
134 | ||
135 | def test_migration_with_exec(self): | |
136 | self.migration_with_exec() |