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 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 16 | |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 17 | import testtools |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 18 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 19 | from tempest.api.compute import base |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 20 | from tempest.common import waiters |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 21 | from tempest import config |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 22 | from tempest import test |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 23 | |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 26 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 27 | class LiveBlockMigrationTestJSON(base.BaseV2ComputeAdminTest): |
Mate Lakat | 0ccf0eb | 2013-03-28 12:00:52 +0000 | [diff] [blame] | 28 | _host_key = 'OS-EXT-SRV-ATTR:host' |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 29 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 30 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 31 | def setup_clients(cls): |
| 32 | super(LiveBlockMigrationTestJSON, cls).setup_clients() |
Attila Fazekas | 8e99b99 | 2013-02-24 09:53:23 +0100 | [diff] [blame] | 33 | cls.admin_hosts_client = cls.os_adm.hosts_client |
| 34 | cls.admin_servers_client = cls.os_adm.servers_client |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 35 | |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 36 | @classmethod |
| 37 | def resource_setup(cls): |
| 38 | super(LiveBlockMigrationTestJSON, cls).resource_setup() |
| 39 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 40 | cls.created_server_ids = [] |
| 41 | |
| 42 | def _get_compute_hostnames(self): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 43 | body = self.admin_hosts_client.list_hosts() |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 44 | return [ |
| 45 | host_record['host_name'] |
| 46 | for host_record in body |
| 47 | if host_record['service'] == 'compute' |
| 48 | ] |
| 49 | |
| 50 | def _get_server_details(self, server_id): |
Ken'ichi Ohmichi | 7680024 | 2015-07-03 05:12:31 +0000 | [diff] [blame] | 51 | body = self.admin_servers_client.show_server(server_id) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 52 | return body |
| 53 | |
| 54 | def _get_host_for_server(self, server_id): |
Mate Lakat | 0ccf0eb | 2013-03-28 12:00:52 +0000 | [diff] [blame] | 55 | return self._get_server_details(server_id)[self._host_key] |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 56 | |
| 57 | def _migrate_server_to(self, server_id, dest_host): |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 58 | body = self.admin_servers_client.live_migrate_server( |
Bob Ball | 0dca897 | 2013-04-09 16:23:31 +0100 | [diff] [blame] | 59 | server_id, dest_host, |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 60 | CONF.compute_feature_enabled.block_migration_for_live_migration) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 61 | return body |
| 62 | |
| 63 | def _get_host_other_than(self, host): |
| 64 | for target_host in self._get_compute_hostnames(): |
| 65 | if host != target_host: |
| 66 | return target_host |
| 67 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 68 | def _get_server_status(self, server_id): |
| 69 | return self._get_server_details(server_id)['status'] |
| 70 | |
| 71 | def _get_an_active_server(self): |
| 72 | for server_id in self.created_server_ids: |
| 73 | if 'ACTIVE' == self._get_server_status(server_id): |
| 74 | return server_id |
| 75 | else: |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 76 | server = self.create_test_server(wait_until="ACTIVE") |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 77 | server_id = server['id'] |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 78 | self.created_server_ids.append(server_id) |
| 79 | return server_id |
| 80 | |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 81 | def _volume_clean_up(self, server_id, volume_id): |
Timofey Durakov | eb82f48 | 2015-04-30 18:24:30 +0300 | [diff] [blame] | 82 | body = self.volumes_client.show_volume(volume_id) |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 83 | if body['status'] == 'in-use': |
| 84 | self.servers_client.detach_volume(server_id, volume_id) |
| 85 | self.volumes_client.wait_for_volume_status(volume_id, 'available') |
| 86 | self.volumes_client.delete_volume(volume_id) |
| 87 | |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 88 | def _test_live_block_migration(self, state='ACTIVE'): |
| 89 | """Tests live block migration between two hosts. |
| 90 | |
| 91 | Requires CONF.compute_feature_enabled.live_migration to be True. |
| 92 | |
| 93 | :param state: The vm_state the migrated server should be in before and |
| 94 | after the live migration. Supported values are 'ACTIVE' |
| 95 | and 'PAUSED'. |
| 96 | """ |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 97 | # Live block migrate an instance to another host |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 98 | if len(self._get_compute_hostnames()) < 2: |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 99 | raise self.skipTest( |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 100 | "Less than 2 compute nodes, skipping migration test.") |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 101 | server_id = self._get_an_active_server() |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 102 | actual_host = self._get_host_for_server(server_id) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 103 | target_host = self._get_host_other_than(actual_host) |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 104 | |
| 105 | if state == 'PAUSED': |
| 106 | self.admin_servers_client.pause_server(server_id) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 107 | waiters.wait_for_server_status(self.admin_servers_client, |
| 108 | server_id, state) |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 109 | |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 110 | self._migrate_server_to(server_id, target_host) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 111 | waiters.wait_for_server_status(self.servers_client, server_id, state) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 112 | self.assertEqual(target_host, self._get_host_for_server(server_id)) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 113 | |
Matt Riedemann | bb9f704 | 2015-03-03 08:53:11 -0800 | [diff] [blame] | 114 | @test.idempotent_id('1dce86b8-eb04-4c03-a9d8-9c1dc3ee0c7b') |
| 115 | @testtools.skipUnless(CONF.compute_feature_enabled.live_migration, |
| 116 | 'Live migration not available') |
| 117 | def test_live_block_migration(self): |
| 118 | self._test_live_block_migration() |
| 119 | |
| 120 | @test.idempotent_id('1e107f21-61b2-4988-8f22-b196e938ab88') |
| 121 | @testtools.skipUnless(CONF.compute_feature_enabled.live_migration, |
| 122 | 'Live migration not available') |
| 123 | @testtools.skipUnless(CONF.compute_feature_enabled.pause, |
| 124 | 'Pause is not available.') |
| 125 | @testtools.skipUnless(CONF.compute_feature_enabled |
| 126 | .live_migrate_paused_instances, |
| 127 | 'Live migration of paused instances is not ' |
| 128 | 'available.') |
| 129 | def test_live_block_migration_paused(self): |
| 130 | self._test_live_block_migration(state='PAUSED') |
| 131 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 132 | @test.idempotent_id('e19c0cc6-6720-4ed8-be83-b6603ed5c812') |
Matthew Treinish | d5c9602 | 2013-10-17 21:51:23 +0000 | [diff] [blame] | 133 | @testtools.skipIf(not CONF.compute_feature_enabled.live_migration or not |
| 134 | CONF.compute_feature_enabled. |
| 135 | block_migration_for_live_migration, |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 136 | 'Block Live migration not available') |
Matthew Treinish | d5c9602 | 2013-10-17 21:51:23 +0000 | [diff] [blame] | 137 | @testtools.skipIf(not CONF.compute_feature_enabled. |
| 138 | block_migrate_cinder_iscsi, |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 139 | 'Block Live migration not configured for iSCSI') |
| 140 | def test_iscsi_volume(self): |
| 141 | # Live block migrate an instance to another host |
| 142 | if len(self._get_compute_hostnames()) < 2: |
| 143 | raise self.skipTest( |
| 144 | "Less than 2 compute nodes, skipping migration test.") |
| 145 | server_id = self._get_an_active_server() |
| 146 | actual_host = self._get_host_for_server(server_id) |
| 147 | target_host = self._get_host_other_than(actual_host) |
| 148 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 149 | volume = self.volumes_client.create_volume(display_name='test') |
Bob Ball | c078be9 | 2013-04-09 14:25:00 +0100 | [diff] [blame] | 150 | |
| 151 | self.volumes_client.wait_for_volume_status(volume['id'], |
| 152 | 'available') |
| 153 | self.addCleanup(self._volume_clean_up, server_id, volume['id']) |
| 154 | |
| 155 | # Attach the volume to the server |
| 156 | self.servers_client.attach_volume(server_id, volume['id'], |
| 157 | device='/dev/xvdb') |
| 158 | self.volumes_client.wait_for_volume_status(volume['id'], 'in-use') |
| 159 | |
| 160 | self._migrate_server_to(server_id, target_host) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 161 | waiters.wait_for_server_status(self.servers_client, |
| 162 | server_id, 'ACTIVE') |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 163 | self.assertEqual(target_host, self._get_host_for_server(server_id)) |