blob: 7d314f3b9f082ec09c5a8f031214561115d33efe [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
dwallecke62b9f02012-10-10 23:34:42 -050023from tempest.services.compute.json.extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053024 ExtensionsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050025from tempest.services.compute.json.flavors_client import FlavorsClientJSON
26from tempest.services.compute.json.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053027 FloatingIPsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050028from tempest.services.compute.json.images_client import ImagesClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010029from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050030from tempest.services.compute.json.limits_client import LimitsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010031from tempest.services.compute.json.quotas_client import QuotasClientJSON
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
Attila Fazekas6968dd52013-02-15 17:05:53 +010034from tempest.services.compute.json.servers_client import ServersClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050035from tempest.services.compute.json.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053036 VolumesExtensionsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050037from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
38from tempest.services.compute.xml.flavors_client import FlavorsClientXML
39from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053040 FloatingIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050041from tempest.services.compute.xml.images_client import ImagesClientXML
42from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
43from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053044from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050045from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053046 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050047from tempest.services.compute.xml.servers_client import ServersClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050048from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053049 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010050from tempest.services.identity.json.identity_client import IdentityClientJSON
51from tempest.services.identity.json.identity_client import TokenClientJSON
52from tempest.services.identity.xml.identity_client import IdentityClientXML
53from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish72ea4422013-02-07 14:42:49 -050054from tempest.services.image.json.image_client import ImageClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050055from tempest.services.network.json.network_client import NetworkClient
dwalleck5d734432012-10-04 01:11:47 -050056from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +053057from tempest.services.object_storage.account_client import \
58 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +010059from tempest.services.object_storage.container_client import ContainerClient
60from tempest.services.object_storage.object_client import ObjectClient
61from tempest.services.object_storage.object_client import \
62 ObjectClientCustomizedHeader
63from tempest.services.volume.json.admin.volume_types_client import \
64 VolumeTypesClientJSON
65from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
66from tempest.services.volume.json.volumes_client import VolumesClientJSON
67from tempest.services.volume.xml.admin.volume_types_client import \
68 VolumeTypesClientXML
69from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
70from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +080071
Jay Pipes3f981df2012-03-27 18:59:44 -040072LOG = logging.getLogger(__name__)
73
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040074IMAGES_CLIENTS = {
75 "json": ImagesClientJSON,
76 "xml": ImagesClientXML,
77}
78
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040079KEYPAIRS_CLIENTS = {
80 "json": KeyPairsClientJSON,
81 "xml": KeyPairsClientXML,
82}
83
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053084QUOTAS_CLIENTS = {
85 "json": QuotasClientJSON,
86 "xml": QuotasClientXML,
87}
88
Dan Smithcf8fab62012-08-14 08:03:48 -070089SERVERS_CLIENTS = {
90 "json": ServersClientJSON,
91 "xml": ServersClientXML,
92}
93
Matthew Treinish33634462012-08-16 16:51:23 -040094LIMITS_CLIENTS = {
95 "json": LimitsClientJSON,
96 "xml": LimitsClientXML,
97}
98
Tiago Melloeda03b52012-08-22 23:47:29 -030099FLAVORS_CLIENTS = {
100 "json": FlavorsClientJSON,
101 "xml": FlavorsClientXML
102}
103
Tiago Mello89126c32012-08-27 11:14:03 -0300104EXTENSIONS_CLIENTS = {
105 "json": ExtensionsClientJSON,
106 "xml": ExtensionsClientXML
107}
108
Matthew Treinish4e086902012-08-17 17:52:22 -0400109VOLUMES_EXTENSIONS_CLIENTS = {
110 "json": VolumesExtensionsClientJSON,
111 "xml": VolumesExtensionsClientXML,
112}
113
Vincent Hou22f03c72012-08-24 17:55:13 +0800114FLOAT_CLIENTS = {
115 "json": FloatingIPsClientJSON,
116 "xml": FloatingIPsClientXML,
117}
118
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100119SNAPSHOTS_CLIENTS = {
120 "json": SnapshotsClientJSON,
121 "xml": SnapshotsClientXML,
122}
123
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400124VOLUMES_CLIENTS = {
125 "json": VolumesClientJSON,
126 "xml": VolumesClientXML,
127}
128
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100129VOLUME_TYPES_CLIENTS = {
130 "json": VolumeTypesClientJSON,
131 "xml": VolumeTypesClientXML,
132}
133
Attila Fazekas407b6db2013-01-19 12:48:36 +0100134IDENTITY_CLIENT = {
135 "json": IdentityClientJSON,
136 "xml": IdentityClientXML,
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800137}
138
139TOKEN_CLIENT = {
140 "json": TokenClientJSON,
141 "xml": TokenClientXML,
142}
143
Vincent Houead03dc2012-08-24 21:35:11 +0800144SECURITY_GROUPS_CLIENT = {
145 "json": SecurityGroupsClientJSON,
146 "xml": SecurityGroupsClientXML,
147}
148
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800149
Daryl Walleck1465d612011-11-02 02:22:15 -0500150class Manager(object):
151
Jay Pipes3f981df2012-03-27 18:59:44 -0400152 """
153 Top level manager for OpenStack Compute clients
154 """
155
James E. Blaire6d8ee12013-01-18 21:33:45 +0000156 def __init__(self, username=None, password=None, tenant_name=None,
157 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400158 """
159 We allow overriding of the credentials used within the various
160 client classes managed by the Manager object. Left as None, the
161 standard username/password/tenant_name is used.
162
163 :param username: Override of the username
164 :param password: Override of the password
165 :param tenant_name: Override of the tenant name
166 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400167 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800168
Jay Pipesf38eaac2012-06-21 13:37:35 -0400169 # If no creds are provided, we fall back on the defaults
170 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100171 self.username = username or self.config.identity.username
172 self.password = password or self.config.identity.password
173 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500174
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700175 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400176 msg = ("Missing required credentials. "
177 "username: %(username)s, password: %(password)s, "
178 "tenant_name: %(tenant_name)s") % locals()
179 raise exceptions.InvalidConfiguration(msg)
180
Jay Pipes7c88eb22013-01-16 21:32:43 -0500181 self.auth_url = self.config.identity.uri
Daryl Walleck587385b2012-03-03 13:00:26 -0600182
183 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700184 client_args = (self.config, self.username, self.password,
185 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500186 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700187 client_args = (self.config, self.username, self.password,
188 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600189
Dan Smithcf8fab62012-08-14 08:03:48 -0700190 try:
191 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400192 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400193 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400194 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +0530195 self.quotas_client = QUOTAS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300196 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800197 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
198 self.extensions_client = ext_cli
199 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
200 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800201 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100202 self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400203 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100204 self.volume_types_client = \
205 VOLUME_TYPES_CLIENTS[interface](*client_args)
Attila Fazekas407b6db2013-01-19 12:48:36 +0100206 self.identity_client = IDENTITY_CLIENT[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800207 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800208 self.security_groups_client = \
209 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700210 except KeyError:
211 msg = "Unsupported interface type `%s'" % interface
212 raise exceptions.InvalidConfiguration(msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530213 self.network_client = NetworkClient(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500214 self.account_client = AccountClient(*client_args)
Matthew Treinish72ea4422013-02-07 14:42:49 -0500215 self.image_client = ImageClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500216 self.container_client = ContainerClient(*client_args)
217 self.object_client = ObjectClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100218 self.ec2api_client = botoclients.APIClientEC2(*client_args)
219 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530220 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530221 self.custom_account_client = \
222 AccountClientCustomizedHeader(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500223
224
Jay Pipesff10d552012-04-06 14:18:50 -0400225class AltManager(Manager):
226
227 """
228 Manager object that uses the alt_XXX credentials for its
229 managed client objects
230 """
231
232 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400233 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100234 super(AltManager, self).__init__(conf.identity.alt_username,
235 conf.identity.alt_password,
236 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400237
238
239class AdminManager(Manager):
240
241 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100242 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400243 managed client objects
244 """
245
James E. Blaire6d8ee12013-01-18 21:33:45 +0000246 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400247 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100248 super(AdminManager, self).__init__(conf.identity.admin_username,
249 conf.identity.admin_password,
250 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000251 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400252
253
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100254class ComputeAdminManager(Manager):
255
256 """
257 Manager object that uses the compute_admin credentials for its
258 managed client objects
259 """
260
261 def __init__(self, interface='json'):
262 conf = config.TempestConfig()
263 base = super(ComputeAdminManager, self)
264 base.__init__(conf.compute_admin.username,
265 conf.compute_admin.password,
266 conf.compute_admin.tenant_name,
267 interface=interface)