blob: 513e5d9aaab8a37fb69cf3ba31db4fe7aee05fd7 [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')
131
132 client_args = (username, password, tenant_name, auth_url)
133
134 # Create our default Nova client to use in testing
Jay Pipes444c3e62012-10-04 19:26:35 -0400135 service_type = self.config.compute.catalog_type
Maru Newbydec13ec2012-08-30 11:19:17 -0700136 return novaclient.client.Client(self.NOVACLIENT_VERSION,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800137 *client_args,
138 service_type=service_type,
139 no_cache=True)
Jay Pipes051075a2012-04-28 17:39:37 -0400140
Maru Newbydec13ec2012-08-30 11:19:17 -0700141 def _get_image_client(self):
Brian Waldonc9b99a22012-09-10 09:24:35 -0700142 keystone = self._get_identity_client()
143 token = keystone.auth_token
144 endpoint = keystone.service_catalog.url_for(service_type='image',
145 endpoint_type='publicURL')
146 return glanceclient.Client('1', endpoint=endpoint, token=token)
Maru Newbydec13ec2012-08-30 11:19:17 -0700147
Maru Newby81f07a02012-09-05 20:21:19 -0700148 def _get_identity_client(self, username=None, password=None,
149 tenant_name=None):
Maru Newbydec13ec2012-08-30 11:19:17 -0700150 # This identity client is not intended to check the security
Maru Newby81f07a02012-09-05 20:21:19 -0700151 # of the identity service, so use admin credentials by default.
152 if not username:
153 username = self.config.identity_admin.username
154 if not password:
155 password = self.config.identity_admin.password
156 if not tenant_name:
157 tenant_name = self.config.identity_admin.tenant_name
Maru Newbydec13ec2012-08-30 11:19:17 -0700158
159 if None in (username, password, tenant_name):
160 msg = ("Missing required credentials for identity client. "
161 "username: %(username)s, password: %(password)s, "
162 "tenant_name: %(tenant_name)s") % locals()
163 raise exceptions.InvalidConfiguration(msg)
164
165 auth_url = self.config.identity.auth_url.rstrip('tokens')
166
167 return keystoneclient.v2_0.client.Client(username=username,
168 password=password,
169 tenant_name=tenant_name,
David Kranz21d95da2012-09-28 11:47:53 -0400170 auth_url=auth_url)
Maru Newbydec13ec2012-08-30 11:19:17 -0700171
172 def _get_network_client(self):
Maru Newbyb72f37c2012-12-14 02:17:06 +0000173 # The intended configuration is for the network client to have
174 # admin privileges and indicate for whom resources are being
175 # created via a 'tenant_id' parameter. This will often be
176 # preferable to authenticating as a specific user because
177 # working with certain resources (public routers and networks)
178 # often requires admin privileges anyway.
179 username = self.config.network_admin.username
180 password = self.config.network_admin.password
181 tenant_name = self.config.network_admin.tenant_name
Maru Newbydec13ec2012-08-30 11:19:17 -0700182
183 if None in (username, password, tenant_name):
184 msg = ("Missing required credentials for network client. "
185 "username: %(username)s, password: %(password)s, "
186 "tenant_name: %(tenant_name)s") % locals()
187 raise exceptions.InvalidConfiguration(msg)
188
189 auth_url = self.config.identity.auth_url.rstrip('tokens')
190
191 return quantumclient.v2_0.client.Client(username=username,
192 password=password,
193 tenant_name=tenant_name,
194 auth_url=auth_url)
Jay Pipes051075a2012-04-28 17:39:37 -0400195
196
197class ComputeFuzzClientManager(FuzzClientManager):
198
199 """
200 Manager that uses the Tempest REST client that can send
201 random or invalid data at the OpenStack Compute API
202 """
203
204 def __init__(self, username=None, password=None, tenant_name=None):
205 """
206 We allow overriding of the credentials used within the various
207 client classes managed by the Manager object. Left as None, the
208 standard username/password/tenant_name is used.
209
210 :param username: Override of the username
211 :param password: Override of the password
212 :param tenant_name: Override of the tenant name
213 """
214 super(ComputeFuzzClientManager, self).__init__()
215
216 # If no creds are provided, we fall back on the defaults
217 # in the config file for the Compute API.
218 username = username or self.config.compute.username
219 password = password or self.config.compute.password
220 tenant_name = tenant_name or self.config.compute.tenant_name
221
222 if None in (username, password, tenant_name):
223 msg = ("Missing required credentials. "
224 "username: %(username)s, password: %(password)s, "
225 "tenant_name: %(tenant_name)s") % locals()
226 raise exceptions.InvalidConfiguration(msg)
227
228 auth_url = self.config.identity.auth_url
229
230 if self.config.identity.strategy == 'keystone':
231 client_args = (self.config, username, password, auth_url,
232 tenant_name)
233 else:
234 client_args = (self.config, username, password, auth_url)
235
236 self.servers_client = ServersClient(*client_args)
237 self.flavors_client = FlavorsClient(*client_args)
238 self.images_client = ImagesClient(*client_args)
239 self.limits_client = LimitsClient(*client_args)
240 self.extensions_client = ExtensionsClient(*client_args)
241 self.keypairs_client = KeyPairsClient(*client_args)
242 self.security_groups_client = SecurityGroupsClient(*client_args)
243 self.floating_ips_client = FloatingIPsClient(*client_args)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700244 self.volumes_extensions_client = VolumesExtensionsClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400245 self.volumes_client = VolumesClient(*client_args)
246 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700247 self.quotas_client = QuotasClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400248 self.network_client = NetworkClient(*client_args)
249
250
251class ComputeFuzzClientAltManager(Manager):
252
253 """
254 Manager object that uses the alt_XXX credentials for its
255 managed client objects
256 """
257
258 def __init__(self):
259 conf = tempest.config.TempestConfig()
260 super(ComputeFuzzClientAltManager, self).__init__(
rajalakshmi-ganesand793d692012-12-25 12:54:50 +0530261 conf.compute.alt_username,
262 conf.compute.alt_password,
263 conf.compute.alt_tenant_name)
Jay Pipes051075a2012-04-28 17:39:37 -0400264
265
266class ComputeFuzzClientAdminManager(Manager):
267
268 """
269 Manager object that uses the alt_XXX credentials for its
270 managed client objects
271 """
272
273 def __init__(self):
274 conf = tempest.config.TempestConfig()
275 super(ComputeFuzzClientAdminManager, self).__init__(
rajalakshmi-ganesand793d692012-12-25 12:54:50 +0530276 conf.compute_admin.username,
277 conf.compute_admin.password,
278 conf.compute_admin.tenant_name)