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 |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 18 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 19 | from tempest.common import waiters |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 20 | from tempest import config |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 21 | from tempest.lib import exceptions |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 22 | from tempest import test |
| 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() |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 32 | cls.client = cls.os_adm.migrations_client |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 33 | cls.flavors_admin_client = cls.os_adm.flavors_client |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 34 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 35 | @test.idempotent_id('75c0b83d-72a0-4cf8-a153-631e83e7d53f') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 36 | def test_list_migrations(self): |
| 37 | # Admin can get the migrations list |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 38 | self.client.list_migrations() |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 39 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 40 | @test.idempotent_id('1b512062-8093-438e-b47a-37d2f597cd64') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 41 | @testtools.skipUnless(CONF.compute_feature_enabled.resize, |
| 42 | 'Resize not available.') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 43 | def test_list_migrations_in_flavor_resize_situation(self): |
| 44 | # Admin can get the migrations list which contains the resized server |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 45 | server = self.create_test_server(wait_until="ACTIVE") |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 46 | server_id = server['id'] |
| 47 | |
Ken'ichi Ohmichi | 5271b0f | 2015-08-10 07:53:27 +0000 | [diff] [blame] | 48 | self.servers_client.resize_server(server_id, self.flavor_ref_alt) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 49 | waiters.wait_for_server_status(self.servers_client, |
| 50 | server_id, 'VERIFY_RESIZE') |
Ken'ichi Ohmichi | b263108 | 2015-08-27 01:31:00 +0000 | [diff] [blame] | 51 | self.servers_client.confirm_resize_server(server_id) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 52 | waiters.wait_for_server_status(self.servers_client, |
| 53 | server_id, 'ACTIVE') |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 54 | |
ghanshyam | 8a59949 | 2015-08-24 15:55:59 +0900 | [diff] [blame] | 55 | body = self.client.list_migrations()['migrations'] |
Ken'ichi Ohmichi | 2fdc182 | 2014-03-18 09:10:57 +0900 | [diff] [blame] | 56 | |
| 57 | instance_uuids = [x['instance_uuid'] for x in body] |
| 58 | self.assertIn(server_id, instance_uuids) |
Matt Riedemann | 98c32b7 | 2016-04-18 19:34:47 -0400 | [diff] [blame] | 59 | |
| 60 | def _flavor_clean_up(self, flavor_id): |
| 61 | try: |
| 62 | self.flavors_admin_client.delete_flavor(flavor_id) |
| 63 | self.flavors_admin_client.wait_for_resource_deletion(flavor_id) |
| 64 | except exceptions.NotFound: |
| 65 | pass |
| 66 | |
| 67 | @test.idempotent_id('33f1fec3-ba18-4470-8e4e-1d888e7c3593') |
| 68 | @testtools.skipUnless(CONF.compute_feature_enabled.resize, |
| 69 | 'Resize not available.') |
| 70 | def test_resize_server_revert_deleted_flavor(self): |
| 71 | # Tests that we can revert the resize on an instance whose original |
| 72 | # flavor has been deleted. |
| 73 | |
| 74 | # First we have to create a flavor that we can delete so make a copy |
| 75 | # of the normal flavor from which we'd create a server. |
| 76 | flavor = self.flavors_admin_client.show_flavor( |
| 77 | self.flavor_ref)['flavor'] |
| 78 | flavor = self.flavors_admin_client.create_flavor( |
| 79 | name=data_utils.rand_name('test_resize_flavor_'), |
| 80 | ram=flavor['ram'], |
| 81 | disk=flavor['disk'], |
| 82 | vcpus=flavor['vcpus'] |
| 83 | )['flavor'] |
| 84 | self.addCleanup(self._flavor_clean_up, flavor['id']) |
| 85 | |
| 86 | # Now boot a server with the copied flavor. |
| 87 | server = self.create_test_server( |
| 88 | wait_until='ACTIVE', flavor=flavor['id']) |
| 89 | |
| 90 | # Delete the flavor we used to boot the instance. |
| 91 | self._flavor_clean_up(flavor['id']) |
| 92 | |
| 93 | # Now resize the server and wait for it to go into verify state. |
| 94 | self.servers_client.resize_server(server['id'], self.flavor_ref_alt) |
| 95 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 96 | 'VERIFY_RESIZE') |
| 97 | |
| 98 | # Now revert the resize, it should be OK even though the original |
| 99 | # flavor used to boot the server was deleted. |
| 100 | self.servers_client.revert_resize_server(server['id']) |
| 101 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 102 | 'ACTIVE') |
| 103 | |
| 104 | server = self.servers_client.show_server(server['id'])['server'] |
| 105 | self.assertEqual(flavor['id'], server['flavor']['id']) |