blob: 2e69579be10c75cdf4c339082feedd52ba94146e [file] [log] [blame]
Matthew Treinishce3ef922013-03-11 14:02:46 -04001# Copyright 2013 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Attila Fazekasa709b762013-10-08 11:52:44 +020015import cStringIO as StringIO
16
Matthew Treinishce3ef922013-03-11 14:02:46 -040017from tempest import clients
Matthew Treinishb86cda92013-07-29 11:22:23 -040018from tempest.common import isolated_creds
Attila Fazekas689e2652013-10-07 18:06:57 +020019from tempest.common.utils import data_utils
Matthew Treinishce3ef922013-03-11 14:02:46 -040020from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040021from tempest.openstack.common import log as logging
Matthew Treinishce3ef922013-03-11 14:02:46 -040022import tempest.test
23
24LOG = logging.getLogger(__name__)
25
26
27class BaseImageTest(tempest.test.BaseTestCase):
28 """Base test class for Image API tests."""
29
30 @classmethod
31 def setUpClass(cls):
Sylvain Afchain11b99d02014-01-16 00:42:33 +010032 cls.set_network_resources()
Attila Fazekasf86fa312013-07-30 19:56:39 +020033 super(BaseImageTest, cls).setUpClass()
Matthew Treinishce3ef922013-03-11 14:02:46 -040034 cls.created_images = []
Matthew Treinishe09b3c22013-07-23 16:49:36 -040035 cls._interface = 'json'
Matthew Treinish9f756a02014-01-15 10:26:07 -050036 cls.isolated_creds = isolated_creds.IsolatedCreds(
37 cls.__name__, network_resources=cls.network_resources)
Matthew Treinish853ae442013-07-19 16:36:07 -040038 if not cls.config.service_available.glance:
39 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
40 raise cls.skipException(skip_msg)
Matthew Treinishe09b3c22013-07-23 16:49:36 -040041 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040042 creds = cls.isolated_creds.get_primary_creds()
Matthew Treinishe09b3c22013-07-23 16:49:36 -040043 username, tenant_name, password = creds
44 cls.os = clients.Manager(username=username,
45 password=password,
46 tenant_name=tenant_name)
47 else:
48 cls.os = clients.Manager()
Matthew Treinishce3ef922013-03-11 14:02:46 -040049
50 @classmethod
51 def tearDownClass(cls):
52 for image_id in cls.created_images:
53 try:
54 cls.client.delete_image(image_id)
55 except exceptions.NotFound:
56 pass
57
58 for image_id in cls.created_images:
59 cls.client.wait_for_resource_deletion(image_id)
Matthew Treinishb86cda92013-07-29 11:22:23 -040060 cls.isolated_creds.clear_isolated_creds()
61 super(BaseImageTest, cls).tearDownClass()
Matthew Treinishce3ef922013-03-11 14:02:46 -040062
63 @classmethod
64 def create_image(cls, **kwargs):
65 """Wrapper that returns a test image."""
Attila Fazekas689e2652013-10-07 18:06:57 +020066 name = data_utils.rand_name(cls.__name__ + "-instance")
Matthew Treinishce3ef922013-03-11 14:02:46 -040067
68 if 'name' in kwargs:
69 name = kwargs.pop('name')
70
71 container_format = kwargs.pop('container_format')
72 disk_format = kwargs.pop('disk_format')
73
74 resp, image = cls.client.create_image(name, container_format,
75 disk_format, **kwargs)
76 cls.created_images.append(image['id'])
77 return resp, image
78
79
80class BaseV1ImageTest(BaseImageTest):
81
82 @classmethod
83 def setUpClass(cls):
84 super(BaseV1ImageTest, cls).setUpClass()
85 cls.client = cls.os.image_client
Matthew Treinish2b5287d2013-10-22 17:40:34 +000086 if not cls.config.image_feature_enabled.api_v1:
Matthew Treinishc0f768f2013-03-11 14:24:16 -040087 msg = "Glance API v1 not supported"
88 raise cls.skipException(msg)
Matthew Treinishce3ef922013-03-11 14:02:46 -040089
90
Attila Fazekasa709b762013-10-08 11:52:44 +020091class BaseV1ImageMembersTest(BaseV1ImageTest):
92 @classmethod
93 def setUpClass(cls):
94 super(BaseV1ImageMembersTest, cls).setUpClass()
95 if cls.config.compute.allow_tenant_isolation:
96 creds = cls.isolated_creds.get_alt_creds()
97 username, tenant_name, password = creds
98 cls.os_alt = clients.Manager(username=username,
99 password=password,
100 tenant_name=tenant_name)
101 cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
102 else:
103 cls.os_alt = clients.AltManager()
104 identity_client = cls._get_identity_admin_client()
105 cls.alt_tenant_id = identity_client.get_tenant_by_name(
106 cls.os_alt.tenant_name)['id']
107
108 cls.alt_img_cli = cls.os_alt.image_client
109
110 def _create_image(self):
111 image_file = StringIO.StringIO('*' * 1024)
112 resp, image = self.create_image(container_format='bare',
113 disk_format='raw',
114 is_public=False,
115 data=image_file)
116 self.assertEqual(201, resp.status)
117 image_id = image['id']
118 return image_id
119
120
Matthew Treinishce3ef922013-03-11 14:02:46 -0400121class BaseV2ImageTest(BaseImageTest):
122
123 @classmethod
124 def setUpClass(cls):
125 super(BaseV2ImageTest, cls).setUpClass()
126 cls.client = cls.os.image_client_v2
Matthew Treinish2b5287d2013-10-22 17:40:34 +0000127 if not cls.config.image_feature_enabled.api_v2:
Matthew Treinishc0f768f2013-03-11 14:24:16 -0400128 msg = "Glance API v2 not supported"
129 raise cls.skipException(msg)
Attila Fazekas689e2652013-10-07 18:06:57 +0200130
131
JordanP236da422014-01-16 14:38:07 +0000132class BaseV2MemberImageTest(BaseV2ImageTest):
Attila Fazekas689e2652013-10-07 18:06:57 +0200133
134 @classmethod
135 def setUpClass(cls):
JordanP236da422014-01-16 14:38:07 +0000136 super(BaseV2MemberImageTest, cls).setUpClass()
Attila Fazekas689e2652013-10-07 18:06:57 +0200137 if cls.config.compute.allow_tenant_isolation:
138 creds = cls.isolated_creds.get_alt_creds()
139 username, tenant_name, password = creds
140 cls.os_alt = clients.Manager(username=username,
141 password=password,
142 tenant_name=tenant_name,
143 interface=cls._interface)
144 cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
145 else:
146 cls.os_alt = clients.AltManager()
147 alt_tenant_name = cls.os_alt.tenant_name
148 identity_client = cls._get_identity_admin_client()
149 cls.alt_tenant_id = identity_client.get_tenant_by_name(
150 alt_tenant_name)['id']
151 cls.os_img_client = cls.os.image_client_v2
152 cls.alt_img_client = cls.os_alt.image_client_v2
153
154 def _list_image_ids_as_alt(self):
155 _, image_list = self.alt_img_client.image_list()
156 image_ids = map(lambda x: x['id'], image_list)
157 return image_ids
158
159 def _create_image(self):
160 name = data_utils.rand_name('image')
161 resp, image = self.os_img_client.create_image(name,
162 container_format='bare',
163 disk_format='raw')
164 image_id = image['id']
165 self.addCleanup(self.os_img_client.delete_image, image_id)
166 return image_id