Browse Source

Add Live Migration Mixin

Mixin does a live migration and checks if old host is different
from destination host.

Mixin is used in test_cluster.py and test_vnuma.py.

Change-Id: Ia647b78b24feeba4e6b74ed08a21e8ac0955920d
tags/0.1.0
Alexandru Muresan 1 year ago
parent
commit
11f87904b2

+ 62
- 0
oswin_tempest_plugin/tests/_mixins/migrate.py View File

@@ -13,6 +13,7 @@
13 13
 #    License for the specific language governing permissions and limitations
14 14
 #    under the License.
15 15
 
16
+from tempest.common import waiters
16 17
 import testtools
17 18
 
18 19
 from oswin_tempest_plugin import config
@@ -43,3 +44,64 @@ class _MigrateMixin(object):
43 44
         server_tuple = self._create_server()
44 45
         self._migrate_server(server_tuple)
45 46
         self._check_server_connectivity(server_tuple)
47
+
48
+
49
+class _LiveMigrateMixin(object):
50
+    """Live migration mixin.
51
+
52
+    This mixin will add a live migration test. It will perform the
53
+    following operations:
54
+
55
+    * Spawn instance.
56
+    * Live migrate the instance.
57
+    * Check the server connectivity.
58
+    """
59
+
60
+    # TODO(amuresan): Different mixins may be used at the same time.
61
+    #                 Each of them may override some fields such as
62
+    #                 'max_microversion'. This has to be sorted out.
63
+    max_microversion = '2.24'
64
+
65
+    def _live_migrate_server(self, server_tuple, destination_host=None,
66
+                             state='ACTIVE', volume_backed=False):
67
+        server = server_tuple.server
68
+        admin_server = self._get_server_as_admin(server)
69
+        current_host = admin_server['OS-EXT-SRV-ATTR:host']
70
+
71
+        block_migration = (CONF.compute_feature_enabled.
72
+                           block_migration_for_live_migration and
73
+                           not volume_backed)
74
+
75
+        self.admin_servers_client.live_migrate_server(
76
+            server['id'],
77
+            host=destination_host,
78
+            block_migration=block_migration,
79
+            disk_over_commit=False)
80
+
81
+        waiters.wait_for_server_status(self.admin_servers_client, server['id'],
82
+                                       state)
83
+
84
+        admin_server = self._get_server_as_admin(server)
85
+        after_migration_host = admin_server['OS-EXT-SRV-ATTR:host']
86
+
87
+        migration_list = (self.admin_migrations_client.list_migrations()
88
+                          ['migrations'])
89
+
90
+        msg = ("Live Migration failed. Migrations list for Instance "
91
+               "%s: [" % server['id'])
92
+        for live_migration in migration_list:
93
+            if live_migration['instance_uuid'] == server['id']:
94
+                msg += "\n%s" % live_migration
95
+        msg += "]"
96
+
97
+        if destination_host:
98
+            self.assertEqual(destination_host, after_migration_host, msg)
99
+        else:
100
+            self.assertNotEqual(current_host, after_migration_host, msg)
101
+
102
+    @testtools.skipUnless(CONF.compute_feature_enabled.live_migration,
103
+                          'Live migration option enabled.')
104
+    def test_live_migration(self):
105
+        server_tuple = self._create_server()
106
+        self._live_migrate_server(server_tuple)
107
+        self._check_server_connectivity(server_tuple)

+ 1
- 5
oswin_tempest_plugin/tests/scenario/test_cluster.py View File

@@ -31,6 +31,7 @@ LOG = logging.getLogger(__name__)
31 31
 
32 32
 class HyperVClusterTest(test_base.TestBase,
33 33
                         migrate._MigrateMixin,
34
+                        migrate._LiveMigrateMixin,
34 35
                         resize._ResizeMixin):
35 36
 
36 37
     """The test suite for the Hyper-V Cluster.
@@ -134,11 +135,6 @@ class HyperVClusterTest(test_base.TestBase,
134 135
                                                res_type='hypervisor')
135 136
         return hypervisor[0]
136 137
 
137
-    def _get_server_as_admin(self, server):
138
-        # only admins have access to certain instance properties.
139
-        return self.admin_servers_client.show_server(
140
-            server['id'])['server']
141
-
142 138
     def _create_server(self):
143 139
         server_tuple = super(HyperVClusterTest, self)._create_server()
144 140
         server = server_tuple.server

+ 1
- 0
oswin_tempest_plugin/tests/scenario/test_vnuma.py View File

@@ -21,6 +21,7 @@ from oswin_tempest_plugin.tests import test_base
21 21
 
22 22
 class HyperVvNumaTestCase(test_base.TestBase,
23 23
                           migrate._MigrateMixin,
24
+                          migrate._LiveMigrateMixin,
24 25
                           optional_feature._OptionalFeatureMixin,
25 26
                           resize._ResizeMixin):
26 27
     """Hyper-V vNUMA test suite.

+ 5
- 0
oswin_tempest_plugin/tests/test_base.py View File

@@ -186,6 +186,11 @@ class TestBase(tempest.test.BaseTestCase):
186 186
 
187 187
         return server_tuple
188 188
 
189
+    def _get_server_as_admin(self, server):
190
+        # only admins have access to certain instance properties.
191
+        return self.admin_servers_client.show_server(
192
+            server['id'])['server']
193
+
189 194
     def _create_security_group(self):
190 195
         sg_name = data_utils.rand_name(self.__class__.__name__)
191 196
         sg_desc = sg_name + " description"

Loading…
Cancel
Save