Merge "Test creating multiple volumes from image simultaneously"
Zuul authored 7 years ago
Gerrit Code Review committed 7 years ago
| 0 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | |
| 1 | # not use this file except in compliance with the License. You may obtain | |
| 2 | # a copy of the License at | |
| 3 | # | |
| 4 | # http://www.apache.org/licenses/LICENSE-2.0 | |
| 5 | # | |
| 6 | # Unless required by applicable law or agreed to in writing, software | |
| 7 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
| 8 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
| 9 | # License for the specific language governing permissions and limitations | |
| 10 | # under the License. | |
| 11 | ||
| 12 | from tempest.common import waiters | |
| 13 | from tempest import config | |
| 14 | from tempest.lib.common.utils import data_utils | |
| 15 | from tempest.lib.common.utils import test_utils | |
| 16 | from tempest.lib import decorators | |
| 17 | ||
| 18 | from cinder_tempest_plugin.api.volume import base | |
| 19 | ||
| 20 | CONF = config.CONF | |
| 21 | ||
| 22 | ||
| 23 | class VolumeFromImageTest(base.BaseVolumeTest): | |
| 24 | ||
| 25 | @classmethod | |
| 26 | def skip_checks(cls): | |
| 27 | super(VolumeFromImageTest, cls).skip_checks() | |
| 28 | ||
| 29 | @classmethod | |
| 30 | def create_volume_no_wait(cls, **kwargs): | |
| 31 | """Returns a test volume. | |
| 32 | ||
| 33 | This does not wait for volume creation to finish, | |
| 34 | so that multiple operations can happen on the | |
| 35 | Cinder server in parallel. | |
| 36 | """ | |
| 37 | if 'size' not in kwargs: | |
| 38 | kwargs['size'] = CONF.volume.volume_size | |
| 39 | ||
| 40 | if 'imageRef' in kwargs: | |
| 41 | image = cls.os_primary.image_client_v2.show_image( | |
| 42 | kwargs['imageRef']) | |
| 43 | min_disk = image['min_disk'] | |
| 44 | kwargs['size'] = max(kwargs['size'], min_disk) | |
| 45 | ||
| 46 | if 'name' not in kwargs: | |
| 47 | name = data_utils.rand_name(cls.__name__ + '-Volume') | |
| 48 | kwargs['name'] = name | |
| 49 | ||
| 50 | volume = cls.volumes_client.create_volume(**kwargs)['volume'] | |
| 51 | cls.addClassResourceCleanup( | |
| 52 | cls.volumes_client.wait_for_resource_deletion, volume['id']) | |
| 53 | cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc, | |
| 54 | cls.volumes_client.delete_volume, | |
| 55 | volume['id']) | |
| 56 | ||
| 57 | return volume | |
| 58 | ||
| 59 | @decorators.idempotent_id('8976a11b-1ddc-49b6-b66f-8c26adf3fa9e') | |
| 60 | def test_create_from_image_multiple(self): | |
| 61 | """Create a handful of volumes from the same image at once. | |
| 62 | ||
| 63 | The purpose of this test is to stress volume drivers, | |
| 64 | image download, the image cache, etc., within Cinder. | |
| 65 | """ | |
| 66 | ||
| 67 | img_uuid = CONF.compute.image_ref | |
| 68 | ||
| 69 | vols = [] | |
| 70 | for v in range(0, 5): | |
| 71 | vols.append(self.create_volume_no_wait(imageRef=img_uuid)) | |
| 72 | ||
| 73 | for v in vols: | |
| 74 | waiters.wait_for_volume_resource_status(self.volumes_client, | |
| 75 | v['id'], | |
| 76 | 'available') |