scottda | 61f68ac | 2016-06-07 12:07:55 -0600 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | from oslo_log import log as logging |
| 14 | |
| 15 | from tempest.common import waiters |
| 16 | from tempest import config |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 17 | from tempest.lib import decorators |
scottda | 61f68ac | 2016-06-07 12:07:55 -0600 | [diff] [blame] | 18 | from tempest.scenario import manager |
| 19 | from tempest import test |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | LOG = logging.getLogger(__name__) |
| 23 | |
| 24 | |
| 25 | class TestVolumeMigrateRetypeAttached(manager.ScenarioTest): |
| 26 | |
| 27 | """This test case attempts to reproduce the following steps: |
| 28 | |
| 29 | * Create 2 volume types representing 2 different backends |
| 30 | * Create in Cinder some bootable volume importing a Glance image using |
| 31 | * volume_type_1 |
| 32 | * Boot an instance from the bootable volume |
| 33 | * Write to the volume |
| 34 | * Perform a cinder retype --on-demand of the volume to type of backend #2 |
| 35 | * Check written content of migrated volume |
| 36 | """ |
| 37 | |
| 38 | credentials = ['primary', 'admin'] |
| 39 | |
| 40 | @classmethod |
| 41 | def setup_clients(cls): |
| 42 | super(TestVolumeMigrateRetypeAttached, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 43 | cls.admin_volume_types_client = cls.os_admin.volume_types_v2_client |
scottda | 61f68ac | 2016-06-07 12:07:55 -0600 | [diff] [blame] | 44 | |
| 45 | @classmethod |
| 46 | def skip_checks(cls): |
| 47 | super(TestVolumeMigrateRetypeAttached, cls).skip_checks() |
| 48 | if not CONF.volume_feature_enabled.multi_backend: |
| 49 | raise cls.skipException("Cinder multi-backend feature disabled") |
| 50 | |
| 51 | if len(set(CONF.volume.backend_names)) < 2: |
| 52 | raise cls.skipException("Requires at least two different " |
| 53 | "backend names") |
| 54 | |
| 55 | def _boot_instance_from_volume(self, vol_id, keypair, security_group): |
| 56 | |
| 57 | key_name = keypair['name'] |
| 58 | security_groups = [{'name': security_group['name']}] |
| 59 | block_device_mapping = [{'device_name': 'vda', 'volume_id': vol_id, |
| 60 | 'delete_on_termination': False}] |
| 61 | |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 62 | return self.create_server(image_id='', |
scottda | 61f68ac | 2016-06-07 12:07:55 -0600 | [diff] [blame] | 63 | key_name=key_name, |
| 64 | security_groups=security_groups, |
| 65 | block_device_mapping=block_device_mapping) |
| 66 | |
| 67 | def _create_volume_types(self): |
| 68 | backend_names = CONF.volume.backend_names |
| 69 | |
| 70 | backend_source = backend_names[0] |
| 71 | backend_dest = backend_names[1] |
| 72 | |
| 73 | source_body = self.create_volume_type(backend_name=backend_source) |
| 74 | dest_body = self.create_volume_type(backend_name=backend_dest) |
| 75 | |
| 76 | LOG.info("Created Volume types: %(src)s -> %(src_backend)s, %(dst)s " |
| 77 | "-> %(dst_backend)s", {'src': source_body['name'], |
| 78 | 'src_backend': backend_source, |
| 79 | 'dst': dest_body['name'], |
| 80 | 'dst_backend': backend_dest}) |
| 81 | return source_body['name'], dest_body['name'] |
| 82 | |
| 83 | def _volume_retype_with_migration(self, volume_id, new_volume_type): |
| 84 | migration_policy = 'on-demand' |
| 85 | self.volumes_client.retype_volume( |
| 86 | volume_id, new_type=new_volume_type, |
| 87 | migration_policy=migration_policy) |
| 88 | waiters.wait_for_volume_retype(self.volumes_client, |
| 89 | volume_id, new_volume_type) |
| 90 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 91 | @decorators.attr(type='slow') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 92 | @decorators.idempotent_id('deadd2c2-beef-4dce-98be-f86765ff311b') |
scottda | 61f68ac | 2016-06-07 12:07:55 -0600 | [diff] [blame] | 93 | @test.services('compute', 'volume') |
| 94 | def test_volume_migrate_attached(self): |
| 95 | LOG.info("Creating keypair and security group") |
| 96 | keypair = self.create_keypair() |
| 97 | security_group = self._create_security_group() |
| 98 | |
| 99 | # create volume types |
| 100 | LOG.info("Creating Volume types") |
| 101 | source_type, dest_type = self._create_volume_types() |
| 102 | |
| 103 | # create an instance from volume |
| 104 | LOG.info("Booting instance from volume") |
| 105 | volume_origin = self.create_volume(imageRef=CONF.compute.image_ref, |
| 106 | volume_type=source_type) |
| 107 | |
| 108 | instance = self._boot_instance_from_volume(volume_origin['id'], |
| 109 | keypair, security_group) |
| 110 | |
| 111 | # write content to volume on instance |
| 112 | LOG.info("Setting timestamp in instance %s", instance['id']) |
| 113 | ip_instance = self.get_server_ip(instance) |
| 114 | timestamp = self.create_timestamp(ip_instance, |
| 115 | private_key=keypair['private_key']) |
| 116 | |
| 117 | # retype volume with migration from backend #1 to backend #2 |
| 118 | LOG.info("Retyping Volume %s to new type %s", volume_origin['id'], |
| 119 | dest_type) |
| 120 | self._volume_retype_with_migration(volume_origin['id'], dest_type) |
| 121 | |
| 122 | # check the content of written file |
| 123 | LOG.info("Getting timestamp in postmigrated instance %s", |
| 124 | instance['id']) |
| 125 | timestamp2 = self.get_timestamp(ip_instance, |
| 126 | private_key=keypair['private_key']) |
| 127 | self.assertEqual(timestamp, timestamp2) |