blob: 93ff4b0ad9919247a489d227be06c53e8e453308 [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
Mate Lakat99ee9142012-09-14 12:34:46 +010020from tempest import config
Yuiko Takadae9999d62014-03-06 09:22:54 +000021from tempest import test
Mate Lakat99ee9142012-09-14 12:34:46 +010022
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000023CONF = config.CONF
24
Mate Lakat99ee9142012-09-14 12:34:46 +010025
ivan-zhuf2b00502013-10-18 10:06:52 +080026class LiveBlockMigrationTestJSON(base.BaseV2ComputeAdminTest):
Mate Lakat0ccf0eb2013-03-28 12:00:52 +000027 _host_key = 'OS-EXT-SRV-ATTR:host'
Mate Lakat99ee9142012-09-14 12:34:46 +010028
Mate Lakat99ee9142012-09-14 12:34:46 +010029 @classmethod
30 def setUpClass(cls):
ravikumar-venkatesan753262b2013-03-21 12:43:57 +000031 super(LiveBlockMigrationTestJSON, cls).setUpClass()
Mate Lakat99ee9142012-09-14 12:34:46 +010032
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
36 cls.created_server_ids = []
37
38 def _get_compute_hostnames(self):
39 _resp, body = self.admin_hosts_client.list_hosts()
40 return [
41 host_record['host_name']
42 for host_record in body
43 if host_record['service'] == 'compute'
44 ]
45
46 def _get_server_details(self, server_id):
47 _resp, body = self.admin_servers_client.get_server(server_id)
48 return body
49
50 def _get_host_for_server(self, server_id):
Mate Lakat0ccf0eb2013-03-28 12:00:52 +000051 return self._get_server_details(server_id)[self._host_key]
Mate Lakat99ee9142012-09-14 12:34:46 +010052
53 def _migrate_server_to(self, server_id, dest_host):
54 _resp, body = self.admin_servers_client.live_migrate_server(
Bob Ball0dca8972013-04-09 16:23:31 +010055 server_id, dest_host,
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000056 CONF.compute_feature_enabled.block_migration_for_live_migration)
Mate Lakat99ee9142012-09-14 12:34:46 +010057 return body
58
59 def _get_host_other_than(self, host):
60 for target_host in self._get_compute_hostnames():
61 if host != target_host:
62 return target_host
63
Mate Lakat99ee9142012-09-14 12:34:46 +010064 def _get_server_status(self, server_id):
65 return self._get_server_details(server_id)['status']
66
67 def _get_an_active_server(self):
68 for server_id in self.created_server_ids:
69 if 'ACTIVE' == self._get_server_status(server_id):
70 return server_id
71 else:
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090072 _, server = self.create_test_server(wait_until="ACTIVE")
Mate Lakat99ee9142012-09-14 12:34:46 +010073 server_id = server['id']
74 self.password = server['adminPass']
75 self.password = 'password'
76 self.created_server_ids.append(server_id)
77 return server_id
78
Bob Ballc078be92013-04-09 14:25:00 +010079 def _volume_clean_up(self, server_id, volume_id):
80 resp, body = self.volumes_client.get_volume(volume_id)
81 if body['status'] == 'in-use':
82 self.servers_client.detach_volume(server_id, volume_id)
83 self.volumes_client.wait_for_volume_status(volume_id, 'available')
84 self.volumes_client.delete_volume(volume_id)
85
Matthew Treinishd5c96022013-10-17 21:51:23 +000086 @testtools.skipIf(not CONF.compute_feature_enabled.live_migration,
Bob Ball0dca8972013-04-09 16:23:31 +010087 'Live migration not available')
Yuiko Takadae9999d62014-03-06 09:22:54 +000088 @test.attr(type='gate')
Attila Fazekas8e99b992013-02-24 09:53:23 +010089 def test_live_block_migration(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050090 # Live block migrate an instance to another host
Mate Lakat99ee9142012-09-14 12:34:46 +010091 if len(self._get_compute_hostnames()) < 2:
ivan-zhu1feeb382013-01-24 10:14:39 +080092 raise self.skipTest(
Mate Lakat99ee9142012-09-14 12:34:46 +010093 "Less than 2 compute nodes, skipping migration test.")
Mate Lakat99ee9142012-09-14 12:34:46 +010094 server_id = self._get_an_active_server()
Mate Lakat99ee9142012-09-14 12:34:46 +010095 actual_host = self._get_host_for_server(server_id)
Mate Lakat99ee9142012-09-14 12:34:46 +010096 target_host = self._get_host_other_than(actual_host)
Mate Lakat99ee9142012-09-14 12:34:46 +010097 self._migrate_server_to(server_id, target_host)
Mate Lakat99ee9142012-09-14 12:34:46 +010098 self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
Chang Bo Guofc77e932013-09-16 17:38:26 -070099 self.assertEqual(target_host, self._get_host_for_server(server_id))
Mate Lakat99ee9142012-09-14 12:34:46 +0100100
Matthew Treinishd5c96022013-10-17 21:51:23 +0000101 @testtools.skipIf(not CONF.compute_feature_enabled.live_migration or not
102 CONF.compute_feature_enabled.
103 block_migration_for_live_migration,
Bob Ballc078be92013-04-09 14:25:00 +0100104 'Block Live migration not available')
Matthew Treinishd5c96022013-10-17 21:51:23 +0000105 @testtools.skipIf(not CONF.compute_feature_enabled.
106 block_migrate_cinder_iscsi,
Bob Ballc078be92013-04-09 14:25:00 +0100107 'Block Live migration not configured for iSCSI')
Yuiko Takadae9999d62014-03-06 09:22:54 +0000108 @test.attr(type='gate')
Bob Ballc078be92013-04-09 14:25:00 +0100109 def test_iscsi_volume(self):
110 # Live block migrate an instance to another host
111 if len(self._get_compute_hostnames()) < 2:
112 raise self.skipTest(
113 "Less than 2 compute nodes, skipping migration test.")
114 server_id = self._get_an_active_server()
115 actual_host = self._get_host_for_server(server_id)
116 target_host = self._get_host_other_than(actual_host)
117
118 resp, volume = self.volumes_client.create_volume(1,
119 display_name='test')
120
121 self.volumes_client.wait_for_volume_status(volume['id'],
122 'available')
123 self.addCleanup(self._volume_clean_up, server_id, volume['id'])
124
125 # Attach the volume to the server
126 self.servers_client.attach_volume(server_id, volume['id'],
127 device='/dev/xvdb')
128 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
129
130 self._migrate_server_to(server_id, target_host)
131 self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
Chang Bo Guofc77e932013-09-16 17:38:26 -0700132 self.assertEqual(target_host, self._get_host_for_server(server_id))
Bob Ballc078be92013-04-09 14:25:00 +0100133
ravikumar-venkatesan753262b2013-03-21 12:43:57 +0000134
135class LiveBlockMigrationTestXML(LiveBlockMigrationTestJSON):
Mate Lakat0ccf0eb2013-03-28 12:00:52 +0000136 _host_key = (
137 '{http://docs.openstack.org/compute/ext/extended_status/api/v1.1}host')
ravikumar-venkatesan753262b2013-03-21 12:43:57 +0000138 _interface = 'xml'