blob: 9b2c1f5f237e58d300ae2fa40ed92d12b3e7cf4d [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
Matthew Treinisha83a16e2012-12-07 13:44:02 -050043from tempest.services.compute.json.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053044 VolumesExtensionsClientJSON
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +090045from tempest.services.compute.xml.aggregates_client import AggregatesClientXML
Leo Toyodaa5278912013-04-16 15:40:12 +090046from tempest.services.compute.xml.availability_zone_client import \
47 AvailabilityZoneClientXML
dwallecke62b9f02012-10-10 23:34:42 -050048from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040049from tempest.services.compute.xml.fixed_ips_client import FixedIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050050from tempest.services.compute.xml.flavors_client import FlavorsClientXML
51from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053052 FloatingIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050053from tempest.services.compute.xml.images_client import ImagesClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040054from tempest.services.compute.xml.interfaces_client import \
55 InterfacesClientXML
dwallecke62b9f02012-10-10 23:34:42 -050056from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
57from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053058from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050059from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053060 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050061from tempest.services.compute.xml.servers_client import ServersClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050062from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053063 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010064from tempest.services.identity.json.identity_client import IdentityClientJSON
65from tempest.services.identity.json.identity_client import TokenClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040066from tempest.services.identity.v3.json.endpoints_client import \
67 EndPointClientJSON
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053068from tempest.services.identity.v3.json.identity_client import \
69 IdentityV3ClientJSON
harika-vakadia92dd742013-02-19 20:41:22 +053070from tempest.services.identity.v3.json.service_client import \
71 ServiceClientJSON
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053072from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053073from tempest.services.identity.v3.xml.identity_client import \
74 IdentityV3ClientXML
harika-vakadia92dd742013-02-19 20:41:22 +053075from tempest.services.identity.v3.xml.service_client import \
76 ServiceClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010077from tempest.services.identity.xml.identity_client import IdentityClientXML
78from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish6d59c992013-03-01 16:20:04 -050079from tempest.services.image.v1.json.image_client import ImageClientJSON
Matthew Treinisha62347f2013-03-01 16:37:30 -050080from tempest.services.image.v2.json.image_client import ImageClientV2JSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050081from tempest.services.network.json.network_client import NetworkClient
dwalleck5d734432012-10-04 01:11:47 -050082from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +053083from tempest.services.object_storage.account_client import \
84 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +010085from tempest.services.object_storage.container_client import ContainerClient
86from tempest.services.object_storage.object_client import ObjectClient
87from tempest.services.object_storage.object_client import \
88 ObjectClientCustomizedHeader
89from tempest.services.volume.json.admin.volume_types_client import \
90 VolumeTypesClientJSON
91from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
92from tempest.services.volume.json.volumes_client import VolumesClientJSON
93from tempest.services.volume.xml.admin.volume_types_client import \
94 VolumeTypesClientXML
95from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
96from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +080097
Jay Pipes3f981df2012-03-27 18:59:44 -040098LOG = logging.getLogger(__name__)
99
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400100IMAGES_CLIENTS = {
101 "json": ImagesClientJSON,
102 "xml": ImagesClientXML,
103}
104
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400105KEYPAIRS_CLIENTS = {
106 "json": KeyPairsClientJSON,
107 "xml": KeyPairsClientXML,
108}
109
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530110QUOTAS_CLIENTS = {
111 "json": QuotasClientJSON,
112 "xml": QuotasClientXML,
113}
114
Dan Smithcf8fab62012-08-14 08:03:48 -0700115SERVERS_CLIENTS = {
116 "json": ServersClientJSON,
117 "xml": ServersClientXML,
118}
119
Matthew Treinish33634462012-08-16 16:51:23 -0400120LIMITS_CLIENTS = {
121 "json": LimitsClientJSON,
122 "xml": LimitsClientXML,
123}
124
Tiago Melloeda03b52012-08-22 23:47:29 -0300125FLAVORS_CLIENTS = {
126 "json": FlavorsClientJSON,
127 "xml": FlavorsClientXML
128}
129
Tiago Mello89126c32012-08-27 11:14:03 -0300130EXTENSIONS_CLIENTS = {
131 "json": ExtensionsClientJSON,
132 "xml": ExtensionsClientXML
133}
134
Matthew Treinish4e086902012-08-17 17:52:22 -0400135VOLUMES_EXTENSIONS_CLIENTS = {
136 "json": VolumesExtensionsClientJSON,
137 "xml": VolumesExtensionsClientXML,
138}
139
Vincent Hou22f03c72012-08-24 17:55:13 +0800140FLOAT_CLIENTS = {
141 "json": FloatingIPsClientJSON,
142 "xml": FloatingIPsClientXML,
143}
144
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100145SNAPSHOTS_CLIENTS = {
146 "json": SnapshotsClientJSON,
147 "xml": SnapshotsClientXML,
148}
149
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400150VOLUMES_CLIENTS = {
151 "json": VolumesClientJSON,
152 "xml": VolumesClientXML,
153}
154
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100155VOLUME_TYPES_CLIENTS = {
156 "json": VolumeTypesClientJSON,
157 "xml": VolumeTypesClientXML,
158}
159
Attila Fazekas407b6db2013-01-19 12:48:36 +0100160IDENTITY_CLIENT = {
161 "json": IdentityClientJSON,
162 "xml": IdentityClientXML,
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800163}
164
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530165IDENTITY_V3_CLIENT = {
166 "json": IdentityV3ClientJSON,
167 "xml": IdentityV3ClientXML,
168}
169
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800170TOKEN_CLIENT = {
171 "json": TokenClientJSON,
172 "xml": TokenClientXML,
173}
174
Vincent Houead03dc2012-08-24 21:35:11 +0800175SECURITY_GROUPS_CLIENT = {
176 "json": SecurityGroupsClientJSON,
177 "xml": SecurityGroupsClientXML,
178}
179
Dan Smith8ad1c472013-02-26 13:03:16 -0500180INTERFACES_CLIENT = {
181 "json": InterfacesClientJSON,
182 "xml": InterfacesClientXML,
183}
184
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530185ENDPOINT_CLIENT = {
186 "json": EndPointClientJSON,
187 "xml": EndPointClientXML,
188}
189
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400190FIXED_IPS_CLIENT = {
191 "json": FixedIPsClientJSON,
192 "xml": FixedIPsClientXML
193}
194
Leo Toyodaa5278912013-04-16 15:40:12 +0900195AVAILABILITY_ZONE_CLIENT = {
196 "json": AvailabilityZoneClientJSON,
197 "xml": AvailabilityZoneClientXML,
198}
199
harika-vakadia92dd742013-02-19 20:41:22 +0530200SERVICE_CLIENT = {
201 "json": ServiceClientJSON,
202 "xml": ServiceClientXML,
203}
204
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900205AGGREGATES_CLIENT = {
206 "json": AggregatesClientJSON,
207 "xml": AggregatesClientXML,
208}
209
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800210
Daryl Walleck1465d612011-11-02 02:22:15 -0500211class Manager(object):
212
Jay Pipes3f981df2012-03-27 18:59:44 -0400213 """
214 Top level manager for OpenStack Compute clients
215 """
216
James E. Blaire6d8ee12013-01-18 21:33:45 +0000217 def __init__(self, username=None, password=None, tenant_name=None,
218 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400219 """
220 We allow overriding of the credentials used within the various
221 client classes managed by the Manager object. Left as None, the
222 standard username/password/tenant_name is used.
223
224 :param username: Override of the username
225 :param password: Override of the password
226 :param tenant_name: Override of the tenant name
227 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400228 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800229
Jay Pipesf38eaac2012-06-21 13:37:35 -0400230 # If no creds are provided, we fall back on the defaults
231 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100232 self.username = username or self.config.identity.username
233 self.password = password or self.config.identity.password
234 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500235
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700236 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400237 msg = ("Missing required credentials. "
238 "username: %(username)s, password: %(password)s, "
239 "tenant_name: %(tenant_name)s") % locals()
240 raise exceptions.InvalidConfiguration(msg)
241
Jay Pipes7c88eb22013-01-16 21:32:43 -0500242 self.auth_url = self.config.identity.uri
Daryl Walleck587385b2012-03-03 13:00:26 -0600243
244 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700245 client_args = (self.config, self.username, self.password,
246 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500247 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700248 client_args = (self.config, self.username, self.password,
249 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600250
Dan Smithcf8fab62012-08-14 08:03:48 -0700251 try:
252 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400253 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400254 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400255 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530256 self.quotas_client = QUOTAS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300257 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800258 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
259 self.extensions_client = ext_cli
260 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
261 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800262 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100263 self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400264 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100265 self.volume_types_client = \
266 VOLUME_TYPES_CLIENTS[interface](*client_args)
Attila Fazekas407b6db2013-01-19 12:48:36 +0100267 self.identity_client = IDENTITY_CLIENT[interface](*client_args)
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530268 self.identity_v3_client = \
269 IDENTITY_V3_CLIENT[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800270 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800271 self.security_groups_client = \
272 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smith8ad1c472013-02-26 13:03:16 -0500273 self.interfaces_client = INTERFACES_CLIENT[interface](*client_args)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530274 self.endpoints_client = ENDPOINT_CLIENT[interface](*client_args)
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400275 self.fixed_ips_client = FIXED_IPS_CLIENT[interface](*client_args)
Leo Toyodaa5278912013-04-16 15:40:12 +0900276 self.availability_zone_client = \
277 AVAILABILITY_ZONE_CLIENT[interface](*client_args)
harika-vakadia92dd742013-02-19 20:41:22 +0530278 self.service_client = SERVICE_CLIENT[interface](*client_args)
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900279 self.aggregates_client = AGGREGATES_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700280 except KeyError:
281 msg = "Unsupported interface type `%s'" % interface
282 raise exceptions.InvalidConfiguration(msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530283 self.network_client = NetworkClient(*client_args)
Attila Fazekas8e99b992013-02-24 09:53:23 +0100284 self.hosts_client = HostsClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500285 self.account_client = AccountClient(*client_args)
Matthew Treinish72ea4422013-02-07 14:42:49 -0500286 self.image_client = ImageClientJSON(*client_args)
Matthew Treinisha62347f2013-03-01 16:37:30 -0500287 self.image_client_v2 = ImageClientV2JSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500288 self.container_client = ContainerClient(*client_args)
289 self.object_client = ObjectClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100290 self.ec2api_client = botoclients.APIClientEC2(*client_args)
291 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530292 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530293 self.custom_account_client = \
294 AccountClientCustomizedHeader(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500295
296
Jay Pipesff10d552012-04-06 14:18:50 -0400297class AltManager(Manager):
298
299 """
300 Manager object that uses the alt_XXX credentials for its
301 managed client objects
302 """
303
304 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400305 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100306 super(AltManager, self).__init__(conf.identity.alt_username,
307 conf.identity.alt_password,
308 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400309
310
311class AdminManager(Manager):
312
313 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100314 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400315 managed client objects
316 """
317
James E. Blaire6d8ee12013-01-18 21:33:45 +0000318 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400319 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100320 super(AdminManager, self).__init__(conf.identity.admin_username,
321 conf.identity.admin_password,
322 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000323 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400324
325
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100326class ComputeAdminManager(Manager):
327
328 """
329 Manager object that uses the compute_admin credentials for its
330 managed client objects
331 """
332
333 def __init__(self, interface='json'):
334 conf = config.TempestConfig()
335 base = super(ComputeAdminManager, self)
336 base.__init__(conf.compute_admin.username,
337 conf.compute_admin.password,
338 conf.compute_admin.tenant_name,
339 interface=interface)