blob: c8bd238873c5686bda0421faa1b61e32c66f24fd [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 \
Vincent Houead03dc2012-08-24 21:35:11 +080036import SecurityGroupsClientJSON
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
Vincent Houead03dc2012-08-24 21:35:11 +080049from tempest.services.nova.xml.security_groups_client \
50import SecurityGroupsClientXML
Dan Smithcf8fab62012-08-14 08:03:48 -070051from tempest.services.nova.xml.servers_client import ServersClientXML
Matthew Treinish4e086902012-08-17 17:52:22 -040052from tempest.services.nova.xml.volumes_extensions_client \
53import VolumesExtensionsClientXML
Matthew Treinish9854d5b2012-09-20 10:22:13 -040054from tempest.services.volume.json.volumes_client import VolumesClientJSON
55from tempest.services.volume.xml.volumes_client import VolumesClientXML
Daryl Walleck1465d612011-11-02 02:22:15 -050056
Vincent Hou6b8a7b72012-08-25 01:24:33 +080057
Jay Pipes3f981df2012-03-27 18:59:44 -040058LOG = logging.getLogger(__name__)
59
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040060IMAGES_CLIENTS = {
61 "json": ImagesClientJSON,
62 "xml": ImagesClientXML,
63}
64
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040065KEYPAIRS_CLIENTS = {
66 "json": KeyPairsClientJSON,
67 "xml": KeyPairsClientXML,
68}
69
Dan Smithcf8fab62012-08-14 08:03:48 -070070SERVERS_CLIENTS = {
71 "json": ServersClientJSON,
72 "xml": ServersClientXML,
73}
74
Matthew Treinish33634462012-08-16 16:51:23 -040075LIMITS_CLIENTS = {
76 "json": LimitsClientJSON,
77 "xml": LimitsClientXML,
78}
79
Tiago Melloeda03b52012-08-22 23:47:29 -030080FLAVORS_CLIENTS = {
81 "json": FlavorsClientJSON,
82 "xml": FlavorsClientXML
83}
84
Tiago Mello89126c32012-08-27 11:14:03 -030085EXTENSIONS_CLIENTS = {
86 "json": ExtensionsClientJSON,
87 "xml": ExtensionsClientXML
88}
89
Matthew Treinish4e086902012-08-17 17:52:22 -040090VOLUMES_EXTENSIONS_CLIENTS = {
91 "json": VolumesExtensionsClientJSON,
92 "xml": VolumesExtensionsClientXML,
93}
94
Vincent Hou22f03c72012-08-24 17:55:13 +080095FLOAT_CLIENTS = {
96 "json": FloatingIPsClientJSON,
97 "xml": FloatingIPsClientXML,
98}
99
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400100VOLUMES_CLIENTS = {
101 "json": VolumesClientJSON,
102 "xml": VolumesClientXML,
103}
104
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800105ADMIN_CLIENT = {
106 "json": AdminClientJSON,
107 "xml": AdminClientXML,
108}
109
110TOKEN_CLIENT = {
111 "json": TokenClientJSON,
112 "xml": TokenClientXML,
113}
114
Vincent Houead03dc2012-08-24 21:35:11 +0800115SECURITY_GROUPS_CLIENT = {
116 "json": SecurityGroupsClientJSON,
117 "xml": SecurityGroupsClientXML,
118}
119
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800120
Daryl Walleck1465d612011-11-02 02:22:15 -0500121class Manager(object):
122
Jay Pipes3f981df2012-03-27 18:59:44 -0400123 """
124 Top level manager for OpenStack Compute clients
125 """
126
Dan Smithcf8fab62012-08-14 08:03:48 -0700127 def __init__(self, username=None, password=None, tenant_name=None,
128 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400129 """
130 We allow overriding of the credentials used within the various
131 client classes managed by the Manager object. Left as None, the
132 standard username/password/tenant_name is used.
133
134 :param username: Override of the username
135 :param password: Override of the password
136 :param tenant_name: Override of the tenant name
137 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400138 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800139
Jay Pipesf38eaac2012-06-21 13:37:35 -0400140 # If no creds are provided, we fall back on the defaults
141 # in the config file for the Compute API.
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700142 self.username = username or self.config.compute.username
143 self.password = password or self.config.compute.password
144 self.tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500145
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700146 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400147 msg = ("Missing required credentials. "
148 "username: %(username)s, password: %(password)s, "
149 "tenant_name: %(tenant_name)s") % locals()
150 raise exceptions.InvalidConfiguration(msg)
151
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700152 self.auth_url = self.config.identity.auth_url
Daryl Walleck587385b2012-03-03 13:00:26 -0600153
154 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700155 client_args = (self.config, self.username, self.password,
156 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500157 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700158 client_args = (self.config, self.username, self.password,
159 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600160
Dan Smithcf8fab62012-08-14 08:03:48 -0700161 try:
162 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400163 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400164 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400165 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300166 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800167 ext_cli = EXTENSIONS_CLIENTS[interface](*client_args)
168 self.extensions_client = ext_cli
169 vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
170 self.volumes_extensions_client = vol_ext_cli
Vincent Hou22f03c72012-08-24 17:55:13 +0800171 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400172 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800173 self.admin_client = ADMIN_CLIENT[interface](*client_args)
174 self.token_client = TOKEN_CLIENT[interface](self.config)
Vincent Houead03dc2012-08-24 21:35:11 +0800175 self.security_groups_client = \
176 SECURITY_GROUPS_CLIENT[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700177 except KeyError:
178 msg = "Unsupported interface type `%s'" % interface
179 raise exceptions.InvalidConfiguration(msg)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530180 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530181 self.network_client = NetworkClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500182
183
Jay Pipesff10d552012-04-06 14:18:50 -0400184class AltManager(Manager):
185
186 """
187 Manager object that uses the alt_XXX credentials for its
188 managed client objects
189 """
190
191 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400192 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400193 super(AltManager, self).__init__(conf.compute.alt_username,
194 conf.compute.alt_password,
195 conf.compute.alt_tenant_name)
196
197
198class AdminManager(Manager):
199
200 """
201 Manager object that uses the alt_XXX credentials for its
202 managed client objects
203 """
204
Tiago Melloeda03b52012-08-22 23:47:29 -0300205 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400206 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400207 super(AdminManager, self).__init__(conf.compute_admin.username,
208 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300209 conf.compute_admin.tenant_name,
210 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400211
212
Jay Pipes50677282012-01-06 15:39:20 -0500213class ServiceManager(object):
214
215 """
216 Top-level object housing clients for OpenStack APIs
217 """
218
219 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400220 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500221 self.services = {}
222 self.services['image'] = image_service.Service(self.config)
223 self.images = self.services['image']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800224
225
226class IdentityManager(Manager):
227
228 """
229 Manager object that uses the alt_XXX credentials for its
230 managed client objects
231 """
232
233 def __init__(self, interface='json'):
234 conf = config.TempestConfig()
235 super(IdentityManager, self).__init__(conf.identity_admin.username,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800236 conf.identity_admin.password,
237 conf.identity_admin.tenant_name,
238 interface)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800239
240
241class IdentityNaManager(Manager):
242
243 """
244 Manager object that uses the alt_XXX credentials for its
245 managed client objects
246 """
247
248 def __init__(self, interface='json'):
249 conf = config.TempestConfig()
250 super(IdentityNaManager, self).__init__(conf.compute.username,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800251 conf.compute.password,
252 conf.compute.tenant_name,
253 interface)