blob: d9cb0a156f4c5c49341d17c63fd094483f7512b2 [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
Tiago Mello89126c32012-08-27 11:14:03 -030028from tempest.services.nova.json.extensions_client import ExtensionsClientJSON
Tiago Melloeda03b52012-08-22 23:47:29 -030029from tempest.services.nova.json.flavors_client import FlavorsClientJSON
Vincent Hou22f03c72012-08-24 17:55:13 +080030from tempest.services.nova.json.floating_ips_client import \
31FloatingIPsClientJSON
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040032from tempest.services.nova.json.images_client import ImagesClientJSON
Matthew Treinish33634462012-08-16 16:51:23 -040033from tempest.services.nova.json.limits_client import LimitsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070034from tempest.services.nova.json.servers_client import ServersClientJSON
Ravikumar Venkatesanaf7ab1c2012-01-17 12:54:22 -080035from tempest.services.nova.json.security_groups_client \
36import SecurityGroupsClient
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040037from tempest.services.nova.json.keypairs_client import KeyPairsClientJSON
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070038from tempest.services.nova.json.volumes_extensions_client \
Matthew Treinish4e086902012-08-17 17:52:22 -040039import VolumesExtensionsClientJSON
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053040from tempest.services.nova.json.console_output_client \
41import ConsoleOutputsClient
Tiago Mello89126c32012-08-27 11:14:03 -030042from tempest.services.nova.xml.extensions_client import ExtensionsClientXML
Tiago Melloeda03b52012-08-22 23:47:29 -030043from tempest.services.nova.xml.flavors_client import FlavorsClientXML
Vincent Hou22f03c72012-08-24 17:55:13 +080044from tempest.services.nova.xml.floating_ips_client import \
45FloatingIPsClientXML
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040046from tempest.services.nova.xml.images_client import ImagesClientXML
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040047from tempest.services.nova.xml.keypairs_client import KeyPairsClientXML
Matthew Treinish33634462012-08-16 16:51:23 -040048from tempest.services.nova.xml.limits_client import LimitsClientXML
Dan Smithcf8fab62012-08-14 08:03:48 -070049from tempest.services.nova.xml.servers_client import ServersClientXML
Matthew Treinish4e086902012-08-17 17:52:22 -040050from tempest.services.nova.xml.volumes_extensions_client \
51import VolumesExtensionsClientXML
Matthew Treinish9854d5b2012-09-20 10:22:13 -040052from tempest.services.volume.json.volumes_client import VolumesClientJSON
53from tempest.services.volume.xml.volumes_client import VolumesClientXML
Daryl Walleck1465d612011-11-02 02:22:15 -050054
Vincent Hou6b8a7b72012-08-25 01:24:33 +080055
Jay Pipes3f981df2012-03-27 18:59:44 -040056LOG = logging.getLogger(__name__)
57
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040058IMAGES_CLIENTS = {
59 "json": ImagesClientJSON,
60 "xml": ImagesClientXML,
61}
62
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040063KEYPAIRS_CLIENTS = {
64 "json": KeyPairsClientJSON,
65 "xml": KeyPairsClientXML,
66}
67
Dan Smithcf8fab62012-08-14 08:03:48 -070068SERVERS_CLIENTS = {
69 "json": ServersClientJSON,
70 "xml": ServersClientXML,
71}
72
Matthew Treinish33634462012-08-16 16:51:23 -040073LIMITS_CLIENTS = {
74 "json": LimitsClientJSON,
75 "xml": LimitsClientXML,
76}
77
Tiago Melloeda03b52012-08-22 23:47:29 -030078FLAVORS_CLIENTS = {
79 "json": FlavorsClientJSON,
80 "xml": FlavorsClientXML
81}
82
Tiago Mello89126c32012-08-27 11:14:03 -030083EXTENSIONS_CLIENTS = {
84 "json": ExtensionsClientJSON,
85 "xml": ExtensionsClientXML
86}
87
Matthew Treinish4e086902012-08-17 17:52:22 -040088VOLUMES_EXTENSIONS_CLIENTS = {
89 "json": VolumesExtensionsClientJSON,
90 "xml": VolumesExtensionsClientXML,
91}
92
Vincent Hou22f03c72012-08-24 17:55:13 +080093FLOAT_CLIENTS = {
94 "json": FloatingIPsClientJSON,
95 "xml": FloatingIPsClientXML,
96}
97
Matthew Treinish9854d5b2012-09-20 10:22:13 -040098VOLUMES_CLIENTS = {
99 "json": VolumesClientJSON,
100 "xml": VolumesClientXML,
101}
102
Daryl Walleck1465d612011-11-02 02:22:15 -0500103
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800104ADMIN_CLIENT = {
105 "json": AdminClientJSON,
106 "xml": AdminClientXML,
107}
108
109TOKEN_CLIENT = {
110 "json": TokenClientJSON,
111 "xml": TokenClientXML,
112}
113
114
Daryl Walleck1465d612011-11-02 02:22:15 -0500115class Manager(object):
116
Jay Pipes3f981df2012-03-27 18:59:44 -0400117 """
118 Top level manager for OpenStack Compute clients
119 """
120
Dan Smithcf8fab62012-08-14 08:03:48 -0700121 def __init__(self, username=None, password=None, tenant_name=None,
122 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400123 """
124 We allow overriding of the credentials used within the various
125 client classes managed by the Manager object. Left as None, the
126 standard username/password/tenant_name is used.
127
128 :param username: Override of the username
129 :param password: Override of the password
130 :param tenant_name: Override of the tenant name
131 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400132 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800133
Jay Pipesf38eaac2012-06-21 13:37:35 -0400134 # If no creds are provided, we fall back on the defaults
135 # in the config file for the Compute API.
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700136 self.username = username or self.config.compute.username
137 self.password = password or self.config.compute.password
138 self.tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500139
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700140 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400141 msg = ("Missing required credentials. "
142 "username: %(username)s, password: %(password)s, "
143 "tenant_name: %(tenant_name)s") % locals()
144 raise exceptions.InvalidConfiguration(msg)
145
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700146 self.auth_url = self.config.identity.auth_url
Daryl Walleck587385b2012-03-03 13:00:26 -0600147
148 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700149 client_args = (self.config, self.username, self.password,
150 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500151 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700152 client_args = (self.config, self.username, self.password,
153 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600154
Dan Smithcf8fab62012-08-14 08:03:48 -0700155 try:
156 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400157 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400158 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400159 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300160 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Tiago Mello89126c32012-08-27 11:14:03 -0300161 self.extensions_client = \
162 EXTENSIONS_CLIENTS[interface](*client_args)
Matthew Treinish4e086902012-08-17 17:52:22 -0400163 self.volumes_extensions_client = \
164 VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
Vincent Hou22f03c72012-08-24 17:55:13 +0800165 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400166 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800167 self.admin_client = ADMIN_CLIENT[interface](*client_args)
168 self.token_client = TOKEN_CLIENT[interface](self.config)
Dan Smithcf8fab62012-08-14 08:03:48 -0700169 except KeyError:
170 msg = "Unsupported interface type `%s'" % interface
171 raise exceptions.InvalidConfiguration(msg)
Daryl Walleck587385b2012-03-03 13:00:26 -0600172 self.security_groups_client = SecurityGroupsClient(*client_args)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530173 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530174 self.network_client = NetworkClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500175
176
Jay Pipesff10d552012-04-06 14:18:50 -0400177class AltManager(Manager):
178
179 """
180 Manager object that uses the alt_XXX credentials for its
181 managed client objects
182 """
183
184 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400185 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400186 super(AltManager, self).__init__(conf.compute.alt_username,
187 conf.compute.alt_password,
188 conf.compute.alt_tenant_name)
189
190
191class AdminManager(Manager):
192
193 """
194 Manager object that uses the alt_XXX credentials for its
195 managed client objects
196 """
197
Tiago Melloeda03b52012-08-22 23:47:29 -0300198 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400199 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400200 super(AdminManager, self).__init__(conf.compute_admin.username,
201 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300202 conf.compute_admin.tenant_name,
203 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400204
205
Jay Pipes50677282012-01-06 15:39:20 -0500206class ServiceManager(object):
207
208 """
209 Top-level object housing clients for OpenStack APIs
210 """
211
212 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400213 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500214 self.services = {}
215 self.services['image'] = image_service.Service(self.config)
216 self.images = self.services['image']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800217
218
219class IdentityManager(Manager):
220
221 """
222 Manager object that uses the alt_XXX credentials for its
223 managed client objects
224 """
225
226 def __init__(self, interface='json'):
227 conf = config.TempestConfig()
228 super(IdentityManager, self).__init__(conf.identity_admin.username,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800229 conf.identity_admin.password,
230 conf.identity_admin.tenant_name,
231 interface)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800232
233
234class IdentityNaManager(Manager):
235
236 """
237 Manager object that uses the alt_XXX credentials for its
238 managed client objects
239 """
240
241 def __init__(self, interface='json'):
242 conf = config.TempestConfig()
243 super(IdentityNaManager, self).__init__(conf.compute.username,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800244 conf.compute.password,
245 conf.compute.tenant_name,
246 interface)