Codebase list cinder-tempest-plugin / a75d5e5
Add test for cinder_img_volume_type image metadata When a volume is created from an image with a cinder_img_volume_type image property, and a volume_type is not specified in the volume- create call, the resulting volume should be the specified volume_type, not the default type. Change-Id: If8edd24ba5183522ebe8202bbf6b62b41b3febe9 Brian Rosmaita 5 years ago
2 changed file(s) with 117 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
164164
165165 cls.admin_volume_types_client = cls.os_admin.volume_types_client_latest
166166 cls.admin_backups_client = cls.os_admin.backups_client_latest
167 cls.admin_volumes_client = cls.os_admin.volumes_client_latest
168
169 @classmethod
170 def create_volume_type(cls, name=None, **kwargs):
171 """Create a test volume-type"""
172
173 name = name or data_utils.rand_name(cls.__name__ + '-volume-type')
174 volume_type = cls.admin_volume_types_client.create_volume_type(
175 name=name, **kwargs)['volume_type']
176 cls.addClassResourceCleanup(cls._clear_volume_type, volume_type)
177 return volume_type
178
179 @classmethod
180 def _clear_volume_type(cls, volume_type):
181 # If image caching is enabled, we must delete the cached volume
182 # before cinder will allow us to delete the volume_type. This function
183 # solves that problem by taking the brute-force approach of deleting
184 # any volumes of this volume_type that exist *no matter what project
185 # they are in*. Since this won't happen until the teardown of the
186 # test class, that should be OK.
187 type_id = volume_type['id']
188 type_name = volume_type['name']
189
190 volumes = cls.admin_volumes_client.list_volumes(
191 detail=True, params={'all_tenants': 1})['volumes']
192 for volume in [v for v in volumes if v['volume_type'] == type_name]:
193 test_utils.call_and_ignore_notfound_exc(
194 cls.admin_volumes_client.delete_volume, volume['id'])
195 cls.admin_volumes_client.wait_for_resource_deletion(volume['id'])
196
197 test_utils.call_and_ignore_notfound_exc(
198 cls.admin_volume_types_client.delete_volume_type, type_id)
199 test_utils.call_and_ignore_notfound_exc(
200 cls.admin_volume_types_client.wait_for_resource_deletion, type_id)
88 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
99 # License for the specific language governing permissions and limitations
1010 # under the License.
11
12 import io
1113
1214 from tempest.common import waiters
1315 from tempest import config
7678 waiters.wait_for_volume_resource_status(self.volumes_client,
7779 v['id'],
7880 'available')
81
82
83 class VolumeAndVolumeTypeFromImageTest(base.BaseVolumeAdminTest):
84 # needs AdminTest as superclass to manipulate volume_types
85
86 @classmethod
87 def skip_checks(cls):
88 super(VolumeAndVolumeTypeFromImageTest, cls).skip_checks()
89 if not CONF.service_available.glance:
90 raise cls.skipException("Glance service is disabled")
91
92 @classmethod
93 def create_image_with_data(cls, **kwargs):
94 # we do this as a class method so we can use the
95 # addClassResourceCleanup functionality of tempest.test.BaseTestCase
96 images_client = cls.os_primary.image_client_v2
97 if 'min_disk' not in kwargs:
98 kwargs['min_disk'] = 1
99 response = images_client.create_image(**kwargs)
100 image_id = response['id']
101 cls.addClassResourceCleanup(
102 images_client.wait_for_resource_deletion, image_id)
103 cls.addClassResourceCleanup(
104 test_utils.call_and_ignore_notfound_exc,
105 images_client.delete_image, image_id)
106
107 # upload "data" to image
108 image_file = io.BytesIO(data_utils.random_bytes(size=1024))
109 images_client.store_image_file(image_id, image_file)
110
111 waiters.wait_for_image_status(images_client, image_id, 'active')
112 image = images_client.show_image(image_id)
113 return image
114
115 @decorators.idempotent_id('6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6')
116 def test_create_from_image_with_volume_type_image_property(self):
117 """Verify that the cinder_img_volume_type image property works.
118
119 When a volume is created from an image containing the
120 cinder_img_volume_type property and no volume_type is specified
121 in the volume-create request, the volume_type of the resulting
122 volume should be the one specified by the image property.
123 """
124
125 volume_type_meta = 'cinder_img_volume_type'
126 volume_type_name = 'vol-type-for-6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6'
127 description = ('Generic volume_type for test '
128 '6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6')
129 proto = CONF.volume.storage_protocol
130 vendor = CONF.volume.vendor_name
131 extra_specs = {"storage_protocol": proto,
132 "vendor_name": vendor}
133 kwargs = {'description': description,
134 'extra_specs': extra_specs,
135 'os-volume-type-access:is_public': True}
136 volume_type = self.create_volume_type(name=volume_type_name,
137 **kwargs)
138 # quick sanity check
139 self.assertEqual(volume_type_name, volume_type['name'])
140
141 # create an image in glance
142 kwargs = {'disk_format': 'raw',
143 'container_format': 'bare',
144 'name': ('image-for-test-'
145 '6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6'),
146 'visibility': 'private',
147 volume_type_meta: volume_type_name}
148 image = self.create_image_with_data(**kwargs)
149 # quick sanity check
150 self.assertEqual(volume_type_name, image[volume_type_meta])
151
152 # create volume from image
153 kwargs = {'name': ('volume-for-test-'
154 '6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6'),
155 'imageRef': image['id']}
156 # this is the whole point of the test, so make sure this is true
157 self.assertNotIn('volume_type', kwargs)
158 volume = self.create_volume(**kwargs)
159
160 found_volume_type = volume['volume_type']
161 self.assertEqual(volume_type_name, found_volume_type)