Codebase list cinder-tempest-plugin / 5a5e1bf
Move create_image_with_data to BaseVolumeTest Move this code to a base class so it can be used in more tests. Change-Id: If8bd605ec75c8ddf8a85bff4e32ceb435aa35b85 Eric Harney 2 years ago
2 changed file(s) with 25 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
1212 # License for the specific language governing permissions and limitations
1313 # under the License.
1414
15 import io
16
1517 from tempest.common import compute
1618 from tempest.common import waiters
1719 from tempest import config
156158 self.os_primary.servers_client.delete_server,
157159 body['id'])
158160 return body
161
162 @classmethod
163 def create_image_with_data(cls, **kwargs):
164 # we do this as a class method so we can use the
165 # addClassResourceCleanup functionality of tempest.test.BaseTestCase
166 images_client = cls.os_primary.image_client_v2
167 if 'min_disk' not in kwargs:
168 kwargs['min_disk'] = 1
169 response = images_client.create_image(**kwargs)
170 image_id = response['id']
171 cls.addClassResourceCleanup(
172 images_client.wait_for_resource_deletion, image_id)
173 cls.addClassResourceCleanup(
174 test_utils.call_and_ignore_notfound_exc,
175 images_client.delete_image, image_id)
176
177 # upload "data" to image
178 image_file = io.BytesIO(data_utils.random_bytes(size=1024))
179 images_client.store_image_file(image_id, image_file)
180
181 waiters.wait_for_image_status(images_client, image_id, 'active')
182 image = images_client.show_image(image_id)
183 return image
159184
160185
161186 class BaseVolumeAdminTest(BaseVolumeTest):
99 # License for the specific language governing permissions and limitations
1010 # under the License.
1111
12 import io
13
14 from tempest.common import waiters
1512 from tempest import config
16 from tempest.lib.common.utils import data_utils
17 from tempest.lib.common.utils import test_utils
1813 from tempest.lib import decorators
1914
2015 from cinder_tempest_plugin.api.volume import base
3025 super(VolumeAndVolumeTypeFromImageTest, cls).skip_checks()
3126 if not CONF.service_available.glance:
3227 raise cls.skipException("Glance service is disabled")
33
34 @classmethod
35 def create_image_with_data(cls, **kwargs):
36 # we do this as a class method so we can use the
37 # addClassResourceCleanup functionality of tempest.test.BaseTestCase
38 images_client = cls.os_primary.image_client_v2
39 if 'min_disk' not in kwargs:
40 kwargs['min_disk'] = 1
41 response = images_client.create_image(**kwargs)
42 image_id = response['id']
43 cls.addClassResourceCleanup(
44 images_client.wait_for_resource_deletion, image_id)
45 cls.addClassResourceCleanup(
46 test_utils.call_and_ignore_notfound_exc,
47 images_client.delete_image, image_id)
48
49 # upload "data" to image
50 image_file = io.BytesIO(data_utils.random_bytes(size=1024))
51 images_client.store_image_file(image_id, image_file)
52
53 waiters.wait_for_image_status(images_client, image_id, 'active')
54 image = images_client.show_image(image_id)
55 return image
5628
5729 @decorators.idempotent_id('6e9266ff-a917-4dd5-aa4a-c36e59e7a2a6')
5830 def test_create_from_image_with_volume_type_image_property(self):