blob: 891e22db1287dce6e52da1b75a0f33e5e0b788cc [file] [log] [blame]
scottda61f68ac2016-06-07 12:07:55 -06001# 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
13from oslo_log import log as logging
14
15from tempest.common import waiters
16from tempest import config
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080017from tempest.lib import decorators
scottda61f68ac2016-06-07 12:07:55 -060018from tempest.scenario import manager
19from tempest import test
20
21CONF = config.CONF
22LOG = logging.getLogger(__name__)
23
24
25class 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()
43 if CONF.volume_feature_enabled.api_v1:
44 cls.admin_volume_types_client = cls.os_adm.volume_types_client
45 else:
46 cls.admin_volume_types_client = cls.os_adm.volume_types_v2_client
47
48 @classmethod
49 def skip_checks(cls):
50 super(TestVolumeMigrateRetypeAttached, cls).skip_checks()
51 if not CONF.volume_feature_enabled.multi_backend:
52 raise cls.skipException("Cinder multi-backend feature disabled")
53
54 if len(set(CONF.volume.backend_names)) < 2:
55 raise cls.skipException("Requires at least two different "
56 "backend names")
57
58 def _boot_instance_from_volume(self, vol_id, keypair, security_group):
59
60 key_name = keypair['name']
61 security_groups = [{'name': security_group['name']}]
62 block_device_mapping = [{'device_name': 'vda', 'volume_id': vol_id,
63 'delete_on_termination': False}]
64
zhufl13c9c892017-02-10 12:04:07 +080065 return self.create_server(image_id='',
scottda61f68ac2016-06-07 12:07:55 -060066 key_name=key_name,
67 security_groups=security_groups,
68 block_device_mapping=block_device_mapping)
69
70 def _create_volume_types(self):
71 backend_names = CONF.volume.backend_names
72
73 backend_source = backend_names[0]
74 backend_dest = backend_names[1]
75
76 source_body = self.create_volume_type(backend_name=backend_source)
77 dest_body = self.create_volume_type(backend_name=backend_dest)
78
79 LOG.info("Created Volume types: %(src)s -> %(src_backend)s, %(dst)s "
80 "-> %(dst_backend)s", {'src': source_body['name'],
81 'src_backend': backend_source,
82 'dst': dest_body['name'],
83 'dst_backend': backend_dest})
84 return source_body['name'], dest_body['name']
85
86 def _volume_retype_with_migration(self, volume_id, new_volume_type):
87 migration_policy = 'on-demand'
88 self.volumes_client.retype_volume(
89 volume_id, new_type=new_volume_type,
90 migration_policy=migration_policy)
91 waiters.wait_for_volume_retype(self.volumes_client,
92 volume_id, new_volume_type)
93
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080094 @decorators.idempotent_id('deadd2c2-beef-4dce-98be-f86765ff311b')
scottda61f68ac2016-06-07 12:07:55 -060095 @test.services('compute', 'volume')
96 def test_volume_migrate_attached(self):
97 LOG.info("Creating keypair and security group")
98 keypair = self.create_keypair()
99 security_group = self._create_security_group()
100
101 # create volume types
102 LOG.info("Creating Volume types")
103 source_type, dest_type = self._create_volume_types()
104
105 # create an instance from volume
106 LOG.info("Booting instance from volume")
107 volume_origin = self.create_volume(imageRef=CONF.compute.image_ref,
108 volume_type=source_type)
109
110 instance = self._boot_instance_from_volume(volume_origin['id'],
111 keypair, security_group)
112
113 # write content to volume on instance
114 LOG.info("Setting timestamp in instance %s", instance['id'])
115 ip_instance = self.get_server_ip(instance)
116 timestamp = self.create_timestamp(ip_instance,
117 private_key=keypair['private_key'])
118
119 # retype volume with migration from backend #1 to backend #2
120 LOG.info("Retyping Volume %s to new type %s", volume_origin['id'],
121 dest_type)
122 self._volume_retype_with_migration(volume_origin['id'], dest_type)
123
124 # check the content of written file
125 LOG.info("Getting timestamp in postmigrated instance %s",
126 instance['id'])
127 timestamp2 = self.get_timestamp(ip_instance,
128 private_key=keypair['private_key'])
129 self.assertEqual(timestamp, timestamp2)