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