Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 1 | # 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 | |
| 15 | import testtools |
| 16 | |
| 17 | from tempest.api.compute import base |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 18 | from tempest.common import waiters |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 19 | from tempest import config |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 21 | from tempest.lib import decorators |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 22 | from tempest.lib import exceptions |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 23 | |
| 24 | CONF = config.CONF |
| 25 | |
| 26 | |
| 27 | class MigrationsAdminTest(base.BaseV2ComputeAdminTest): |
| 28 | |
| 29 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 30 | def setup_clients(cls): |
| 31 | super(MigrationsAdminTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 32 | cls.client = cls.os_admin.migrations_client |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 33 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 34 | @decorators.idempotent_id('75c0b83d-72a0-4cf8-a153-631e83e7d53f') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 35 | def test_list_migrations(self): |
| 36 | # Admin can get the migrations list |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 37 | self.client.list_migrations() |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 38 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 39 | @decorators.idempotent_id('1b512062-8093-438e-b47a-37d2f597cd64') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 40 | @testtools.skipUnless(CONF.compute_feature_enabled.resize, |
| 41 | 'Resize not available.') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 42 | def test_list_migrations_in_flavor_resize_situation(self): |
| 43 | # Admin can get the migrations list which contains the resized server |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 44 | server = self.create_test_server(wait_until="ACTIVE") |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 45 | server_id = server['id'] |
| 46 | |
zhufl | 3d018b0 | 2016-11-25 16:43:04 +0800 | [diff] [blame] | 47 | self.resize_server(server_id, self.flavor_ref_alt) |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 48 | |
ghanshyam | 8a59949 | 2015-08-24 15:55:59 +0900 | [diff] [blame] | 49 | body = self.client.list_migrations()['migrations'] |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 50 | |
| 51 | instance_uuids = [x['instance_uuid'] for x in body] |
| 52 | self.assertIn(server_id, instance_uuids) |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 53 | |
| 54 | def _flavor_clean_up(self, flavor_id): |
| 55 | try: |
zhufl | fec7c59 | 2017-03-01 17:38:13 +0800 | [diff] [blame] | 56 | self.admin_flavors_client.delete_flavor(flavor_id) |
| 57 | self.admin_flavors_client.wait_for_resource_deletion(flavor_id) |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 58 | except exceptions.NotFound: |
| 59 | pass |
| 60 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 61 | @decorators.idempotent_id('33f1fec3-ba18-4470-8e4e-1d888e7c3593') |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 62 | @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. |
zhufl | fec7c59 | 2017-03-01 17:38:13 +0800 | [diff] [blame] | 70 | flavor = self.admin_flavors_client.show_flavor( |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 71 | self.flavor_ref)['flavor'] |
zhufl | fec7c59 | 2017-03-01 17:38:13 +0800 | [diff] [blame] | 72 | flavor = self.admin_flavors_client.create_flavor( |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 73 | 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 | |
zhufl | c88e0a1 | 2017-12-28 11:30:01 +0800 | [diff] [blame] | 80 | # 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 Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 90 | # 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'] |
zhufl | bcb7117 | 2018-03-29 13:49:31 +0800 | [diff] [blame] | 109 | self.assert_flavor_equal(flavor['id'], server['flavor']) |
Ludovic Beliveau | ae31488 | 2016-09-15 13:34:14 -0400 | [diff] [blame] | 110 | |
Ludovic Beliveau | 20c03bc | 2016-09-15 14:25:58 -0400 | [diff] [blame] | 111 | def _test_cold_migrate_server(self, revert=False): |
Ludovic Beliveau | ae31488 | 2016-09-15 13:34:14 -0400 | [diff] [blame] | 112 | 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") |
zhufl | 7bc916d | 2018-08-22 14:47:39 +0800 | [diff] [blame] | 117 | src_host = self.get_host_for_server(server['id']) |
Ludovic Beliveau | ae31488 | 2016-09-15 13:34:14 -0400 | [diff] [blame] | 118 | |
| 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 Beliveau | 20c03bc | 2016-09-15 14:25:58 -0400 | [diff] [blame] | 124 | 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 Beliveau | ae31488 | 2016-09-15 13:34:14 -0400 | [diff] [blame] | 131 | waiters.wait_for_server_status(self.servers_client, |
| 132 | server['id'], 'ACTIVE') |
zhufl | 7bc916d | 2018-08-22 14:47:39 +0800 | [diff] [blame] | 133 | dst_host = self.get_host_for_server(server['id']) |
Ludovic Beliveau | 20c03bc | 2016-09-15 14:25:58 -0400 | [diff] [blame] | 134 | assert_func(src_host, dst_host) |
Ludovic Beliveau | ae31488 | 2016-09-15 13:34:14 -0400 | [diff] [blame] | 135 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 136 | @decorators.idempotent_id('4bf0be52-3b6f-4746-9a27-3143636fe30d') |
Ludovic Beliveau | 20c03bc | 2016-09-15 14:25:58 -0400 | [diff] [blame] | 137 | @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 Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 142 | @decorators.idempotent_id('caa1aa8b-f4ef-4374-be0d-95f001c2ac2d') |
Ludovic Beliveau | 20c03bc | 2016-09-15 14:25:58 -0400 | [diff] [blame] | 143 | @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) |