blob: 732a9824573bb11bd2543d396b66f79a40795af7 [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-ganesanab426722013-02-08 15:49:15 +053067from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010068from tempest.services.identity.xml.identity_client import IdentityClientXML
69from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish6d59c992013-03-01 16:20:04 -050070from tempest.services.image.v1.json.image_client import ImageClientJSON
Matthew Treinisha62347f2013-03-01 16:37:30 -050071from tempest.services.image.v2.json.image_client import ImageClientV2JSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050072from tempest.services.network.json.network_client import NetworkClient
dwalleck5d734432012-10-04 01:11:47 -050073from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +053074from tempest.services.object_storage.account_client import \
75 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +010076from tempest.services.object_storage.container_client import ContainerClient
77from tempest.services.object_storage.object_client import ObjectClient
78from tempest.services.object_storage.object_client import \
79 ObjectClientCustomizedHeader
80from tempest.services.volume.json.admin.volume_types_client import \
81 VolumeTypesClientJSON
82from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
83from tempest.services.volume.json.volumes_client import VolumesClientJSON
84from tempest.services.volume.xml.admin.volume_types_client import \
85 VolumeTypesClientXML
86from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
87from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +080088
Jay Pipes3f981df2012-03-27 18:59:44 -040089LOG = logging.getLogger(__name__)
90
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040091IMAGES_CLIENTS = {
92 "json": ImagesClientJSON,
93 "xml": ImagesClientXML,
94}
95
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040096KEYPAIRS_CLIENTS = {
97 "json": KeyPairsClientJSON,
98 "xml": KeyPairsClientXML,
99}
100
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530101QUOTAS_CLIENTS = {
102 "json": QuotasClientJSON,
103 "xml": QuotasClientXML,
104}
105
Dan Smithcf8fab62012-08-14 08:03:48 -0700106SERVERS_CLIENTS = {
107 "json": ServersClientJSON,
108 "xml": ServersClientXML,
109}
110
Matthew Treinish33634462012-08-16 16:51:23 -0400111LIMITS_CLIENTS = {
112 "json": LimitsClientJSON,
113 "xml": LimitsClientXML,
114}
115
Tiago Melloeda03b52012-08-22 23:47:29 -0300116FLAVORS_CLIENTS = {
117 "json": FlavorsClientJSON,
118 "xml": FlavorsClientXML
119}
120
Tiago Mello89126c32012-08-27 11:14:03 -0300121EXTENSIONS_CLIENTS = {
122 "json": ExtensionsClientJSON,
123 "xml": ExtensionsClientXML
124}
125
Matthew Treinish4e086902012-08-17 17:52:22 -0400126VOLUMES_EXTENSIONS_CLIENTS = {
127 "json": VolumesExtensionsClientJSON,
128 "xml": VolumesExtensionsClientXML,
129}
130
Vincent Hou22f03c72012-08-24 17:55:13 +0800131FLOAT_CLIENTS = {
132 "json": FloatingIPsClientJSON,
133 "xml": FloatingIPsClientXML,
134}
135
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100136SNAPSHOTS_CLIENTS = {
137 "json": SnapshotsClientJSON,
138 "xml": SnapshotsClientXML,
139}
140
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400141VOLUMES_CLIENTS = {
142 "json": VolumesClientJSON,
143 "xml": VolumesClientXML,
144}
145
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100146VOLUME_TYPES_CLIENTS = {
147 "json": VolumeTypesClientJSON,
148 "xml": VolumeTypesClientXML,
149}
150
Attila Fazekas407b6db2013-01-19 12:48:36 +0100151IDENTITY_CLIENT = {
152 "json": IdentityClientJSON,
153 "xml": IdentityClientXML,
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800154}
155
156TOKEN_CLIENT = {
157 "json": TokenClientJSON,
158 "xml": TokenClientXML,
159}
160
Vincent Houead03dc2012-08-24 21:35:11 +0800161SECURITY_GROUPS_CLIENT = {
162 "json": SecurityGroupsClientJSON,
163 "xml": SecurityGroupsClientXML,
164}
165
Dan Smith8ad1c472013-02-26 13:03:16 -0500166INTERFACES_CLIENT = {
167 "json": InterfacesClientJSON,
168 "xml": InterfacesClientXML,
169}
170
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530171ENDPOINT_CLIENT = {
172 "json": EndPointClientJSON,
173 "xml": EndPointClientXML,
174}
175
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400176FIXED_IPS_CLIENT = {
177 "json": FixedIPsClientJSON,
178 "xml": FixedIPsClientXML
179}
180
Leo Toyodaa5278912013-04-16 15:40:12 +0900181AVAILABILITY_ZONE_CLIENT = {
182 "json": AvailabilityZoneClientJSON,
183 "xml": AvailabilityZoneClientXML,
184}
185
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800186
Daryl Walleck1465d612011-11-02 02:22:15 -0500187class Manager(object):
188
Jay Pipes3f981df2012-03-27 18:59:44 -0400189 """
190 Top level manager for OpenStack Compute clients
191 """
192
James E. Blaire6d8ee12013-01-18 21:33:45 +0000193 def __init__(self, username=None, password=None, tenant_name=None,
194 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400195 """
196 We allow overriding of the credentials used within the various
197 client classes managed by the Manager object. Left as None, the
198 standard username/password/tenant_name is used.
199
200 :param username: Override of the username
201 :param password: Override of the password
202 :param tenant_name: Override of the tenant name
203 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400204 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800205
Jay Pipesf38eaac2012-06-21 13:37:35 -0400206 # If no creds are provided, we fall back on the defaults
207 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100208 self.username = username or self.config.identity.username
209 self.password = password or self.config.identity.password
210 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500211
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700212 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400213 msg = ("Missing required credentials. "
214 "username: %(username)s, password: %(password)s, "
215 "tenant_name: %(tenant_name)s") % locals()
216 raise exceptions.InvalidConfiguration(msg)
217
Jay Pipes7c88eb22013-01-16 21:32:43 -0500218 self.auth_url = self.config.identity.uri
Daryl Walleck587385b2012-03-03 13:00:26 -0600219
220 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700221 client_args = (self.config, self.username, self.password,
222 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500223 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700224 client_args = (self.config, self.username, self.password,
225 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600226
Dan Smithcf8fab62012-08-14 08:03:48 -0700227 try:
228 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400229 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400230 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400231 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530232 self.quotas_client = QUOTAS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300233 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800234 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
235 self.extensions_client = ext_cli
236 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
237 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800238 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100239 self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400240 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100241 self.volume_types_client = \
242 VOLUME_TYPES_CLIENTS[interface](*client_args)
Attila Fazekas407b6db2013-01-19 12:48:36 +0100243 self.identity_client = IDENTITY_CLIENT[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800244 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800245 self.security_groups_client = \
246 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smith8ad1c472013-02-26 13:03:16 -0500247 self.interfaces_client = INTERFACES_CLIENT[interface](*client_args)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530248 self.endpoints_client = ENDPOINT_CLIENT[interface](*client_args)
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400249 self.fixed_ips_client = FIXED_IPS_CLIENT[interface](*client_args)
Leo Toyodaa5278912013-04-16 15:40:12 +0900250 self.availability_zone_client = \
251 AVAILABILITY_ZONE_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700252 except KeyError:
253 msg = "Unsupported interface type `%s'" % interface
254 raise exceptions.InvalidConfiguration(msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530255 self.network_client = NetworkClient(*client_args)
Attila Fazekas8e99b992013-02-24 09:53:23 +0100256 self.hosts_client = HostsClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500257 self.account_client = AccountClient(*client_args)
Matthew Treinish72ea4422013-02-07 14:42:49 -0500258 self.image_client = ImageClientJSON(*client_args)
Matthew Treinisha62347f2013-03-01 16:37:30 -0500259 self.image_client_v2 = ImageClientV2JSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500260 self.container_client = ContainerClient(*client_args)
261 self.object_client = ObjectClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100262 self.ec2api_client = botoclients.APIClientEC2(*client_args)
263 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530264 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530265 self.custom_account_client = \
266 AccountClientCustomizedHeader(*client_args)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900267 self.aggregates_client = AggregatesClientJSON(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500268
269
Jay Pipesff10d552012-04-06 14:18:50 -0400270class AltManager(Manager):
271
272 """
273 Manager object that uses the alt_XXX credentials for its
274 managed client objects
275 """
276
277 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400278 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100279 super(AltManager, self).__init__(conf.identity.alt_username,
280 conf.identity.alt_password,
281 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400282
283
284class AdminManager(Manager):
285
286 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100287 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400288 managed client objects
289 """
290
James E. Blaire6d8ee12013-01-18 21:33:45 +0000291 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400292 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100293 super(AdminManager, self).__init__(conf.identity.admin_username,
294 conf.identity.admin_password,
295 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000296 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400297
298
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100299class ComputeAdminManager(Manager):
300
301 """
302 Manager object that uses the compute_admin credentials for its
303 managed client objects
304 """
305
306 def __init__(self, interface='json'):
307 conf = config.TempestConfig()
308 base = super(ComputeAdminManager, self)
309 base.__init__(conf.compute_admin.username,
310 conf.compute_admin.password,
311 conf.compute_admin.tenant_name,
312 interface=interface)