blob: 2cac25e18062356ff90674d8d1a8902b93ef494c [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
24import quantumclient.v2_0.client
Jay Pipes051075a2012-04-28 17:39:37 -040025
26import tempest.config
27from tempest import exceptions
28# Tempest REST Fuzz testing client libs
29from tempest.services.network.json import network_client
30from tempest.services.nova.json import images_client
31from tempest.services.nova.json import flavors_client
32from tempest.services.nova.json import servers_client
33from tempest.services.nova.json import limits_client
34from tempest.services.nova.json import extensions_client
35from tempest.services.nova.json import security_groups_client
36from tempest.services.nova.json import floating_ips_client
37from tempest.services.nova.json import keypairs_client
38from tempest.services.nova.json import volumes_client
39from tempest.services.nova.json import console_output_client
40
41NetworkClient = network_client.NetworkClient
42ImagesClient = images_client.ImagesClient
Tiago Melloeda03b52012-08-22 23:47:29 -030043FlavorsClient = flavors_client.FlavorsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070044ServersClient = servers_client.ServersClientJSON
Matthew Treinish33634462012-08-16 16:51:23 -040045LimitsClient = limits_client.LimitsClientJSON
Jay Pipes051075a2012-04-28 17:39:37 -040046ExtensionsClient = extensions_client.ExtensionsClient
47SecurityGroupsClient = security_groups_client.SecurityGroupsClient
48FloatingIPsClient = floating_ips_client.FloatingIPsClient
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040049KeyPairsClient = keypairs_client.KeyPairsClientJSON
Jay Pipes051075a2012-04-28 17:39:37 -040050VolumesClient = volumes_client.VolumesClient
51ConsoleOutputsClient = console_output_client.ConsoleOutputsClient
52
53LOG = logging.getLogger(__name__)
54
55
56class Manager(object):
57
58 """
59 Base manager class
60
61 Manager objects are responsible for providing a configuration object
62 and a client object for a test case to use in performing actions.
63 """
64
65 def __init__(self):
66 self.config = tempest.config.TempestConfig()
Maru Newbydec13ec2012-08-30 11:19:17 -070067 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040068
69
70class FuzzClientManager(Manager):
71
72 """
73 Manager class that indicates the client provided by the manager
74 is a fuzz-testing client that Tempest contains. These fuzz-testing
75 clients are used to be able to throw random or invalid data at
76 an endpoint and check for appropriate error messages returned
77 from the endpoint.
78 """
79 pass
80
81
Maru Newbydec13ec2012-08-30 11:19:17 -070082class DefaultClientManager(Manager):
Jay Pipes051075a2012-04-28 17:39:37 -040083
84 """
Maru Newbydec13ec2012-08-30 11:19:17 -070085 Manager that provides the default clients to access the various
86 OpenStack APIs.
Jay Pipes051075a2012-04-28 17:39:37 -040087 """
88
89 NOVACLIENT_VERSION = '2'
90
91 def __init__(self):
Maru Newbydec13ec2012-08-30 11:19:17 -070092 super(DefaultClientManager, self).__init__()
93 self.compute_client = self._get_compute_client()
94 self.image_client = self._get_image_client()
95 self.identity_client = self._get_identity_client()
96 self.network_client = self._get_network_client()
97 self.client_attr_names = [
98 'compute_client',
99 'image_client',
100 'identity_client',
101 'network_client',
102 ]
103
104 def _get_compute_client(self, username=None, password=None,
105 tenant_name=None):
106 # Novaclient will not execute operations for anyone but the
107 # identified user, so a new client needs to be created for
108 # each user that operations need to be performed for.
109 if not username:
110 username = self.config.compute.username
111 if not password:
112 password = self.config.compute.password
113 if not tenant_name:
114 tenant_name = self.config.compute.tenant_name
Jay Pipes051075a2012-04-28 17:39:37 -0400115
116 if None in (username, password, tenant_name):
Maru Newbydec13ec2012-08-30 11:19:17 -0700117 msg = ("Missing required credentials for compute client. "
Jay Pipes051075a2012-04-28 17:39:37 -0400118 "username: %(username)s, password: %(password)s, "
119 "tenant_name: %(tenant_name)s") % locals()
120 raise exceptions.InvalidConfiguration(msg)
121
122 # Novaclient adds a /tokens/ part to the auth URL automatically
123 auth_url = self.config.identity.auth_url.rstrip('tokens')
124
125 client_args = (username, password, tenant_name, auth_url)
126
127 # Create our default Nova client to use in testing
Maru Newbydec13ec2012-08-30 11:19:17 -0700128 return novaclient.client.Client(self.NOVACLIENT_VERSION,
Jay Pipes051075a2012-04-28 17:39:37 -0400129 *client_args,
dwalleck6427e7d2012-08-06 22:54:39 -0500130 service_type=self.config.compute.catalog_type,
131 no_cache=True)
Jay Pipes051075a2012-04-28 17:39:37 -0400132
Maru Newbydec13ec2012-08-30 11:19:17 -0700133 def _get_image_client(self):
Brian Waldonc9b99a22012-09-10 09:24:35 -0700134 keystone = self._get_identity_client()
135 token = keystone.auth_token
136 endpoint = keystone.service_catalog.url_for(service_type='image',
137 endpoint_type='publicURL')
138 return glanceclient.Client('1', endpoint=endpoint, token=token)
Maru Newbydec13ec2012-08-30 11:19:17 -0700139
140 def _get_identity_client(self):
141 # This identity client is not intended to check the security
142 # of the identity service, so use admin credentials.
143 username = self.config.identity_admin.username
144 password = self.config.identity_admin.password
145 tenant_name = self.config.identity_admin.tenant_name
146
147 if None in (username, password, tenant_name):
148 msg = ("Missing required credentials for identity client. "
149 "username: %(username)s, password: %(password)s, "
150 "tenant_name: %(tenant_name)s") % locals()
151 raise exceptions.InvalidConfiguration(msg)
152
153 auth_url = self.config.identity.auth_url.rstrip('tokens')
154
155 return keystoneclient.v2_0.client.Client(username=username,
156 password=password,
157 tenant_name=tenant_name,
158 endpoint=auth_url)
159
160 def _get_network_client(self):
161 # TODO(mnewby) add network-specific auth configuration
162 username = self.config.compute.username
163 password = self.config.compute.password
164 tenant_name = self.config.compute.tenant_name
165
166 if None in (username, password, tenant_name):
167 msg = ("Missing required credentials for network client. "
168 "username: %(username)s, password: %(password)s, "
169 "tenant_name: %(tenant_name)s") % locals()
170 raise exceptions.InvalidConfiguration(msg)
171
172 auth_url = self.config.identity.auth_url.rstrip('tokens')
173
174 return quantumclient.v2_0.client.Client(username=username,
175 password=password,
176 tenant_name=tenant_name,
177 auth_url=auth_url)
Jay Pipes051075a2012-04-28 17:39:37 -0400178
179
180class ComputeFuzzClientManager(FuzzClientManager):
181
182 """
183 Manager that uses the Tempest REST client that can send
184 random or invalid data at the OpenStack Compute API
185 """
186
187 def __init__(self, username=None, password=None, tenant_name=None):
188 """
189 We allow overriding of the credentials used within the various
190 client classes managed by the Manager object. Left as None, the
191 standard username/password/tenant_name is used.
192
193 :param username: Override of the username
194 :param password: Override of the password
195 :param tenant_name: Override of the tenant name
196 """
197 super(ComputeFuzzClientManager, self).__init__()
198
199 # If no creds are provided, we fall back on the defaults
200 # in the config file for the Compute API.
201 username = username or self.config.compute.username
202 password = password or self.config.compute.password
203 tenant_name = tenant_name or self.config.compute.tenant_name
204
205 if None in (username, password, tenant_name):
206 msg = ("Missing required credentials. "
207 "username: %(username)s, password: %(password)s, "
208 "tenant_name: %(tenant_name)s") % locals()
209 raise exceptions.InvalidConfiguration(msg)
210
211 auth_url = self.config.identity.auth_url
212
213 if self.config.identity.strategy == 'keystone':
214 client_args = (self.config, username, password, auth_url,
215 tenant_name)
216 else:
217 client_args = (self.config, username, password, auth_url)
218
219 self.servers_client = ServersClient(*client_args)
220 self.flavors_client = FlavorsClient(*client_args)
221 self.images_client = ImagesClient(*client_args)
222 self.limits_client = LimitsClient(*client_args)
223 self.extensions_client = ExtensionsClient(*client_args)
224 self.keypairs_client = KeyPairsClient(*client_args)
225 self.security_groups_client = SecurityGroupsClient(*client_args)
226 self.floating_ips_client = FloatingIPsClient(*client_args)
227 self.volumes_client = VolumesClient(*client_args)
228 self.console_outputs_client = ConsoleOutputsClient(*client_args)
229 self.network_client = NetworkClient(*client_args)
230
231
232class ComputeFuzzClientAltManager(Manager):
233
234 """
235 Manager object that uses the alt_XXX credentials for its
236 managed client objects
237 """
238
239 def __init__(self):
240 conf = tempest.config.TempestConfig()
241 super(ComputeFuzzClientAltManager, self).__init__(
242 conf.compute.alt_username,
243 conf.compute.alt_password,
244 conf.compute.alt_tenant_name)
245
246
247class ComputeFuzzClientAdminManager(Manager):
248
249 """
250 Manager object that uses the alt_XXX credentials for its
251 managed client objects
252 """
253
254 def __init__(self):
255 conf = tempest.config.TempestConfig()
256 super(ComputeFuzzClientAdminManager, self).__init__(
257 conf.compute_admin.username,
258 conf.compute_admin.password,
259 conf.compute_admin.tenant_name)