blob: 6ffa4e9ed4c3fba6a7883b153b485d92abe315a8 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Mate Lakat99ee9142012-09-14 12:34:46 +01002# 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 Lakat99ee9142012-09-14 12:34:46 +010016
ivan-zhu1feeb382013-01-24 10:14:39 +080017import testtools
Matthew Treinisha83a16e2012-12-07 13:44:02 -050018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000020from tempest.common import waiters
Mate Lakat99ee9142012-09-14 12:34:46 +010021from tempest import config
Yuiko Takadae9999d62014-03-06 09:22:54 +000022from tempest import test
Mate Lakat99ee9142012-09-14 12:34:46 +010023
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000024CONF = config.CONF
25
Mate Lakat99ee9142012-09-14 12:34:46 +010026
ivan-zhuf2b00502013-10-18 10:06:52 +080027class LiveBlockMigrationTestJSON(base.BaseV2ComputeAdminTest):
Mate Lakat0ccf0eb2013-03-28 12:00:52 +000028 _host_key = 'OS-EXT-SRV-ATTR:host'
Mate Lakat99ee9142012-09-14 12:34:46 +010029
Mate Lakat99ee9142012-09-14 12:34:46 +010030 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053031 def setup_clients(cls):
32 super(LiveBlockMigrationTestJSON, cls).setup_clients()
Attila Fazekas8e99b992013-02-24 09:53:23 +010033 cls.admin_hosts_client = cls.os_adm.hosts_client
34 cls.admin_servers_client = cls.os_adm.servers_client
Mate Lakat99ee9142012-09-14 12:34:46 +010035
Rohan Kanade60b73092015-02-04 17:58:19 +053036 @classmethod
37 def resource_setup(cls):
38 super(LiveBlockMigrationTestJSON, cls).resource_setup()
39
Mate Lakat99ee9142012-09-14 12:34:46 +010040 cls.created_server_ids = []
41
42 def _get_compute_hostnames(self):
David Kranz0a735172015-01-16 10:51:18 -050043 body = self.admin_hosts_client.list_hosts()
Mate Lakat99ee9142012-09-14 12:34:46 +010044 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 Ohmichi76800242015-07-03 05:12:31 +000051 body = self.admin_servers_client.show_server(server_id)
Mate Lakat99ee9142012-09-14 12:34:46 +010052 return body
53
54 def _get_host_for_server(self, server_id):
Mate Lakat0ccf0eb2013-03-28 12:00:52 +000055 return self._get_server_details(server_id)[self._host_key]
Mate Lakat99ee9142012-09-14 12:34:46 +010056
57 def _migrate_server_to(self, server_id, dest_host):
David Kranzae99b9a2015-02-16 13:37:01 -050058 body = self.admin_servers_client.live_migrate_server(
Bob Ball0dca8972013-04-09 16:23:31 +010059 server_id, dest_host,
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000060 CONF.compute_feature_enabled.block_migration_for_live_migration)
Mate Lakat99ee9142012-09-14 12:34:46 +010061 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 Lakat99ee9142012-09-14 12:34:46 +010068 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 Kranz0fb14292015-02-11 15:55:20 -050076 server = self.create_test_server(wait_until="ACTIVE")
Mate Lakat99ee9142012-09-14 12:34:46 +010077 server_id = server['id']
Mate Lakat99ee9142012-09-14 12:34:46 +010078 self.created_server_ids.append(server_id)
79 return server_id
80
Bob Ballc078be92013-04-09 14:25:00 +010081 def _volume_clean_up(self, server_id, volume_id):
Timofey Durakoveb82f482015-04-30 18:24:30 +030082 body = self.volumes_client.show_volume(volume_id)
Bob Ballc078be92013-04-09 14:25:00 +010083 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 Riedemannbb9f7042015-03-03 08:53:11 -080088 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 Dague4dd2c0b2013-01-03 17:50:28 -050097 # Live block migrate an instance to another host
Mate Lakat99ee9142012-09-14 12:34:46 +010098 if len(self._get_compute_hostnames()) < 2:
ivan-zhu1feeb382013-01-24 10:14:39 +080099 raise self.skipTest(
Mate Lakat99ee9142012-09-14 12:34:46 +0100100 "Less than 2 compute nodes, skipping migration test.")
Mate Lakat99ee9142012-09-14 12:34:46 +0100101 server_id = self._get_an_active_server()
Mate Lakat99ee9142012-09-14 12:34:46 +0100102 actual_host = self._get_host_for_server(server_id)
Mate Lakat99ee9142012-09-14 12:34:46 +0100103 target_host = self._get_host_other_than(actual_host)
Matt Riedemannbb9f7042015-03-03 08:53:11 -0800104
105 if state == 'PAUSED':
106 self.admin_servers_client.pause_server(server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000107 waiters.wait_for_server_status(self.admin_servers_client,
108 server_id, state)
Matt Riedemannbb9f7042015-03-03 08:53:11 -0800109
Mate Lakat99ee9142012-09-14 12:34:46 +0100110 self._migrate_server_to(server_id, target_host)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000111 waiters.wait_for_server_status(self.servers_client, server_id, state)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700112 self.assertEqual(target_host, self._get_host_for_server(server_id))
Mate Lakat99ee9142012-09-14 12:34:46 +0100113
Matt Riedemannbb9f7042015-03-03 08:53:11 -0800114 @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 Hoge7579c1a2015-02-26 14:12:15 -0800132 @test.idempotent_id('e19c0cc6-6720-4ed8-be83-b6603ed5c812')
Matthew Treinishd5c96022013-10-17 21:51:23 +0000133 @testtools.skipIf(not CONF.compute_feature_enabled.live_migration or not
134 CONF.compute_feature_enabled.
135 block_migration_for_live_migration,
Bob Ballc078be92013-04-09 14:25:00 +0100136 'Block Live migration not available')
Matthew Treinishd5c96022013-10-17 21:51:23 +0000137 @testtools.skipIf(not CONF.compute_feature_enabled.
138 block_migrate_cinder_iscsi,
Bob Ballc078be92013-04-09 14:25:00 +0100139 '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 Zoeller3d2a21c2015-02-27 12:04:22 +0100149 volume = self.volumes_client.create_volume(display_name='test')
Bob Ballc078be92013-04-09 14:25:00 +0100150
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 Ohmichi0eb153c2015-07-13 02:18:25 +0000161 waiters.wait_for_server_status(self.servers_client,
162 server_id, 'ACTIVE')
Chang Bo Guofc77e932013-09-16 17:38:26 -0700163 self.assertEqual(target_host, self._get_host_for_server(server_id))