blob: 83f2e610fe6ea02c6be5ed3e7ce62242dc259ec5 [file] [log] [blame]
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +09001# Copyright 2014 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import testtools
16
17from tempest.api.compute import base
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000018from tempest.common import waiters
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090019from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080020from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080021from tempest.lib import decorators
Matt Riedemann98c32b72016-04-18 19:34:47 -040022from tempest.lib import exceptions
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090023
24CONF = config.CONF
25
26
27class MigrationsAdminTest(base.BaseV2ComputeAdminTest):
28
29 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053030 def setup_clients(cls):
31 super(MigrationsAdminTest, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020032 cls.client = cls.os_admin.migrations_client
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090033
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080034 @decorators.idempotent_id('75c0b83d-72a0-4cf8-a153-631e83e7d53f')
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090035 def test_list_migrations(self):
36 # Admin can get the migrations list
David Kranz5cf4ba42015-02-10 14:00:50 -050037 self.client.list_migrations()
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090038
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080039 @decorators.idempotent_id('1b512062-8093-438e-b47a-37d2f597cd64')
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090040 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
41 'Resize not available.')
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090042 def test_list_migrations_in_flavor_resize_situation(self):
43 # Admin can get the migrations list which contains the resized server
David Kranz0fb14292015-02-11 15:55:20 -050044 server = self.create_test_server(wait_until="ACTIVE")
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090045 server_id = server['id']
46
zhufl3d018b02016-11-25 16:43:04 +080047 self.resize_server(server_id, self.flavor_ref_alt)
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090048
ghanshyam8a599492015-08-24 15:55:59 +090049 body = self.client.list_migrations()['migrations']
Ken'ichi Ohmichi2fdc1822014-03-18 09:10:57 +090050
51 instance_uuids = [x['instance_uuid'] for x in body]
52 self.assertIn(server_id, instance_uuids)
Matt Riedemann98c32b72016-04-18 19:34:47 -040053
54 def _flavor_clean_up(self, flavor_id):
55 try:
zhuflfec7c592017-03-01 17:38:13 +080056 self.admin_flavors_client.delete_flavor(flavor_id)
57 self.admin_flavors_client.wait_for_resource_deletion(flavor_id)
Matt Riedemann98c32b72016-04-18 19:34:47 -040058 except exceptions.NotFound:
59 pass
60
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080061 @decorators.idempotent_id('33f1fec3-ba18-4470-8e4e-1d888e7c3593')
Matt Riedemann98c32b72016-04-18 19:34:47 -040062 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
63 'Resize not available.')
64 def test_resize_server_revert_deleted_flavor(self):
65 # Tests that we can revert the resize on an instance whose original
66 # flavor has been deleted.
67
68 # First we have to create a flavor that we can delete so make a copy
69 # of the normal flavor from which we'd create a server.
zhuflfec7c592017-03-01 17:38:13 +080070 flavor = self.admin_flavors_client.show_flavor(
Matt Riedemann98c32b72016-04-18 19:34:47 -040071 self.flavor_ref)['flavor']
zhuflfec7c592017-03-01 17:38:13 +080072 flavor = self.admin_flavors_client.create_flavor(
Matt Riedemann98c32b72016-04-18 19:34:47 -040073 name=data_utils.rand_name('test_resize_flavor_'),
74 ram=flavor['ram'],
75 disk=flavor['disk'],
76 vcpus=flavor['vcpus']
77 )['flavor']
78 self.addCleanup(self._flavor_clean_up, flavor['id'])
79
zhuflc88e0a12017-12-28 11:30:01 +080080 # Set extra specs same as self.flavor_ref for the created flavor,
81 # because the environment may need some special extra specs to
82 # create server which should have been contained in
83 # self.flavor_ref.
84 extra_spec_keys = self.admin_flavors_client.list_flavor_extra_specs(
85 self.flavor_ref)['extra_specs']
86 if extra_spec_keys:
87 self.admin_flavors_client.set_flavor_extra_spec(
88 flavor['id'], **extra_spec_keys)
89
Matt Riedemann98c32b72016-04-18 19:34:47 -040090 # Now boot a server with the copied flavor.
91 server = self.create_test_server(
92 wait_until='ACTIVE', flavor=flavor['id'])
93
94 # Delete the flavor we used to boot the instance.
95 self._flavor_clean_up(flavor['id'])
96
97 # Now resize the server and wait for it to go into verify state.
98 self.servers_client.resize_server(server['id'], self.flavor_ref_alt)
99 waiters.wait_for_server_status(self.servers_client, server['id'],
100 'VERIFY_RESIZE')
101
102 # Now revert the resize, it should be OK even though the original
103 # flavor used to boot the server was deleted.
104 self.servers_client.revert_resize_server(server['id'])
105 waiters.wait_for_server_status(self.servers_client, server['id'],
106 'ACTIVE')
107
108 server = self.servers_client.show_server(server['id'])['server']
zhuflbcb71172018-03-29 13:49:31 +0800109 self.assert_flavor_equal(flavor['id'], server['flavor'])
Ludovic Beliveauae314882016-09-15 13:34:14 -0400110
Ludovic Beliveau20c03bc2016-09-15 14:25:58 -0400111 def _test_cold_migrate_server(self, revert=False):
Ludovic Beliveauae314882016-09-15 13:34:14 -0400112 if CONF.compute.min_compute_nodes < 2:
113 msg = "Less than 2 compute nodes, skipping multinode tests."
114 raise self.skipException(msg)
115
116 server = self.create_test_server(wait_until="ACTIVE")
zhufl7bc916d2018-08-22 14:47:39 +0800117 src_host = self.get_host_for_server(server['id'])
Ludovic Beliveauae314882016-09-15 13:34:14 -0400118
119 self.admin_servers_client.migrate_server(server['id'])
120
121 waiters.wait_for_server_status(self.servers_client,
122 server['id'], 'VERIFY_RESIZE')
123
Ludovic Beliveau20c03bc2016-09-15 14:25:58 -0400124 if revert:
125 self.servers_client.revert_resize_server(server['id'])
126 assert_func = self.assertEqual
127 else:
128 self.servers_client.confirm_resize_server(server['id'])
129 assert_func = self.assertNotEqual
130
Ludovic Beliveauae314882016-09-15 13:34:14 -0400131 waiters.wait_for_server_status(self.servers_client,
132 server['id'], 'ACTIVE')
zhufl7bc916d2018-08-22 14:47:39 +0800133 dst_host = self.get_host_for_server(server['id'])
Ludovic Beliveau20c03bc2016-09-15 14:25:58 -0400134 assert_func(src_host, dst_host)
Ludovic Beliveauae314882016-09-15 13:34:14 -0400135
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800136 @decorators.idempotent_id('4bf0be52-3b6f-4746-9a27-3143636fe30d')
Ludovic Beliveau20c03bc2016-09-15 14:25:58 -0400137 @testtools.skipUnless(CONF.compute_feature_enabled.cold_migration,
138 'Cold migration not available.')
139 def test_cold_migration(self):
140 self._test_cold_migrate_server(revert=False)
141
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800142 @decorators.idempotent_id('caa1aa8b-f4ef-4374-be0d-95f001c2ac2d')
Ludovic Beliveau20c03bc2016-09-15 14:25:58 -0400143 @testtools.skipUnless(CONF.compute_feature_enabled.cold_migration,
144 'Cold migration not available.')
145 def test_revert_cold_migration(self):
146 self._test_cold_migrate_server(revert=True)