ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Markus Zoeller | 69d58b8 | 2017-02-17 10:09:22 +0100 | [diff] [blame] | 16 | import time |
| 17 | |
Sarafraj Singh | 61e4045 | 2016-09-29 13:06:59 -0500 | [diff] [blame] | 18 | from oslo_log import log as logging |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 19 | import testtools |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 21 | from tempest.api.compute import base |
Markus Zoeller | 69d58b8 | 2017-02-17 10:09:22 +0100 | [diff] [blame] | 22 | from tempest.common import compute |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 23 | from tempest.common import utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 24 | from tempest.common import waiters |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 25 | from tempest import config |
Brian Haley | a3879b5 | 2016-02-24 16:53:47 -0600 | [diff] [blame] | 26 | from tempest.lib import decorators |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 27 | |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 28 | CONF = config.CONF |
Sarafraj Singh | 61e4045 | 2016-09-29 13:06:59 -0500 | [diff] [blame] | 29 | LOG = logging.getLogger(__name__) |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 30 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 31 | |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 32 | class LiveMigrationTest(base.BaseV2ComputeAdminTest): |
Eli Qiao | e07eacc | 2016-03-03 13:49:37 +0800 | [diff] [blame] | 33 | max_microversion = '2.24' |
| 34 | block_migration = None |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 35 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 36 | @classmethod |
Timofey Durakov | ad7aea5 | 2015-10-12 13:37:44 +0300 | [diff] [blame] | 37 | def skip_checks(cls): |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 38 | super(LiveMigrationTest, cls).skip_checks() |
Timofey Durakov | ad7aea5 | 2015-10-12 13:37:44 +0300 | [diff] [blame] | 39 | |
| 40 | if not CONF.compute_feature_enabled.live_migration: |
| 41 | skip_msg = ("%s skipped as live-migration is " |
| 42 | "not available" % cls.__name__) |
| 43 | raise cls.skipException(skip_msg) |
Jordan Pittier | f60c100 | 2015-11-16 11:24:09 +0100 | [diff] [blame] | 44 | if CONF.compute.min_compute_nodes < 2: |
Timofey Durakov | 7a04e91 | 2015-11-17 17:37:53 +0300 | [diff] [blame] | 45 | raise cls.skipException( |
Timofey Durakov | ad7aea5 | 2015-10-12 13:37:44 +0300 | [diff] [blame] | 46 | "Less than 2 compute nodes, skipping migration test.") |
| 47 | |
| 48 | @classmethod |
Matt Riedemann | 75891d8 | 2017-10-11 12:10:16 -0400 | [diff] [blame] | 49 | def setup_credentials(cls): |
| 50 | # These tests don't attempt any SSH validation nor do they use |
| 51 | # floating IPs on the instance, so all we need is a network and |
| 52 | # a subnet so the instance being migrated has a single port, but |
| 53 | # we need that to make sure we are properly updating the port |
| 54 | # host bindings during the live migration. |
| 55 | # TODO(mriedem): SSH validation before and after the instance is |
| 56 | # live migrated would be a nice test wrinkle addition. |
| 57 | cls.set_network_resources(network=True, subnet=True) |
| 58 | super(LiveMigrationTest, cls).setup_credentials() |
| 59 | |
| 60 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 61 | def setup_clients(cls): |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 62 | super(LiveMigrationTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 63 | cls.admin_migration_client = cls.os_admin.migrations_client |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 64 | |
Claudiu Belu | 516b7a4 | 2016-03-03 06:28:43 -0800 | [diff] [blame] | 65 | def _migrate_server_to(self, server_id, dest_host, volume_backed=False): |
Eli Qiao | e07eacc | 2016-03-03 13:49:37 +0800 | [diff] [blame] | 66 | kwargs = dict() |
| 67 | block_migration = getattr(self, 'block_migration', None) |
| 68 | if self.block_migration is None: |
| 69 | kwargs['disk_over_commit'] = False |
| 70 | block_migration = (CONF.compute_feature_enabled. |
| 71 | block_migration_for_live_migration and |
| 72 | not volume_backed) |
zhufl | 4a2cfff | 2017-01-03 15:45:02 +0800 | [diff] [blame] | 73 | self.admin_servers_client.live_migrate_server( |
Timofey Durakov | f358a7e | 2015-10-05 13:06:51 +0300 | [diff] [blame] | 74 | server_id, host=dest_host, block_migration=block_migration, |
Eli Qiao | e07eacc | 2016-03-03 13:49:37 +0800 | [diff] [blame] | 75 | **kwargs) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 76 | |
Sarafraj Singh | 61e4045 | 2016-09-29 13:06:59 -0500 | [diff] [blame] | 77 | def _live_migrate(self, server_id, target_host, state, |
| 78 | volume_backed=False): |
| 79 | self._migrate_server_to(server_id, target_host, volume_backed) |
| 80 | waiters.wait_for_server_status(self.servers_client, server_id, state) |
| 81 | migration_list = (self.admin_migration_client.list_migrations() |
| 82 | ['migrations']) |
| 83 | |
| 84 | msg = ("Live Migration failed. Migrations list for Instance " |
| 85 | "%s: [" % server_id) |
| 86 | for live_migration in migration_list: |
| 87 | if (live_migration['instance_uuid'] == server_id): |
| 88 | msg += "\n%s" % live_migration |
| 89 | msg += "]" |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 90 | self.assertEqual(target_host, self.get_host_for_server(server_id), |
Sarafraj Singh | 61e4045 | 2016-09-29 13:06:59 -0500 | [diff] [blame] | 91 | msg) |
| 92 | |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 93 | def _test_live_migration(self, state='ACTIVE', volume_backed=False): |
| 94 | """Tests live migration between two hosts. |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 95 | |
| 96 | Requires CONF.compute_feature_enabled.live_migration to be True. |
| 97 | |
| 98 | :param state: The vm_state the migrated server should be in before and |
| 99 | after the live migration. Supported values are 'ACTIVE' |
| 100 | and 'PAUSED'. |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 101 | :param volume_backed: If the instance is volume backed or not. If |
| 102 | volume_backed, *block* migration is not used. |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 103 | """ |
Timofey Durakov | f358a7e | 2015-10-05 13:06:51 +0300 | [diff] [blame] | 104 | # Live migrate an instance to another host |
Jordan Pittier | 599a356 | 2016-01-08 17:38:14 +0100 | [diff] [blame] | 105 | server_id = self.create_test_server(wait_until="ACTIVE", |
| 106 | volume_backed=volume_backed)['id'] |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 107 | source_host = self.get_host_for_server(server_id) |
| 108 | destination_host = self.get_host_other_than(server_id) |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 109 | |
| 110 | if state == 'PAUSED': |
| 111 | self.admin_servers_client.pause_server(server_id) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 112 | waiters.wait_for_server_status(self.admin_servers_client, |
| 113 | server_id, state) |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 114 | |
Sarafraj Singh | 61e4045 | 2016-09-29 13:06:59 -0500 | [diff] [blame] | 115 | LOG.info("Live migrate from source %s to destination %s", |
| 116 | source_host, destination_host) |
| 117 | self._live_migrate(server_id, destination_host, state, volume_backed) |
| 118 | if CONF.compute_feature_enabled.live_migrate_back_and_forth: |
| 119 | # If live_migrate_back_and_forth is enabled it is a grenade job. |
| 120 | # Therefore test should validate whether LM is compatible in both |
| 121 | # ways, so live migrate VM back to the source host |
| 122 | LOG.info("Live migrate back to source %s", source_host) |
| 123 | self._live_migrate(server_id, source_host, state, volume_backed) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 124 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 125 | @decorators.idempotent_id('1dce86b8-eb04-4c03-a9d8-9c1dc3ee0c7b') |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 126 | def test_live_block_migration(self): |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 127 | self._test_live_migration() |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 128 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 129 | @decorators.idempotent_id('1e107f21-61b2-4988-8f22-b196e938ab88') |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 130 | @testtools.skipUnless(CONF.compute_feature_enabled.pause, |
| 131 | 'Pause is not available.') |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 132 | def test_live_block_migration_paused(self): |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 133 | self._test_live_migration(state='PAUSED') |
| 134 | |
Matt Riedemann | ea8796a | 2016-10-15 13:44:09 -0400 | [diff] [blame] | 135 | @decorators.skip_because(bug="1524898") |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 136 | @decorators.idempotent_id('5071cf17-3004-4257-ae61-73a84e28badd') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 137 | @utils.services('volume') |
Joe Gordon | 8843f0f | 2015-03-17 15:07:34 -0700 | [diff] [blame] | 138 | def test_volume_backed_live_migration(self): |
| 139 | self._test_live_migration(volume_backed=True) |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 140 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 141 | @decorators.idempotent_id('e19c0cc6-6720-4ed8-be83-b6603ed5c812') |
Timofey Durakov | ad7aea5 | 2015-10-12 13:37:44 +0300 | [diff] [blame] | 142 | @testtools.skipIf(not CONF.compute_feature_enabled. |
Matthew Treinish | d5c9602 | 2013-10-17 21:51:23 +0000 | [diff] [blame] | 143 | block_migration_for_live_migration, |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 144 | 'Block Live migration not available') |
Matthew Treinish | d5c9602 | 2013-10-17 21:51:23 +0000 | [diff] [blame] | 145 | @testtools.skipIf(not CONF.compute_feature_enabled. |
| 146 | block_migrate_cinder_iscsi, |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 147 | 'Block Live migration not configured for iSCSI') |
| 148 | def test_iscsi_volume(self): |
Matt Riedemann | cb16a66 | 2016-10-01 18:30:05 -0400 | [diff] [blame] | 149 | server = self.create_test_server(wait_until="ACTIVE") |
| 150 | server_id = server['id'] |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 151 | target_host = self.get_host_other_than(server_id) |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 152 | |
Matt Riedemann | cb16a66 | 2016-10-01 18:30:05 -0400 | [diff] [blame] | 153 | volume = self.create_volume() |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 154 | |
| 155 | # Attach the volume to the server |
Matt Riedemann | cb16a66 | 2016-10-01 18:30:05 -0400 | [diff] [blame] | 156 | self.attach_volume(server, volume, device='/dev/xvdb') |
lianghao | 39d8699 | 2017-04-11 16:01:26 +0800 | [diff] [blame] | 157 | server = self.admin_servers_client.show_server(server_id)['server'] |
| 158 | volume_id1 = server["os-extended-volumes:volumes_attached"][0]["id"] |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 159 | self._migrate_server_to(server_id, target_host) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 160 | waiters.wait_for_server_status(self.servers_client, |
| 161 | server_id, 'ACTIVE') |
lianghao | 39d8699 | 2017-04-11 16:01:26 +0800 | [diff] [blame] | 162 | |
| 163 | server = self.admin_servers_client.show_server(server_id)['server'] |
| 164 | volume_id2 = server["os-extended-volumes:volumes_attached"][0]["id"] |
| 165 | |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 166 | self.assertEqual(target_host, self.get_host_for_server(server_id)) |
lianghao | 39d8699 | 2017-04-11 16:01:26 +0800 | [diff] [blame] | 167 | self.assertEqual(volume_id1, volume_id2) |
Eli Qiao | e07eacc | 2016-03-03 13:49:37 +0800 | [diff] [blame] | 168 | |
| 169 | |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 170 | class LiveMigrationRemoteConsolesV26Test(LiveMigrationTest): |
Markus Zoeller | 69d58b8 | 2017-02-17 10:09:22 +0100 | [diff] [blame] | 171 | min_microversion = '2.6' |
| 172 | max_microversion = 'latest' |
| 173 | |
| 174 | @decorators.idempotent_id('6190af80-513e-4f0f-90f2-9714e84955d7') |
| 175 | @testtools.skipUnless(CONF.compute_feature_enabled.serial_console, |
| 176 | 'Serial console not supported.') |
| 177 | @testtools.skipUnless( |
Andrea Frittoli | 88eb677 | 2017-08-07 21:06:27 +0100 | [diff] [blame] | 178 | compute.is_scheduler_filter_enabled("DifferentHostFilter"), |
Markus Zoeller | 69d58b8 | 2017-02-17 10:09:22 +0100 | [diff] [blame] | 179 | 'DifferentHostFilter is not available.') |
| 180 | def test_live_migration_serial_console(self): |
| 181 | """Test the live-migration of an instance which has a serial console |
| 182 | |
| 183 | The serial console feature of an instance uses ports on the host. |
| 184 | These ports need to be updated when they are already in use by |
| 185 | another instance on the target host. This test checks if this |
| 186 | update behavior is correctly done, by connecting to the serial |
| 187 | consoles of the instances before and after the live migration. |
| 188 | """ |
| 189 | server01_id = self.create_test_server(wait_until='ACTIVE')['id'] |
| 190 | hints = {'different_host': server01_id} |
| 191 | server02_id = self.create_test_server(scheduler_hints=hints, |
| 192 | wait_until='ACTIVE')['id'] |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 193 | host01_id = self.get_host_for_server(server01_id) |
| 194 | host02_id = self.get_host_for_server(server02_id) |
Markus Zoeller | 69d58b8 | 2017-02-17 10:09:22 +0100 | [diff] [blame] | 195 | self.assertNotEqual(host01_id, host02_id) |
| 196 | |
| 197 | # At this step we have 2 instances on different hosts, both with |
| 198 | # serial consoles, both with port 10000 (the default value). |
| 199 | # https://bugs.launchpad.net/nova/+bug/1455252 describes the issue |
| 200 | # when live-migrating in such a scenario. |
| 201 | |
| 202 | self._verify_console_interaction(server01_id) |
| 203 | self._verify_console_interaction(server02_id) |
| 204 | |
| 205 | self._migrate_server_to(server01_id, host02_id) |
| 206 | waiters.wait_for_server_status(self.servers_client, |
| 207 | server01_id, 'ACTIVE') |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 208 | self.assertEqual(host02_id, self.get_host_for_server(server01_id)) |
Markus Zoeller | 69d58b8 | 2017-02-17 10:09:22 +0100 | [diff] [blame] | 209 | self._verify_console_interaction(server01_id) |
| 210 | # At this point, both instances have a valid serial console |
| 211 | # connection, which means the ports got updated. |
| 212 | |
| 213 | def _verify_console_interaction(self, server_id): |
| 214 | body = self.servers_client.get_remote_console(server_id, |
| 215 | console_type='serial', |
| 216 | protocol='serial') |
| 217 | console_url = body['remote_console']['url'] |
| 218 | data = "test_live_migration_serial_console" |
| 219 | console_output = '' |
| 220 | t = 0.0 |
| 221 | interval = 0.1 |
| 222 | |
| 223 | ws = compute.create_websocket(console_url) |
| 224 | try: |
| 225 | # NOTE (markus_z): It can take a long time until the terminal |
| 226 | # of the instance is available for interaction. Hence the |
| 227 | # long timeout value. |
| 228 | while data not in console_output and t <= 120.0: |
| 229 | try: |
| 230 | ws.send_frame(data) |
| 231 | recieved = ws.receive_frame() |
| 232 | console_output += recieved |
| 233 | except Exception: |
| 234 | # In case we had an issue with send/receive on the |
| 235 | # websocket connection, we create a new one. |
| 236 | ws = compute.create_websocket(console_url) |
| 237 | time.sleep(interval) |
| 238 | t += interval |
| 239 | finally: |
| 240 | ws.close() |
| 241 | self.assertIn(data, console_output) |
| 242 | |
| 243 | |
Duc Truong | 0994120 | 2017-06-07 10:15:20 -0700 | [diff] [blame] | 244 | class LiveAutoBlockMigrationV225Test(LiveMigrationTest): |
Eli Qiao | e07eacc | 2016-03-03 13:49:37 +0800 | [diff] [blame] | 245 | min_microversion = '2.25' |
| 246 | max_microversion = 'latest' |
| 247 | block_migration = 'auto' |