blob: 35562b1e7610af4ebc50c989865f25678f9b24a8 [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
Vincent Hou6b8a7b72012-08-25 01:24:33 +080022from tempest.services.identity.json.admin_client import AdminClientJSON
23from tempest.services.identity.json.admin_client import TokenClientJSON
24from tempest.services.identity.xml.admin_client import AdminClientXML
25from tempest.services.identity.xml.admin_client import TokenClientXML
Jay Pipes50677282012-01-06 15:39:20 -050026from tempest.services.image import service as image_service
Unmesh Gurjar44986832012-05-08 19:57:10 +053027from tempest.services.network.json.network_client import NetworkClient
dwallecke62b9f02012-10-10 23:34:42 -050028from tempest.services.compute.json.extensions_client import \
29ExtensionsClientJSON
30from tempest.services.compute.json.flavors_client import FlavorsClientJSON
31from tempest.services.compute.json.floating_ips_client import \
Vincent Hou22f03c72012-08-24 17:55:13 +080032FloatingIPsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050033from tempest.services.compute.json.images_client import ImagesClientJSON
34from tempest.services.compute.json.limits_client import LimitsClientJSON
35from tempest.services.compute.json.servers_client import ServersClientJSON
36from tempest.services.compute.json.security_groups_client \
Vincent Houead03dc2012-08-24 21:35:11 +080037import SecurityGroupsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050038from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
39from tempest.services.compute.json.volumes_extensions_client \
Matthew Treinish4e086902012-08-17 17:52:22 -040040import VolumesExtensionsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050041from tempest.services.compute.json.console_output_client \
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053042import ConsoleOutputsClient
dwallecke62b9f02012-10-10 23:34:42 -050043from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
44from tempest.services.compute.xml.flavors_client import FlavorsClientXML
45from tempest.services.compute.xml.floating_ips_client import \
Vincent Hou22f03c72012-08-24 17:55:13 +080046FloatingIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050047from tempest.services.compute.xml.images_client import ImagesClientXML
48from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
49from tempest.services.compute.xml.limits_client import LimitsClientXML
50from tempest.services.compute.xml.security_groups_client \
Vincent Houead03dc2012-08-24 21:35:11 +080051import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050052from tempest.services.compute.xml.servers_client import ServersClientXML
53from tempest.services.compute.xml.volumes_extensions_client \
Matthew Treinish4e086902012-08-17 17:52:22 -040054import VolumesExtensionsClientXML
Matthew Treinish9854d5b2012-09-20 10:22:13 -040055from tempest.services.volume.json.volumes_client import VolumesClientJSON
56from tempest.services.volume.xml.volumes_client import VolumesClientXML
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
Daryl Walleck1465d612011-11-02 02:22:15 -050060
Vincent Hou6b8a7b72012-08-25 01:24:33 +080061
Jay Pipes3f981df2012-03-27 18:59:44 -040062LOG = logging.getLogger(__name__)
63
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040064IMAGES_CLIENTS = {
65 "json": ImagesClientJSON,
66 "xml": ImagesClientXML,
67}
68
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040069KEYPAIRS_CLIENTS = {
70 "json": KeyPairsClientJSON,
71 "xml": KeyPairsClientXML,
72}
73
Dan Smithcf8fab62012-08-14 08:03:48 -070074SERVERS_CLIENTS = {
75 "json": ServersClientJSON,
76 "xml": ServersClientXML,
77}
78
Matthew Treinish33634462012-08-16 16:51:23 -040079LIMITS_CLIENTS = {
80 "json": LimitsClientJSON,
81 "xml": LimitsClientXML,
82}
83
Tiago Melloeda03b52012-08-22 23:47:29 -030084FLAVORS_CLIENTS = {
85 "json": FlavorsClientJSON,
86 "xml": FlavorsClientXML
87}
88
Tiago Mello89126c32012-08-27 11:14:03 -030089EXTENSIONS_CLIENTS = {
90 "json": ExtensionsClientJSON,
91 "xml": ExtensionsClientXML
92}
93
Matthew Treinish4e086902012-08-17 17:52:22 -040094VOLUMES_EXTENSIONS_CLIENTS = {
95 "json": VolumesExtensionsClientJSON,
96 "xml": VolumesExtensionsClientXML,
97}
98
Vincent Hou22f03c72012-08-24 17:55:13 +080099FLOAT_CLIENTS = {
100 "json": FloatingIPsClientJSON,
101 "xml": FloatingIPsClientXML,
102}
103
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400104VOLUMES_CLIENTS = {
105 "json": VolumesClientJSON,
106 "xml": VolumesClientXML,
107}
108
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800109ADMIN_CLIENT = {
110 "json": AdminClientJSON,
111 "xml": AdminClientXML,
112}
113
114TOKEN_CLIENT = {
115 "json": TokenClientJSON,
116 "xml": TokenClientXML,
117}
118
Vincent Houead03dc2012-08-24 21:35:11 +0800119SECURITY_GROUPS_CLIENT = {
120 "json": SecurityGroupsClientJSON,
121 "xml": SecurityGroupsClientXML,
122}
123
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800124
Daryl Walleck1465d612011-11-02 02:22:15 -0500125class Manager(object):
126
Jay Pipes3f981df2012-03-27 18:59:44 -0400127 """
128 Top level manager for OpenStack Compute clients
129 """
130
Dan Smithcf8fab62012-08-14 08:03:48 -0700131 def __init__(self, username=None, password=None, tenant_name=None,
132 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400133 """
134 We allow overriding of the credentials used within the various
135 client classes managed by the Manager object. Left as None, the
136 standard username/password/tenant_name is used.
137
138 :param username: Override of the username
139 :param password: Override of the password
140 :param tenant_name: Override of the tenant name
141 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400142 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800143
Jay Pipesf38eaac2012-06-21 13:37:35 -0400144 # If no creds are provided, we fall back on the defaults
145 # in the config file for the Compute API.
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700146 self.username = username or self.config.compute.username
147 self.password = password or self.config.compute.password
148 self.tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500149
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700150 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400151 msg = ("Missing required credentials. "
152 "username: %(username)s, password: %(password)s, "
153 "tenant_name: %(tenant_name)s") % locals()
154 raise exceptions.InvalidConfiguration(msg)
155
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700156 self.auth_url = self.config.identity.auth_url
Daryl Walleck587385b2012-03-03 13:00:26 -0600157
158 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700159 client_args = (self.config, self.username, self.password,
160 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500161 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700162 client_args = (self.config, self.username, self.password,
163 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600164
Dan Smithcf8fab62012-08-14 08:03:48 -0700165 try:
166 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400167 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400168 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400169 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300170 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800171 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
172 self.extensions_client = ext_cli
173 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
174 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800175 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400176 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800177 self.admin_client = ADMIN_CLIENT[interface](*client_args)
178 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800179 self.security_groups_client = \
180 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700181 except KeyError:
182 msg = "Unsupported interface type `%s'" % interface
183 raise exceptions.InvalidConfiguration(msg)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530184 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530185 self.network_client = NetworkClient(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500186 self.account_client = AccountClient(*client_args)
187 self.container_client = ContainerClient(*client_args)
188 self.object_client = ObjectClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500189
190
Jay Pipesff10d552012-04-06 14:18:50 -0400191class AltManager(Manager):
192
193 """
194 Manager object that uses the alt_XXX credentials for its
195 managed client objects
196 """
197
198 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400199 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400200 super(AltManager, self).__init__(conf.compute.alt_username,
201 conf.compute.alt_password,
202 conf.compute.alt_tenant_name)
203
204
205class AdminManager(Manager):
206
207 """
208 Manager object that uses the alt_XXX credentials for its
209 managed client objects
210 """
211
Tiago Melloeda03b52012-08-22 23:47:29 -0300212 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400213 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400214 super(AdminManager, self).__init__(conf.compute_admin.username,
215 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300216 conf.compute_admin.tenant_name,
217 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400218
219
Jay Pipes50677282012-01-06 15:39:20 -0500220class ServiceManager(object):
221
222 """
223 Top-level object housing clients for OpenStack APIs
224 """
225
226 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400227 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500228 self.services = {}
229 self.services['image'] = image_service.Service(self.config)
230 self.images = self.services['image']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800231
232
233class IdentityManager(Manager):
234
235 """
236 Manager object that uses the alt_XXX credentials for its
237 managed client objects
238 """
239
240 def __init__(self, interface='json'):
241 conf = config.TempestConfig()
242 super(IdentityManager, self).__init__(conf.identity_admin.username,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800243 conf.identity_admin.password,
244 conf.identity_admin.tenant_name,
245 interface)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800246
247
248class IdentityNaManager(Manager):
249
250 """
251 Manager object that uses the alt_XXX credentials for its
252 managed client objects
253 """
254
255 def __init__(self, interface='json'):
256 conf = config.TempestConfig()
257 super(IdentityNaManager, self).__init__(conf.compute.username,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800258 conf.compute.password,
259 conf.compute.tenant_name,
260 interface)