blob: 8d9c216456dc0a90b63a69d22dc2c45d9fdd57f0 [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
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022from tempest.services.boto.clients import APIClientEC2
23from tempest.services.boto.clients import ObjectClientS3
dwallecke62b9f02012-10-10 23:34:42 -050024from tempest.services.compute.json.extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053025 ExtensionsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050026from tempest.services.compute.json.flavors_client import FlavorsClientJSON
27from tempest.services.compute.json.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053028 FloatingIPsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050029from tempest.services.compute.json.images_client import ImagesClientJSON
30from tempest.services.compute.json.limits_client import LimitsClientJSON
31from tempest.services.compute.json.servers_client import ServersClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050032from tempest.services.compute.json.security_groups_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053033 SecurityGroupsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050034from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053035from tempest.services.compute.json.quotas_client import QuotasClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050036from tempest.services.compute.json.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053037 VolumesExtensionsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050038from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
39from tempest.services.compute.xml.flavors_client import FlavorsClientXML
40from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053041 FloatingIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050042from tempest.services.compute.xml.images_client import ImagesClientXML
43from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
44from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053045from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050046from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053047 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050048from tempest.services.compute.xml.servers_client import ServersClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050049from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053050 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010051from tempest.services.identity.json.identity_client import IdentityClientJSON
52from tempest.services.identity.json.identity_client import TokenClientJSON
53from tempest.services.identity.xml.identity_client import IdentityClientXML
54from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish72ea4422013-02-07 14:42:49 -050055from tempest.services.image.json.image_client import ImageClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050056from tempest.services.network.json.network_client import NetworkClient
dwalleck5d734432012-10-04 01:11:47 -050057from tempest.services.object_storage.account_client import AccountClient
58from tempest.services.object_storage.container_client import ContainerClient
59from tempest.services.object_storage.object_client import ObjectClient
Attila Fazekas3dcdae12013-02-14 12:50:04 +010060from tempest.services.volume.json.admin.volume_types_client import \
61 VolumeTypesClientJSON
62from tempest.services.volume.xml.admin.volume_types_client import \
63 VolumeTypesClientXML
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010064from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050065from tempest.services.volume.json.volumes_client import VolumesClientJSON
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010066from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050067from tempest.services.volume.xml.volumes_client import VolumesClientXML
harika-vakadi1a9ad612012-12-14 19:12:08 +053068from tempest.services.object_storage.object_client import \
69 ObjectClientCustomizedHeader
harika-vakadi2daed0a2013-01-01 20:51:39 +053070from tempest.services.object_storage.account_client import \
71 AccountClientCustomizedHeader
Vincent Hou6b8a7b72012-08-25 01:24:33 +080072
Jay Pipes3f981df2012-03-27 18:59:44 -040073LOG = logging.getLogger(__name__)
74
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040075IMAGES_CLIENTS = {
76 "json": ImagesClientJSON,
77 "xml": ImagesClientXML,
78}
79
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040080KEYPAIRS_CLIENTS = {
81 "json": KeyPairsClientJSON,
82 "xml": KeyPairsClientXML,
83}
84
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053085QUOTAS_CLIENTS = {
86 "json": QuotasClientJSON,
87 "xml": QuotasClientXML,
88}
89
Dan Smithcf8fab62012-08-14 08:03:48 -070090SERVERS_CLIENTS = {
91 "json": ServersClientJSON,
92 "xml": ServersClientXML,
93}
94
Matthew Treinish33634462012-08-16 16:51:23 -040095LIMITS_CLIENTS = {
96 "json": LimitsClientJSON,
97 "xml": LimitsClientXML,
98}
99
Tiago Melloeda03b52012-08-22 23:47:29 -0300100FLAVORS_CLIENTS = {
101 "json": FlavorsClientJSON,
102 "xml": FlavorsClientXML
103}
104
Tiago Mello89126c32012-08-27 11:14:03 -0300105EXTENSIONS_CLIENTS = {
106 "json": ExtensionsClientJSON,
107 "xml": ExtensionsClientXML
108}
109
Matthew Treinish4e086902012-08-17 17:52:22 -0400110VOLUMES_EXTENSIONS_CLIENTS = {
111 "json": VolumesExtensionsClientJSON,
112 "xml": VolumesExtensionsClientXML,
113}
114
Vincent Hou22f03c72012-08-24 17:55:13 +0800115FLOAT_CLIENTS = {
116 "json": FloatingIPsClientJSON,
117 "xml": FloatingIPsClientXML,
118}
119
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100120SNAPSHOTS_CLIENTS = {
121 "json": SnapshotsClientJSON,
122 "xml": SnapshotsClientXML,
123}
124
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400125VOLUMES_CLIENTS = {
126 "json": VolumesClientJSON,
127 "xml": VolumesClientXML,
128}
129
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100130VOLUME_TYPES_CLIENTS = {
131 "json": VolumeTypesClientJSON,
132 "xml": VolumeTypesClientXML,
133}
134
Attila Fazekas407b6db2013-01-19 12:48:36 +0100135IDENTITY_CLIENT = {
136 "json": IdentityClientJSON,
137 "xml": IdentityClientXML,
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800138}
139
140TOKEN_CLIENT = {
141 "json": TokenClientJSON,
142 "xml": TokenClientXML,
143}
144
Vincent Houead03dc2012-08-24 21:35:11 +0800145SECURITY_GROUPS_CLIENT = {
146 "json": SecurityGroupsClientJSON,
147 "xml": SecurityGroupsClientXML,
148}
149
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800150
Daryl Walleck1465d612011-11-02 02:22:15 -0500151class Manager(object):
152
Jay Pipes3f981df2012-03-27 18:59:44 -0400153 """
154 Top level manager for OpenStack Compute clients
155 """
156
James E. Blaire6d8ee12013-01-18 21:33:45 +0000157 def __init__(self, username=None, password=None, tenant_name=None,
158 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400159 """
160 We allow overriding of the credentials used within the various
161 client classes managed by the Manager object. Left as None, the
162 standard username/password/tenant_name is used.
163
164 :param username: Override of the username
165 :param password: Override of the password
166 :param tenant_name: Override of the tenant name
167 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400168 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800169
Jay Pipesf38eaac2012-06-21 13:37:35 -0400170 # If no creds are provided, we fall back on the defaults
171 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100172 self.username = username or self.config.identity.username
173 self.password = password or self.config.identity.password
174 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500175
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700176 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400177 msg = ("Missing required credentials. "
178 "username: %(username)s, password: %(password)s, "
179 "tenant_name: %(tenant_name)s") % locals()
180 raise exceptions.InvalidConfiguration(msg)
181
Jay Pipes7c88eb22013-01-16 21:32:43 -0500182 self.auth_url = self.config.identity.uri
Daryl Walleck587385b2012-03-03 13:00:26 -0600183
184 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700185 client_args = (self.config, self.username, self.password,
186 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500187 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700188 client_args = (self.config, self.username, self.password,
189 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600190
Dan Smithcf8fab62012-08-14 08:03:48 -0700191 try:
192 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400193 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400194 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400195 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530196 self.quotas_client = QUOTAS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300197 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800198 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
199 self.extensions_client = ext_cli
200 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
201 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800202 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100203 self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400204 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100205 self.volume_types_client = \
206 VOLUME_TYPES_CLIENTS[interface](*client_args)
Attila Fazekas407b6db2013-01-19 12:48:36 +0100207 self.identity_client = IDENTITY_CLIENT[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800208 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800209 self.security_groups_client = \
210 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700211 except KeyError:
212 msg = "Unsupported interface type `%s'" % interface
213 raise exceptions.InvalidConfiguration(msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530214 self.network_client = NetworkClient(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500215 self.account_client = AccountClient(*client_args)
Matthew Treinish72ea4422013-02-07 14:42:49 -0500216 self.image_client = ImageClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500217 self.container_client = ContainerClient(*client_args)
218 self.object_client = ObjectClient(*client_args)
Attila Fazekasa23f5002012-10-23 19:32:45 +0200219 self.ec2api_client = APIClientEC2(*client_args)
220 self.s3_client = ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530221 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530222 self.custom_account_client = \
223 AccountClientCustomizedHeader(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500224
225
Jay Pipesff10d552012-04-06 14:18:50 -0400226class AltManager(Manager):
227
228 """
229 Manager object that uses the alt_XXX credentials for its
230 managed client objects
231 """
232
233 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400234 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100235 super(AltManager, self).__init__(conf.identity.alt_username,
236 conf.identity.alt_password,
237 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400238
239
240class AdminManager(Manager):
241
242 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100243 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400244 managed client objects
245 """
246
James E. Blaire6d8ee12013-01-18 21:33:45 +0000247 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400248 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100249 super(AdminManager, self).__init__(conf.identity.admin_username,
250 conf.identity.admin_password,
251 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000252 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400253
254
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100255class ComputeAdminManager(Manager):
256
257 """
258 Manager object that uses the compute_admin credentials for its
259 managed client objects
260 """
261
262 def __init__(self, interface='json'):
263 conf = config.TempestConfig()
264 base = super(ComputeAdminManager, self)
265 base.__init__(conf.compute_admin.username,
266 conf.compute_admin.password,
267 conf.compute_admin.tenant_name,
268 interface=interface)