blob: f284f16e218c89e1013616201c7d160865991d61 [file] [log] [blame]
Jay Pipes3f981df2012-03-27 18:59:44 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import logging
19
Jay Pipesf38eaac2012-06-21 13:37:35 -040020from tempest import config
Daryl Walleck587385b2012-03-03 13:00:26 -060021from tempest import exceptions
Attila Fazekas1aed6202013-02-11 14:47:45 +010022from tempest.services import botoclients
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090023from tempest.services.compute.json.aggregates_client import \
24 AggregatesClientJSON
Leo Toyodaa5278912013-04-16 15:40:12 +090025from tempest.services.compute.json.availability_zone_client import \
26 AvailabilityZoneClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050027from tempest.services.compute.json.extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053028 ExtensionsClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040029from tempest.services.compute.json.fixed_ips_client import FixedIPsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050030from tempest.services.compute.json.flavors_client import FlavorsClientJSON
31from tempest.services.compute.json.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053032 FloatingIPsClientJSON
Attila Fazekas8e99b992013-02-24 09:53:23 +010033from tempest.services.compute.json.hosts_client import HostsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050034from tempest.services.compute.json.images_client import ImagesClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040035from tempest.services.compute.json.interfaces_client import \
36 InterfacesClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010037from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050038from tempest.services.compute.json.limits_client import LimitsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010039from tempest.services.compute.json.quotas_client import QuotasClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050040from tempest.services.compute.json.security_groups_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053041 SecurityGroupsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010042from tempest.services.compute.json.servers_client import ServersClientJSON
Leo Toyoda3ae31e12013-04-19 11:19:57 +090043from tempest.services.compute.json.services_client import ServicesClientJSON
Leo Toyodad80b6a02013-05-08 12:15:13 +090044from tempest.services.compute.json.tenant_usages_client import \
45 TenantUsagesClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050046from tempest.services.compute.json.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053047 VolumesExtensionsClientJSON
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +090048from tempest.services.compute.xml.aggregates_client import AggregatesClientXML
Leo Toyodaa5278912013-04-16 15:40:12 +090049from tempest.services.compute.xml.availability_zone_client import \
50 AvailabilityZoneClientXML
dwallecke62b9f02012-10-10 23:34:42 -050051from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040052from tempest.services.compute.xml.fixed_ips_client import FixedIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050053from tempest.services.compute.xml.flavors_client import FlavorsClientXML
54from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053055 FloatingIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050056from tempest.services.compute.xml.images_client import ImagesClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040057from tempest.services.compute.xml.interfaces_client import \
58 InterfacesClientXML
dwallecke62b9f02012-10-10 23:34:42 -050059from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
60from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053061from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050062from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053063 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050064from tempest.services.compute.xml.servers_client import ServersClientXML
Leo Toyoda3ae31e12013-04-19 11:19:57 +090065from tempest.services.compute.xml.services_client import ServicesClientXML
Leo Toyodad80b6a02013-05-08 12:15:13 +090066from tempest.services.compute.xml.tenant_usages_client import \
67 TenantUsagesClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050068from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053069 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010070from tempest.services.identity.json.identity_client import IdentityClientJSON
71from tempest.services.identity.json.identity_client import TokenClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040072from tempest.services.identity.v3.json.endpoints_client import \
73 EndPointClientJSON
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053074from tempest.services.identity.v3.json.identity_client import \
75 IdentityV3ClientJSON
harika-vakadia92dd742013-02-19 20:41:22 +053076from tempest.services.identity.v3.json.service_client import \
77 ServiceClientJSON
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053078from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053079from tempest.services.identity.v3.xml.identity_client import \
80 IdentityV3ClientXML
harika-vakadia92dd742013-02-19 20:41:22 +053081from tempest.services.identity.v3.xml.service_client import \
82 ServiceClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010083from tempest.services.identity.xml.identity_client import IdentityClientXML
84from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish6d59c992013-03-01 16:20:04 -050085from tempest.services.image.v1.json.image_client import ImageClientJSON
Matthew Treinisha62347f2013-03-01 16:37:30 -050086from tempest.services.image.v2.json.image_client import ImageClientV2JSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050087from tempest.services.network.json.network_client import NetworkClient
dwalleck5d734432012-10-04 01:11:47 -050088from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +053089from tempest.services.object_storage.account_client import \
90 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +010091from tempest.services.object_storage.container_client import ContainerClient
92from tempest.services.object_storage.object_client import ObjectClient
93from tempest.services.object_storage.object_client import \
94 ObjectClientCustomizedHeader
Steve Bakerc60e4e32013-05-06 15:22:41 +120095from tempest.services.orchestration.json.orchestration_client import \
96 OrchestrationClient
Attila Fazekas6968dd52013-02-15 17:05:53 +010097from tempest.services.volume.json.admin.volume_types_client import \
98 VolumeTypesClientJSON
99from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
100from tempest.services.volume.json.volumes_client import VolumesClientJSON
101from tempest.services.volume.xml.admin.volume_types_client import \
102 VolumeTypesClientXML
103from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
104from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800105
Jay Pipes3f981df2012-03-27 18:59:44 -0400106LOG = logging.getLogger(__name__)
107
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400108IMAGES_CLIENTS = {
109 "json": ImagesClientJSON,
110 "xml": ImagesClientXML,
111}
112
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400113KEYPAIRS_CLIENTS = {
114 "json": KeyPairsClientJSON,
115 "xml": KeyPairsClientXML,
116}
117
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530118QUOTAS_CLIENTS = {
119 "json": QuotasClientJSON,
120 "xml": QuotasClientXML,
121}
122
Dan Smithcf8fab62012-08-14 08:03:48 -0700123SERVERS_CLIENTS = {
124 "json": ServersClientJSON,
125 "xml": ServersClientXML,
126}
127
Matthew Treinish33634462012-08-16 16:51:23 -0400128LIMITS_CLIENTS = {
129 "json": LimitsClientJSON,
130 "xml": LimitsClientXML,
131}
132
Tiago Melloeda03b52012-08-22 23:47:29 -0300133FLAVORS_CLIENTS = {
134 "json": FlavorsClientJSON,
135 "xml": FlavorsClientXML
136}
137
Tiago Mello89126c32012-08-27 11:14:03 -0300138EXTENSIONS_CLIENTS = {
139 "json": ExtensionsClientJSON,
140 "xml": ExtensionsClientXML
141}
142
Matthew Treinish4e086902012-08-17 17:52:22 -0400143VOLUMES_EXTENSIONS_CLIENTS = {
144 "json": VolumesExtensionsClientJSON,
145 "xml": VolumesExtensionsClientXML,
146}
147
Vincent Hou22f03c72012-08-24 17:55:13 +0800148FLOAT_CLIENTS = {
149 "json": FloatingIPsClientJSON,
150 "xml": FloatingIPsClientXML,
151}
152
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100153SNAPSHOTS_CLIENTS = {
154 "json": SnapshotsClientJSON,
155 "xml": SnapshotsClientXML,
156}
157
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400158VOLUMES_CLIENTS = {
159 "json": VolumesClientJSON,
160 "xml": VolumesClientXML,
161}
162
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100163VOLUME_TYPES_CLIENTS = {
164 "json": VolumeTypesClientJSON,
165 "xml": VolumeTypesClientXML,
166}
167
Attila Fazekas407b6db2013-01-19 12:48:36 +0100168IDENTITY_CLIENT = {
169 "json": IdentityClientJSON,
170 "xml": IdentityClientXML,
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800171}
172
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530173IDENTITY_V3_CLIENT = {
174 "json": IdentityV3ClientJSON,
175 "xml": IdentityV3ClientXML,
176}
177
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800178TOKEN_CLIENT = {
179 "json": TokenClientJSON,
180 "xml": TokenClientXML,
181}
182
Vincent Houead03dc2012-08-24 21:35:11 +0800183SECURITY_GROUPS_CLIENT = {
184 "json": SecurityGroupsClientJSON,
185 "xml": SecurityGroupsClientXML,
186}
187
Dan Smith8ad1c472013-02-26 13:03:16 -0500188INTERFACES_CLIENT = {
189 "json": InterfacesClientJSON,
190 "xml": InterfacesClientXML,
191}
192
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530193ENDPOINT_CLIENT = {
194 "json": EndPointClientJSON,
195 "xml": EndPointClientXML,
196}
197
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400198FIXED_IPS_CLIENT = {
199 "json": FixedIPsClientJSON,
200 "xml": FixedIPsClientXML
201}
202
Leo Toyodaa5278912013-04-16 15:40:12 +0900203AVAILABILITY_ZONE_CLIENT = {
204 "json": AvailabilityZoneClientJSON,
205 "xml": AvailabilityZoneClientXML,
206}
207
harika-vakadia92dd742013-02-19 20:41:22 +0530208SERVICE_CLIENT = {
209 "json": ServiceClientJSON,
210 "xml": ServiceClientXML,
211}
212
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900213AGGREGATES_CLIENT = {
214 "json": AggregatesClientJSON,
215 "xml": AggregatesClientXML,
216}
217
Leo Toyoda3ae31e12013-04-19 11:19:57 +0900218SERVICES_CLIENT = {
219 "json": ServicesClientJSON,
220 "xml": ServicesClientXML,
221}
222
Leo Toyodad80b6a02013-05-08 12:15:13 +0900223TENANT_USAGES_CLIENT = {
224 "json": TenantUsagesClientJSON,
225 "xml": TenantUsagesClientXML,
226}
227
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800228
Daryl Walleck1465d612011-11-02 02:22:15 -0500229class Manager(object):
230
Jay Pipes3f981df2012-03-27 18:59:44 -0400231 """
232 Top level manager for OpenStack Compute clients
233 """
234
James E. Blaire6d8ee12013-01-18 21:33:45 +0000235 def __init__(self, username=None, password=None, tenant_name=None,
236 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400237 """
238 We allow overriding of the credentials used within the various
239 client classes managed by the Manager object. Left as None, the
240 standard username/password/tenant_name is used.
241
242 :param username: Override of the username
243 :param password: Override of the password
244 :param tenant_name: Override of the tenant name
245 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400246 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800247
Jay Pipesf38eaac2012-06-21 13:37:35 -0400248 # If no creds are provided, we fall back on the defaults
249 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100250 self.username = username or self.config.identity.username
251 self.password = password or self.config.identity.password
252 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500253
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700254 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400255 msg = ("Missing required credentials. "
256 "username: %(username)s, password: %(password)s, "
257 "tenant_name: %(tenant_name)s") % locals()
258 raise exceptions.InvalidConfiguration(msg)
259
Jay Pipes7c88eb22013-01-16 21:32:43 -0500260 self.auth_url = self.config.identity.uri
Daryl Walleck587385b2012-03-03 13:00:26 -0600261
262 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700263 client_args = (self.config, self.username, self.password,
264 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500265 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700266 client_args = (self.config, self.username, self.password,
267 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600268
Dan Smithcf8fab62012-08-14 08:03:48 -0700269 try:
270 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400271 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400272 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400273 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530274 self.quotas_client = QUOTAS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300275 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800276 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
277 self.extensions_client = ext_cli
278 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
279 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800280 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100281 self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400282 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100283 self.volume_types_client = \
284 VOLUME_TYPES_CLIENTS[interface](*client_args)
Attila Fazekas407b6db2013-01-19 12:48:36 +0100285 self.identity_client = IDENTITY_CLIENT[interface](*client_args)
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530286 self.identity_v3_client = \
287 IDENTITY_V3_CLIENT[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800288 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800289 self.security_groups_client = \
290 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smith8ad1c472013-02-26 13:03:16 -0500291 self.interfaces_client = INTERFACES_CLIENT[interface](*client_args)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530292 self.endpoints_client = ENDPOINT_CLIENT[interface](*client_args)
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400293 self.fixed_ips_client = FIXED_IPS_CLIENT[interface](*client_args)
Leo Toyodaa5278912013-04-16 15:40:12 +0900294 self.availability_zone_client = \
295 AVAILABILITY_ZONE_CLIENT[interface](*client_args)
harika-vakadia92dd742013-02-19 20:41:22 +0530296 self.service_client = SERVICE_CLIENT[interface](*client_args)
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900297 self.aggregates_client = AGGREGATES_CLIENT[interface](*client_args)
Leo Toyoda3ae31e12013-04-19 11:19:57 +0900298 self.services_client = SERVICES_CLIENT[interface](*client_args)
Leo Toyodad80b6a02013-05-08 12:15:13 +0900299 self.tenant_usages_client = \
300 TENANT_USAGES_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700301 except KeyError:
302 msg = "Unsupported interface type `%s'" % interface
303 raise exceptions.InvalidConfiguration(msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530304 self.network_client = NetworkClient(*client_args)
Attila Fazekas8e99b992013-02-24 09:53:23 +0100305 self.hosts_client = HostsClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500306 self.account_client = AccountClient(*client_args)
Matthew Treinish72ea4422013-02-07 14:42:49 -0500307 self.image_client = ImageClientJSON(*client_args)
Matthew Treinisha62347f2013-03-01 16:37:30 -0500308 self.image_client_v2 = ImageClientV2JSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500309 self.container_client = ContainerClient(*client_args)
310 self.object_client = ObjectClient(*client_args)
Steve Bakerc60e4e32013-05-06 15:22:41 +1200311 self.orchestration_client = OrchestrationClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100312 self.ec2api_client = botoclients.APIClientEC2(*client_args)
313 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530314 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530315 self.custom_account_client = \
316 AccountClientCustomizedHeader(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500317
318
Jay Pipesff10d552012-04-06 14:18:50 -0400319class AltManager(Manager):
320
321 """
322 Manager object that uses the alt_XXX credentials for its
323 managed client objects
324 """
325
326 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400327 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100328 super(AltManager, self).__init__(conf.identity.alt_username,
329 conf.identity.alt_password,
330 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400331
332
333class AdminManager(Manager):
334
335 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100336 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400337 managed client objects
338 """
339
James E. Blaire6d8ee12013-01-18 21:33:45 +0000340 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400341 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100342 super(AdminManager, self).__init__(conf.identity.admin_username,
343 conf.identity.admin_password,
344 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000345 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400346
347
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100348class ComputeAdminManager(Manager):
349
350 """
351 Manager object that uses the compute_admin credentials for its
352 managed client objects
353 """
354
355 def __init__(self, interface='json'):
356 conf = config.TempestConfig()
357 base = super(ComputeAdminManager, self)
358 base.__init__(conf.compute_admin.username,
359 conf.compute_admin.password,
360 conf.compute_admin.tenant_name,
361 interface=interface)
Steve Bakerc60e4e32013-05-06 15:22:41 +1200362
363
364class OrchestrationManager(Manager):
365 """
366 Manager object that uses the admin credentials for its
367 so that heat templates can create users
368 """
369 def __init__(self, interface='json'):
370 conf = config.TempestConfig()
371 base = super(OrchestrationManager, self)
372 base.__init__(conf.identity.admin_username,
373 conf.identity.admin_password,
374 conf.identity.admin_tenant_name,
375 interface=interface)