| 8 | 8 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 9 | 9 |
# License for the specific language governing permissions and limitations
|
| 10 | 10 |
# under the License.
|
|
11 |
|
|
12 |
import io
|
| 11 | 13 |
|
| 12 | 14 |
from tempest.common import waiters
|
| 13 | 15 |
from tempest import config
|
|
| 76 | 78 |
waiters.wait_for_volume_resource_status(self.volumes_client,
|
| 77 | 79 |
v['id'],
|
| 78 | 80 |
'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)
|