blob: cfe8a5cb9064325fb452a8131fac9f74fab47333 [file] [log] [blame]
Jay Pipes051075a2012-04-28 17:39:37 -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
20# Default client libs
Brian Waldonc9b99a22012-09-10 09:24:35 -070021import glanceclient
Maru Newbydec13ec2012-08-30 11:19:17 -070022import keystoneclient.v2_0.client
23import novaclient.client
Dan Princebff52232012-10-10 11:40:55 -040024try:
25 import quantumclient.v2_0.client
26except ImportError:
27 pass
Jay Pipes051075a2012-04-28 17:39:37 -040028
29import tempest.config
30from tempest import exceptions
31# Tempest REST Fuzz testing client libs
Matthew Treinisha83a16e2012-12-07 13:44:02 -050032from tempest.services.compute.json import console_output_client
33from tempest.services.compute.json import extensions_client
34from tempest.services.compute.json import flavors_client
35from tempest.services.compute.json import floating_ips_client
36from tempest.services.compute.json import images_client
37from tempest.services.compute.json import keypairs_client
38from tempest.services.compute.json import limits_client
39from tempest.services.compute.json import quotas_client
40from tempest.services.compute.json import security_groups_client
41from tempest.services.compute.json import servers_client
42from tempest.services.compute.json import volumes_extensions_client
Jay Pipes051075a2012-04-28 17:39:37 -040043from tempest.services.network.json import network_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070044from tempest.services.volume.json import volumes_client
Jay Pipes051075a2012-04-28 17:39:37 -040045
46NetworkClient = network_client.NetworkClient
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040047ImagesClient = images_client.ImagesClientJSON
Tiago Melloeda03b52012-08-22 23:47:29 -030048FlavorsClient = flavors_client.FlavorsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070049ServersClient = servers_client.ServersClientJSON
Matthew Treinish33634462012-08-16 16:51:23 -040050LimitsClient = limits_client.LimitsClientJSON
Tiago Mello89126c32012-08-27 11:14:03 -030051ExtensionsClient = extensions_client.ExtensionsClientJSON
Vincent Hou22f03c72012-08-24 17:55:13 +080052FloatingIPsClient = floating_ips_client.FloatingIPsClientJSON
Vincent Houead03dc2012-08-24 21:35:11 +080053SecurityGroupsClient = security_groups_client.SecurityGroupsClientJSON
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040054KeyPairsClient = keypairs_client.KeyPairsClientJSON
Matthew Treinish4e086902012-08-17 17:52:22 -040055VolumesExtensionsClient = volumes_extensions_client.VolumesExtensionsClientJSON
Matthew Treinish9854d5b2012-09-20 10:22:13 -040056VolumesClient = volumes_client.VolumesClientJSON
rajalakshmi-ganesand793d692012-12-25 12:54:50 +053057ConsoleOutputsClient = console_output_client.ConsoleOutputsClientJSON
Rohit Karajgi07599c52012-11-02 05:35:16 -070058QuotasClient = quotas_client.QuotasClient
Jay Pipes051075a2012-04-28 17:39:37 -040059
60LOG = logging.getLogger(__name__)
61
62
63class Manager(object):
64
65 """
66 Base manager class
67
68 Manager objects are responsible for providing a configuration object
69 and a client object for a test case to use in performing actions.
70 """
71
72 def __init__(self):
73 self.config = tempest.config.TempestConfig()
Maru Newbydec13ec2012-08-30 11:19:17 -070074 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040075
76
77class FuzzClientManager(Manager):
78
79 """
80 Manager class that indicates the client provided by the manager
81 is a fuzz-testing client that Tempest contains. These fuzz-testing
82 clients are used to be able to throw random or invalid data at
83 an endpoint and check for appropriate error messages returned
84 from the endpoint.
85 """
86 pass
87
88
Maru Newbydec13ec2012-08-30 11:19:17 -070089class DefaultClientManager(Manager):
Jay Pipes051075a2012-04-28 17:39:37 -040090
91 """
Maru Newbydec13ec2012-08-30 11:19:17 -070092 Manager that provides the default clients to access the various
93 OpenStack APIs.
Jay Pipes051075a2012-04-28 17:39:37 -040094 """
95
96 NOVACLIENT_VERSION = '2'
97
98 def __init__(self):
Maru Newbydec13ec2012-08-30 11:19:17 -070099 super(DefaultClientManager, self).__init__()
100 self.compute_client = self._get_compute_client()
101 self.image_client = self._get_image_client()
102 self.identity_client = self._get_identity_client()
103 self.network_client = self._get_network_client()
104 self.client_attr_names = [
105 'compute_client',
106 'image_client',
107 'identity_client',
108 'network_client',
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900109 ]
Maru Newbydec13ec2012-08-30 11:19:17 -0700110
111 def _get_compute_client(self, username=None, password=None,
112 tenant_name=None):
113 # Novaclient will not execute operations for anyone but the
114 # identified user, so a new client needs to be created for
115 # each user that operations need to be performed for.
116 if not username:
117 username = self.config.compute.username
118 if not password:
119 password = self.config.compute.password
120 if not tenant_name:
121 tenant_name = self.config.compute.tenant_name
Jay Pipes051075a2012-04-28 17:39:37 -0400122
123 if None in (username, password, tenant_name):
Maru Newbydec13ec2012-08-30 11:19:17 -0700124 msg = ("Missing required credentials for compute client. "
Jay Pipes051075a2012-04-28 17:39:37 -0400125 "username: %(username)s, password: %(password)s, "
126 "tenant_name: %(tenant_name)s") % locals()
127 raise exceptions.InvalidConfiguration(msg)
128
129 # Novaclient adds a /tokens/ part to the auth URL automatically
130 auth_url = self.config.identity.auth_url.rstrip('tokens')
Jay Pipescd8eaec2013-01-16 21:03:48 -0500131 dscv = self.config.identity.disable_ssl_certificate_validation
Jay Pipes051075a2012-04-28 17:39:37 -0400132
133 client_args = (username, password, tenant_name, auth_url)
134
135 # Create our default Nova client to use in testing
Jay Pipes444c3e62012-10-04 19:26:35 -0400136 service_type = self.config.compute.catalog_type
Maru Newbydec13ec2012-08-30 11:19:17 -0700137 return novaclient.client.Client(self.NOVACLIENT_VERSION,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800138 *client_args,
139 service_type=service_type,
Jay Pipescd8eaec2013-01-16 21:03:48 -0500140 no_cache=True,
141 insecure=dscv)
Jay Pipes051075a2012-04-28 17:39:37 -0400142
Maru Newbydec13ec2012-08-30 11:19:17 -0700143 def _get_image_client(self):
Brian Waldonc9b99a22012-09-10 09:24:35 -0700144 keystone = self._get_identity_client()
145 token = keystone.auth_token
146 endpoint = keystone.service_catalog.url_for(service_type='image',
147 endpoint_type='publicURL')
Jay Pipescd8eaec2013-01-16 21:03:48 -0500148 dscv = self.config.identity.disable_ssl_certificate_validation
149 return glanceclient.Client('1', endpoint=endpoint, token=token,
150 insecure=dscv)
Maru Newbydec13ec2012-08-30 11:19:17 -0700151
Maru Newby81f07a02012-09-05 20:21:19 -0700152 def _get_identity_client(self, username=None, password=None,
153 tenant_name=None):
Maru Newbydec13ec2012-08-30 11:19:17 -0700154 # This identity client is not intended to check the security
Maru Newby81f07a02012-09-05 20:21:19 -0700155 # of the identity service, so use admin credentials by default.
156 if not username:
157 username = self.config.identity_admin.username
158 if not password:
159 password = self.config.identity_admin.password
160 if not tenant_name:
161 tenant_name = self.config.identity_admin.tenant_name
Maru Newbydec13ec2012-08-30 11:19:17 -0700162
163 if None in (username, password, tenant_name):
164 msg = ("Missing required credentials for identity client. "
165 "username: %(username)s, password: %(password)s, "
166 "tenant_name: %(tenant_name)s") % locals()
167 raise exceptions.InvalidConfiguration(msg)
168
169 auth_url = self.config.identity.auth_url.rstrip('tokens')
Jay Pipescd8eaec2013-01-16 21:03:48 -0500170 dscv = self.config.identity.disable_ssl_certificate_validation
Maru Newbydec13ec2012-08-30 11:19:17 -0700171
172 return keystoneclient.v2_0.client.Client(username=username,
173 password=password,
174 tenant_name=tenant_name,
Jay Pipescd8eaec2013-01-16 21:03:48 -0500175 auth_url=auth_url,
176 insecure=dscv)
Maru Newbydec13ec2012-08-30 11:19:17 -0700177
178 def _get_network_client(self):
Maru Newbyb72f37c2012-12-14 02:17:06 +0000179 # The intended configuration is for the network client to have
180 # admin privileges and indicate for whom resources are being
181 # created via a 'tenant_id' parameter. This will often be
182 # preferable to authenticating as a specific user because
183 # working with certain resources (public routers and networks)
184 # often requires admin privileges anyway.
185 username = self.config.network_admin.username
186 password = self.config.network_admin.password
187 tenant_name = self.config.network_admin.tenant_name
Maru Newbydec13ec2012-08-30 11:19:17 -0700188
189 if None in (username, password, tenant_name):
190 msg = ("Missing required credentials for network client. "
191 "username: %(username)s, password: %(password)s, "
192 "tenant_name: %(tenant_name)s") % locals()
193 raise exceptions.InvalidConfiguration(msg)
194
195 auth_url = self.config.identity.auth_url.rstrip('tokens')
Jay Pipescd8eaec2013-01-16 21:03:48 -0500196 dscv = self.config.identity.disable_ssl_certificate_validation
Maru Newbydec13ec2012-08-30 11:19:17 -0700197
198 return quantumclient.v2_0.client.Client(username=username,
199 password=password,
200 tenant_name=tenant_name,
Jay Pipescd8eaec2013-01-16 21:03:48 -0500201 auth_url=auth_url,
202 insecure=dscv)
Jay Pipes051075a2012-04-28 17:39:37 -0400203
204
205class ComputeFuzzClientManager(FuzzClientManager):
206
207 """
208 Manager that uses the Tempest REST client that can send
209 random or invalid data at the OpenStack Compute API
210 """
211
212 def __init__(self, username=None, password=None, tenant_name=None):
213 """
214 We allow overriding of the credentials used within the various
215 client classes managed by the Manager object. Left as None, the
216 standard username/password/tenant_name is used.
217
218 :param username: Override of the username
219 :param password: Override of the password
220 :param tenant_name: Override of the tenant name
221 """
222 super(ComputeFuzzClientManager, self).__init__()
223
224 # If no creds are provided, we fall back on the defaults
225 # in the config file for the Compute API.
226 username = username or self.config.compute.username
227 password = password or self.config.compute.password
228 tenant_name = tenant_name or self.config.compute.tenant_name
229
230 if None in (username, password, tenant_name):
231 msg = ("Missing required credentials. "
232 "username: %(username)s, password: %(password)s, "
233 "tenant_name: %(tenant_name)s") % locals()
234 raise exceptions.InvalidConfiguration(msg)
235
236 auth_url = self.config.identity.auth_url
237
238 if self.config.identity.strategy == 'keystone':
239 client_args = (self.config, username, password, auth_url,
240 tenant_name)
241 else:
242 client_args = (self.config, username, password, auth_url)
243
244 self.servers_client = ServersClient(*client_args)
245 self.flavors_client = FlavorsClient(*client_args)
246 self.images_client = ImagesClient(*client_args)
247 self.limits_client = LimitsClient(*client_args)
248 self.extensions_client = ExtensionsClient(*client_args)
249 self.keypairs_client = KeyPairsClient(*client_args)
250 self.security_groups_client = SecurityGroupsClient(*client_args)
251 self.floating_ips_client = FloatingIPsClient(*client_args)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700252 self.volumes_extensions_client = VolumesExtensionsClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400253 self.volumes_client = VolumesClient(*client_args)
254 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700255 self.quotas_client = QuotasClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400256 self.network_client = NetworkClient(*client_args)
257
258
259class ComputeFuzzClientAltManager(Manager):
260
261 """
262 Manager object that uses the alt_XXX credentials for its
263 managed client objects
264 """
265
266 def __init__(self):
267 conf = tempest.config.TempestConfig()
268 super(ComputeFuzzClientAltManager, self).__init__(
rajalakshmi-ganesand793d692012-12-25 12:54:50 +0530269 conf.compute.alt_username,
270 conf.compute.alt_password,
271 conf.compute.alt_tenant_name)
Jay Pipes051075a2012-04-28 17:39:37 -0400272
273
274class ComputeFuzzClientAdminManager(Manager):
275
276 """
277 Manager object that uses the alt_XXX credentials for its
278 managed client objects
279 """
280
281 def __init__(self):
282 conf = tempest.config.TempestConfig()
283 super(ComputeFuzzClientAdminManager, self).__init__(
rajalakshmi-ganesand793d692012-12-25 12:54:50 +0530284 conf.compute_admin.username,
285 conf.compute_admin.password,
286 conf.compute_admin.tenant_name)