File: test_create_from_image.py

package info (click to toggle)
cinder-tempest-plugin 1.19.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 460 kB
  • sloc: python: 3,281; makefile: 22
file content (76 lines) | stat: -rw-r--r-- 3,315 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest import config
from tempest.lib import decorators

from cinder_tempest_plugin.api.volume import base

CONF = config.CONF


class VolumeAndVolumeTypeFromImageTest(base.BaseVolumeAdminTest):
    # needs AdminTest as superclass to manipulate volume_types

    @classmethod
    def skip_checks(cls):
        super(VolumeAndVolumeTypeFromImageTest, cls).skip_checks()
        if not CONF.service_available.glance:
            raise cls.skipException("Glance service is disabled")

    @decorators.idempotent_id('6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6')
    def test_create_from_image_with_volume_type_image_property(self):
        """Verify that the cinder_img_volume_type image property works.

        When a volume is created from an image containing the
        cinder_img_volume_type property and no volume_type is specified
        in the volume-create request, the volume_type of the resulting
        volume should be the one specified by the image property.
        """

        volume_type_meta = 'cinder_img_volume_type'
        volume_type_name = 'vol-type-for-6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6'
        description = ('Generic volume_type for test '
                       '6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6')
        proto = CONF.volume.storage_protocol
        vendor = CONF.volume.vendor_name
        extra_specs = {"storage_protocol": proto,
                       "vendor_name": vendor}
        kwargs = {'description': description,
                  'extra_specs': extra_specs,
                  'os-volume-type-access:is_public': True}
        volume_type = self.create_volume_type(name=volume_type_name,
                                              **kwargs)
        # quick sanity check
        self.assertEqual(volume_type_name, volume_type['name'])

        # create an image in glance
        kwargs = {'disk_format': 'raw',
                  'container_format': 'bare',
                  'name': ('image-for-test-'
                           '6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6'),
                  'visibility': 'private',
                  volume_type_meta: volume_type_name}
        image = self.create_image_with_data(**kwargs)
        # quick sanity check
        self.assertEqual(volume_type_name, image[volume_type_meta])

        # create volume from image
        kwargs = {'name': ('volume-for-test-'
                           '6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6'),
                  'imageRef': image['id']}
        # this is the whole point of the test, so make sure this is true
        self.assertNotIn('volume_type', kwargs)
        volume = self.create_volume(**kwargs)

        found_volume_type = volume['volume_type']
        self.assertEqual(volume_type_name, found_volume_type)