blob: 7b1e5cc911edf8bc8db283a576db656711232c4f [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
Leo Toyodaa5278912013-04-16 15:40:12 +090045from tempest.services.compute.xml.availability_zone_client import \
46 AvailabilityZoneClientXML
dwallecke62b9f02012-10-10 23:34:42 -050047from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040048from tempest.services.compute.xml.fixed_ips_client import FixedIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050049from tempest.services.compute.xml.flavors_client import FlavorsClientXML
50from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053051 FloatingIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050052from tempest.services.compute.xml.images_client import ImagesClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040053from tempest.services.compute.xml.interfaces_client import \
54 InterfacesClientXML
dwallecke62b9f02012-10-10 23:34:42 -050055from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
56from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053057from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050058from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053059 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050060from tempest.services.compute.xml.servers_client import ServersClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050061from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053062 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010063from tempest.services.identity.json.identity_client import IdentityClientJSON
64from tempest.services.identity.json.identity_client import TokenClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040065from tempest.services.identity.v3.json.endpoints_client import \
66 EndPointClientJSON
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053067from tempest.services.identity.v3.json.identity_client import \
68 IdentityV3ClientJSON
harika-vakadia92dd742013-02-19 20:41:22 +053069from tempest.services.identity.v3.json.service_client import \
70 ServiceClientJSON
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053071from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053072from tempest.services.identity.v3.xml.identity_client import \
73 IdentityV3ClientXML
harika-vakadia92dd742013-02-19 20:41:22 +053074from tempest.services.identity.v3.xml.service_client import \
75 ServiceClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010076from tempest.services.identity.xml.identity_client import IdentityClientXML
77from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish6d59c992013-03-01 16:20:04 -050078from tempest.services.image.v1.json.image_client import ImageClientJSON
Matthew Treinisha62347f2013-03-01 16:37:30 -050079from tempest.services.image.v2.json.image_client import ImageClientV2JSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050080from tempest.services.network.json.network_client import NetworkClient
dwalleck5d734432012-10-04 01:11:47 -050081from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +053082from tempest.services.object_storage.account_client import \
83 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +010084from tempest.services.object_storage.container_client import ContainerClient
85from tempest.services.object_storage.object_client import ObjectClient
86from tempest.services.object_storage.object_client import \
87 ObjectClientCustomizedHeader
88from tempest.services.volume.json.admin.volume_types_client import \
89 VolumeTypesClientJSON
90from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
91from tempest.services.volume.json.volumes_client import VolumesClientJSON
92from tempest.services.volume.xml.admin.volume_types_client import \
93 VolumeTypesClientXML
94from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
95from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +080096
Jay Pipes3f981df2012-03-27 18:59:44 -040097LOG = logging.getLogger(__name__)
98
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040099IMAGES_CLIENTS = {
100 "json": ImagesClientJSON,
101 "xml": ImagesClientXML,
102}
103
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400104KEYPAIRS_CLIENTS = {
105 "json": KeyPairsClientJSON,
106 "xml": KeyPairsClientXML,
107}
108
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530109QUOTAS_CLIENTS = {
110 "json": QuotasClientJSON,
111 "xml": QuotasClientXML,
112}
113
Dan Smithcf8fab62012-08-14 08:03:48 -0700114SERVERS_CLIENTS = {
115 "json": ServersClientJSON,
116 "xml": ServersClientXML,
117}
118
Matthew Treinish33634462012-08-16 16:51:23 -0400119LIMITS_CLIENTS = {
120 "json": LimitsClientJSON,
121 "xml": LimitsClientXML,
122}
123
Tiago Melloeda03b52012-08-22 23:47:29 -0300124FLAVORS_CLIENTS = {
125 "json": FlavorsClientJSON,
126 "xml": FlavorsClientXML
127}
128
Tiago Mello89126c32012-08-27 11:14:03 -0300129EXTENSIONS_CLIENTS = {
130 "json": ExtensionsClientJSON,
131 "xml": ExtensionsClientXML
132}
133
Matthew Treinish4e086902012-08-17 17:52:22 -0400134VOLUMES_EXTENSIONS_CLIENTS = {
135 "json": VolumesExtensionsClientJSON,
136 "xml": VolumesExtensionsClientXML,
137}
138
Vincent Hou22f03c72012-08-24 17:55:13 +0800139FLOAT_CLIENTS = {
140 "json": FloatingIPsClientJSON,
141 "xml": FloatingIPsClientXML,
142}
143
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100144SNAPSHOTS_CLIENTS = {
145 "json": SnapshotsClientJSON,
146 "xml": SnapshotsClientXML,
147}
148
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400149VOLUMES_CLIENTS = {
150 "json": VolumesClientJSON,
151 "xml": VolumesClientXML,
152}
153
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100154VOLUME_TYPES_CLIENTS = {
155 "json": VolumeTypesClientJSON,
156 "xml": VolumeTypesClientXML,
157}
158
Attila Fazekas407b6db2013-01-19 12:48:36 +0100159IDENTITY_CLIENT = {
160 "json": IdentityClientJSON,
161 "xml": IdentityClientXML,
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800162}
163
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530164IDENTITY_V3_CLIENT = {
165 "json": IdentityV3ClientJSON,
166 "xml": IdentityV3ClientXML,
167}
168
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800169TOKEN_CLIENT = {
170 "json": TokenClientJSON,
171 "xml": TokenClientXML,
172}
173
Vincent Houead03dc2012-08-24 21:35:11 +0800174SECURITY_GROUPS_CLIENT = {
175 "json": SecurityGroupsClientJSON,
176 "xml": SecurityGroupsClientXML,
177}
178
Dan Smith8ad1c472013-02-26 13:03:16 -0500179INTERFACES_CLIENT = {
180 "json": InterfacesClientJSON,
181 "xml": InterfacesClientXML,
182}
183
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530184ENDPOINT_CLIENT = {
185 "json": EndPointClientJSON,
186 "xml": EndPointClientXML,
187}
188
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400189FIXED_IPS_CLIENT = {
190 "json": FixedIPsClientJSON,
191 "xml": FixedIPsClientXML
192}
193
Leo Toyodaa5278912013-04-16 15:40:12 +0900194AVAILABILITY_ZONE_CLIENT = {
195 "json": AvailabilityZoneClientJSON,
196 "xml": AvailabilityZoneClientXML,
197}
198
harika-vakadia92dd742013-02-19 20:41:22 +0530199SERVICE_CLIENT = {
200 "json": ServiceClientJSON,
201 "xml": ServiceClientXML,
202}
203
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800204
Daryl Walleck1465d612011-11-02 02:22:15 -0500205class Manager(object):
206
Jay Pipes3f981df2012-03-27 18:59:44 -0400207 """
208 Top level manager for OpenStack Compute clients
209 """
210
James E. Blaire6d8ee12013-01-18 21:33:45 +0000211 def __init__(self, username=None, password=None, tenant_name=None,
212 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400213 """
214 We allow overriding of the credentials used within the various
215 client classes managed by the Manager object. Left as None, the
216 standard username/password/tenant_name is used.
217
218 :param username: Override of the username
219 :param password: Override of the password
220 :param tenant_name: Override of the tenant name
221 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400222 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800223
Jay Pipesf38eaac2012-06-21 13:37:35 -0400224 # If no creds are provided, we fall back on the defaults
225 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100226 self.username = username or self.config.identity.username
227 self.password = password or self.config.identity.password
228 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500229
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700230 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400231 msg = ("Missing required credentials. "
232 "username: %(username)s, password: %(password)s, "
233 "tenant_name: %(tenant_name)s") % locals()
234 raise exceptions.InvalidConfiguration(msg)
235
Jay Pipes7c88eb22013-01-16 21:32:43 -0500236 self.auth_url = self.config.identity.uri
Daryl Walleck587385b2012-03-03 13:00:26 -0600237
238 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700239 client_args = (self.config, self.username, self.password,
240 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500241 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700242 client_args = (self.config, self.username, self.password,
243 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600244
Dan Smithcf8fab62012-08-14 08:03:48 -0700245 try:
246 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400247 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400248 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400249 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530250 self.quotas_client = QUOTAS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300251 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800252 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
253 self.extensions_client = ext_cli
254 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
255 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800256 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100257 self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400258 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100259 self.volume_types_client = \
260 VOLUME_TYPES_CLIENTS[interface](*client_args)
Attila Fazekas407b6db2013-01-19 12:48:36 +0100261 self.identity_client = IDENTITY_CLIENT[interface](*client_args)
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530262 self.identity_v3_client = \
263 IDENTITY_V3_CLIENT[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800264 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800265 self.security_groups_client = \
266 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smith8ad1c472013-02-26 13:03:16 -0500267 self.interfaces_client = INTERFACES_CLIENT[interface](*client_args)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530268 self.endpoints_client = ENDPOINT_CLIENT[interface](*client_args)
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400269 self.fixed_ips_client = FIXED_IPS_CLIENT[interface](*client_args)
Leo Toyodaa5278912013-04-16 15:40:12 +0900270 self.availability_zone_client = \
271 AVAILABILITY_ZONE_CLIENT[interface](*client_args)
harika-vakadia92dd742013-02-19 20:41:22 +0530272 self.service_client = SERVICE_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700273 except KeyError:
274 msg = "Unsupported interface type `%s'" % interface
275 raise exceptions.InvalidConfiguration(msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530276 self.network_client = NetworkClient(*client_args)
Attila Fazekas8e99b992013-02-24 09:53:23 +0100277 self.hosts_client = HostsClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500278 self.account_client = AccountClient(*client_args)
Matthew Treinish72ea4422013-02-07 14:42:49 -0500279 self.image_client = ImageClientJSON(*client_args)
Matthew Treinisha62347f2013-03-01 16:37:30 -0500280 self.image_client_v2 = ImageClientV2JSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500281 self.container_client = ContainerClient(*client_args)
282 self.object_client = ObjectClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100283 self.ec2api_client = botoclients.APIClientEC2(*client_args)
284 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530285 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530286 self.custom_account_client = \
287 AccountClientCustomizedHeader(*client_args)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900288 self.aggregates_client = AggregatesClientJSON(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500289
290
Jay Pipesff10d552012-04-06 14:18:50 -0400291class AltManager(Manager):
292
293 """
294 Manager object that uses the alt_XXX credentials for its
295 managed client objects
296 """
297
298 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400299 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100300 super(AltManager, self).__init__(conf.identity.alt_username,
301 conf.identity.alt_password,
302 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400303
304
305class AdminManager(Manager):
306
307 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100308 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400309 managed client objects
310 """
311
James E. Blaire6d8ee12013-01-18 21:33:45 +0000312 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400313 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100314 super(AdminManager, self).__init__(conf.identity.admin_username,
315 conf.identity.admin_password,
316 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000317 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400318
319
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100320class ComputeAdminManager(Manager):
321
322 """
323 Manager object that uses the compute_admin credentials for its
324 managed client objects
325 """
326
327 def __init__(self, interface='json'):
328 conf = config.TempestConfig()
329 base = super(ComputeAdminManager, self)
330 base.__init__(conf.compute_admin.username,
331 conf.compute_admin.password,
332 conf.compute_admin.tenant_name,
333 interface=interface)