blob: 58d0003d9eef4376db4497c1b72fab7c96f4b4a7 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016
17from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090018from tempest_lib import exceptions as lib_exc
Attila Fazekasa709b762013-10-08 11:52:44 +020019
Matthew Treinishce3ef922013-03-11 14:02:46 -040020from tempest import clients
Cyril Roelandtc1482a22014-11-13 16:55:04 +010021from tempest.common import credentials
Matthew Treinish5ba84e32014-01-29 16:52:57 +000022from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040023from tempest.openstack.common import log as logging
Matthew Treinishce3ef922013-03-11 14:02:46 -040024import tempest.test
25
Matthew Treinish5ba84e32014-01-29 16:52:57 +000026CONF = config.CONF
27
Matthew Treinishce3ef922013-03-11 14:02:46 -040028LOG = logging.getLogger(__name__)
29
30
31class BaseImageTest(tempest.test.BaseTestCase):
32 """Base test class for Image API tests."""
33
34 @classmethod
Rohan Kanade3bbbed02015-02-05 18:18:28 +053035 def skip_checks(cls):
36 super(BaseImageTest, cls).skip_checks()
37 if not CONF.service_available.glance:
38 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
39 raise cls.skipException(skip_msg)
40
41 @classmethod
42 def setup_credentials(cls):
43 super(BaseImageTest, cls).setup_credentials()
44 cls.isolated_creds = credentials.get_isolated_credentials(
45 cls.__name__, network_resources=cls.network_resources)
46 cls.os = clients.Manager(cls.isolated_creds.get_primary_creds())
47
48 @classmethod
Andrea Frittoli69a6b632014-09-15 13:14:53 +010049 def resource_setup(cls):
Sylvain Afchain11b99d02014-01-16 00:42:33 +010050 cls.set_network_resources()
Andrea Frittoli69a6b632014-09-15 13:14:53 +010051 super(BaseImageTest, cls).resource_setup()
Matthew Treinishce3ef922013-03-11 14:02:46 -040052 cls.created_images = []
53
54 @classmethod
Andrea Frittoli69a6b632014-09-15 13:14:53 +010055 def resource_cleanup(cls):
Matthew Treinishce3ef922013-03-11 14:02:46 -040056 for image_id in cls.created_images:
57 try:
58 cls.client.delete_image(image_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090059 except lib_exc.NotFound:
Matthew Treinishce3ef922013-03-11 14:02:46 -040060 pass
61
62 for image_id in cls.created_images:
63 cls.client.wait_for_resource_deletion(image_id)
Matthew Treinishb86cda92013-07-29 11:22:23 -040064 cls.isolated_creds.clear_isolated_creds()
Andrea Frittoli69a6b632014-09-15 13:14:53 +010065 super(BaseImageTest, cls).resource_cleanup()
Matthew Treinishce3ef922013-03-11 14:02:46 -040066
67 @classmethod
68 def create_image(cls, **kwargs):
69 """Wrapper that returns a test image."""
Attila Fazekas689e2652013-10-07 18:06:57 +020070 name = data_utils.rand_name(cls.__name__ + "-instance")
Matthew Treinishce3ef922013-03-11 14:02:46 -040071
72 if 'name' in kwargs:
73 name = kwargs.pop('name')
74
75 container_format = kwargs.pop('container_format')
76 disk_format = kwargs.pop('disk_format')
77
David Kranz34f18782015-01-06 13:43:55 -050078 image = cls.client.create_image(name, container_format,
79 disk_format, **kwargs)
Matthew Treinishce3ef922013-03-11 14:02:46 -040080 cls.created_images.append(image['id'])
David Kranz34f18782015-01-06 13:43:55 -050081 return image
Matthew Treinishce3ef922013-03-11 14:02:46 -040082
83
84class BaseV1ImageTest(BaseImageTest):
85
86 @classmethod
Rohan Kanade3bbbed02015-02-05 18:18:28 +053087 def skip_checks(cls):
88 super(BaseV1ImageTest, cls).skip_checks()
Matthew Treinish5ba84e32014-01-29 16:52:57 +000089 if not CONF.image_feature_enabled.api_v1:
Matthew Treinishc0f768f2013-03-11 14:24:16 -040090 msg = "Glance API v1 not supported"
91 raise cls.skipException(msg)
Matthew Treinishce3ef922013-03-11 14:02:46 -040092
Rohan Kanade3bbbed02015-02-05 18:18:28 +053093 @classmethod
94 def setup_clients(cls):
95 super(BaseV1ImageTest, cls).setup_clients()
96 cls.client = cls.os.image_client
97
Matthew Treinishce3ef922013-03-11 14:02:46 -040098
Attila Fazekasa709b762013-10-08 11:52:44 +020099class BaseV1ImageMembersTest(BaseV1ImageTest):
Rohan Kanade3bbbed02015-02-05 18:18:28 +0530100
101 @classmethod
102 def setup_credentials(cls):
103 super(BaseV1ImageMembersTest, cls).setup_credentials()
104 cls.os_alt = clients.Manager(cls.isolated_creds.get_alt_creds())
105
106 @classmethod
107 def setup_clients(cls):
108 super(BaseV1ImageMembersTest, cls).setup_clients()
109 cls.alt_img_cli = cls.os_alt.image_client
110
Attila Fazekasa709b762013-10-08 11:52:44 +0200111 @classmethod
Andrea Frittoli69a6b632014-09-15 13:14:53 +0100112 def resource_setup(cls):
113 super(BaseV1ImageMembersTest, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +0000114 cls.alt_tenant_id = cls.alt_img_cli.tenant_id
Attila Fazekasa709b762013-10-08 11:52:44 +0200115
116 def _create_image(self):
Mark Washenberger5c3b6fe2014-07-29 13:40:34 -0700117 image_file = StringIO.StringIO(data_utils.random_bytes())
David Kranz34f18782015-01-06 13:43:55 -0500118 image = self.create_image(container_format='bare',
119 disk_format='raw',
120 is_public=False,
121 data=image_file)
Attila Fazekasa709b762013-10-08 11:52:44 +0200122 image_id = image['id']
123 return image_id
124
125
Matthew Treinishce3ef922013-03-11 14:02:46 -0400126class BaseV2ImageTest(BaseImageTest):
127
128 @classmethod
Rohan Kanade3bbbed02015-02-05 18:18:28 +0530129 def skip_checks(cls):
130 super(BaseV2ImageTest, cls).skip_checks()
Matthew Treinish5ba84e32014-01-29 16:52:57 +0000131 if not CONF.image_feature_enabled.api_v2:
Matthew Treinishc0f768f2013-03-11 14:24:16 -0400132 msg = "Glance API v2 not supported"
133 raise cls.skipException(msg)
Attila Fazekas689e2652013-10-07 18:06:57 +0200134
Rohan Kanade3bbbed02015-02-05 18:18:28 +0530135 @classmethod
136 def setup_clients(cls):
137 super(BaseV2ImageTest, cls).setup_clients()
138 cls.client = cls.os.image_client_v2
139
Attila Fazekas689e2652013-10-07 18:06:57 +0200140
JordanP236da422014-01-16 14:38:07 +0000141class BaseV2MemberImageTest(BaseV2ImageTest):
Attila Fazekas689e2652013-10-07 18:06:57 +0200142
143 @classmethod
Rohan Kanade3bbbed02015-02-05 18:18:28 +0530144 def setup_credentials(cls):
145 super(BaseV2MemberImageTest, cls).setup_credentials()
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100146 creds = cls.isolated_creds.get_alt_creds()
147 cls.os_alt = clients.Manager(creds)
Rohan Kanade3bbbed02015-02-05 18:18:28 +0530148
149 @classmethod
150 def setup_clients(cls):
151 super(BaseV2MemberImageTest, cls).setup_clients()
Attila Fazekas689e2652013-10-07 18:06:57 +0200152 cls.os_img_client = cls.os.image_client_v2
153 cls.alt_img_client = cls.os_alt.image_client_v2
Rohan Kanade3bbbed02015-02-05 18:18:28 +0530154
155 @classmethod
156 def resource_setup(cls):
157 super(BaseV2MemberImageTest, cls).resource_setup()
Zhi Kun Liud752c602014-05-16 13:25:28 +0800158 cls.alt_tenant_id = cls.alt_img_client.tenant_id
Attila Fazekas689e2652013-10-07 18:06:57 +0200159
160 def _list_image_ids_as_alt(self):
David Kranz34f18782015-01-06 13:43:55 -0500161 image_list = self.alt_img_client.image_list()
Attila Fazekas689e2652013-10-07 18:06:57 +0200162 image_ids = map(lambda x: x['id'], image_list)
163 return image_ids
164
165 def _create_image(self):
166 name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -0500167 image = self.os_img_client.create_image(name,
168 container_format='bare',
169 disk_format='raw')
Attila Fazekas689e2652013-10-07 18:06:57 +0200170 image_id = image['id']
171 self.addCleanup(self.os_img_client.delete_image, image_id)
172 return image_id