blob: 4469301ca275c50215ab9517f0e3b1e8753bc586 [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
21import novaclient.client
22import glance.client
23
24import tempest.config
25from tempest import exceptions
26# Tempest REST Fuzz testing client libs
27from tempest.services.network.json import network_client
28from tempest.services.nova.json import images_client
29from tempest.services.nova.json import flavors_client
30from tempest.services.nova.json import servers_client
31from tempest.services.nova.json import limits_client
32from tempest.services.nova.json import extensions_client
33from tempest.services.nova.json import security_groups_client
34from tempest.services.nova.json import floating_ips_client
35from tempest.services.nova.json import keypairs_client
36from tempest.services.nova.json import volumes_client
37from tempest.services.nova.json import console_output_client
38
39NetworkClient = network_client.NetworkClient
40ImagesClient = images_client.ImagesClient
41FlavorsClient = flavors_client.FlavorsClient
Dan Smithcf8fab62012-08-14 08:03:48 -070042ServersClient = servers_client.ServersClientJSON
Matthew Treinish33634462012-08-16 16:51:23 -040043LimitsClient = limits_client.LimitsClientJSON
Jay Pipes051075a2012-04-28 17:39:37 -040044ExtensionsClient = extensions_client.ExtensionsClient
45SecurityGroupsClient = security_groups_client.SecurityGroupsClient
46FloatingIPsClient = floating_ips_client.FloatingIPsClient
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040047KeyPairsClient = keypairs_client.KeyPairsClientJSON
Jay Pipes051075a2012-04-28 17:39:37 -040048VolumesClient = volumes_client.VolumesClient
49ConsoleOutputsClient = console_output_client.ConsoleOutputsClient
50
51LOG = logging.getLogger(__name__)
52
53
54class Manager(object):
55
56 """
57 Base manager class
58
59 Manager objects are responsible for providing a configuration object
60 and a client object for a test case to use in performing actions.
61 """
62
63 def __init__(self):
64 self.config = tempest.config.TempestConfig()
65 self.client = None
66
67
68class DefaultClientManager(Manager):
69
70 """
71 Manager class that indicates the client provided by the manager
72 is the default Python client that an OpenStack API provides.
73 """
74 pass
75
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
89class ComputeDefaultClientManager(DefaultClientManager):
90
91 """
92 Manager that provides the default python-novaclient client object
93 to access the OpenStack Compute API.
94 """
95
96 NOVACLIENT_VERSION = '2'
97
98 def __init__(self):
99 super(ComputeDefaultClientManager, self).__init__()
100 username = self.config.compute.username
101 password = self.config.compute.password
102 tenant_name = self.config.compute.tenant_name
103
104 if None in (username, password, tenant_name):
105 msg = ("Missing required credentials. "
106 "username: %(username)s, password: %(password)s, "
107 "tenant_name: %(tenant_name)s") % locals()
108 raise exceptions.InvalidConfiguration(msg)
109
110 # Novaclient adds a /tokens/ part to the auth URL automatically
111 auth_url = self.config.identity.auth_url.rstrip('tokens')
112
113 client_args = (username, password, tenant_name, auth_url)
114
115 # Create our default Nova client to use in testing
116 self.client = novaclient.client.Client(self.NOVACLIENT_VERSION,
117 *client_args,
dwalleck6427e7d2012-08-06 22:54:39 -0500118 service_type=self.config.compute.catalog_type,
119 no_cache=True)
Jay Pipes051075a2012-04-28 17:39:37 -0400120
121
122class GlanceDefaultClientManager(DefaultClientManager):
123 """
124 Manager that provides the default glance client object to access
125 the OpenStack Images API
126 """
127 def __init__(self):
128 super(GlanceDefaultClientManager, self).__init__()
129 host = self.config.images.host
130 port = self.config.images.port
131 strategy = self.config.identity.strategy
132 auth_url = self.config.identity.auth_url
133 username = self.config.images.username
134 password = self.config.images.password
135 tenant_name = self.config.images.tenant_name
136
137 if None in (host, port, username, password, tenant_name):
138 msg = ("Missing required credentials. "
139 "host:%(host)s, port: %(port)s username: %(username)s, "
140 "password: %(password)s, "
141 "tenant_name: %(tenant_name)s") % locals()
142 raise exceptions.InvalidConfiguration(msg)
143 auth_url = self.config.identity.auth_url.rstrip('tokens')
144
145 creds = {'strategy': strategy,
146 'username': username,
147 'password': password,
148 'tenant': tenant_name,
149 'auth_url': auth_url}
150
151 # Create our default Glance client to use in testing
152 self.client = glance.client.Client(host, port, creds=creds)
153
154
155class ComputeFuzzClientManager(FuzzClientManager):
156
157 """
158 Manager that uses the Tempest REST client that can send
159 random or invalid data at the OpenStack Compute API
160 """
161
162 def __init__(self, username=None, password=None, tenant_name=None):
163 """
164 We allow overriding of the credentials used within the various
165 client classes managed by the Manager object. Left as None, the
166 standard username/password/tenant_name is used.
167
168 :param username: Override of the username
169 :param password: Override of the password
170 :param tenant_name: Override of the tenant name
171 """
172 super(ComputeFuzzClientManager, self).__init__()
173
174 # If no creds are provided, we fall back on the defaults
175 # in the config file for the Compute API.
176 username = username or self.config.compute.username
177 password = password or self.config.compute.password
178 tenant_name = tenant_name or self.config.compute.tenant_name
179
180 if None in (username, password, tenant_name):
181 msg = ("Missing required credentials. "
182 "username: %(username)s, password: %(password)s, "
183 "tenant_name: %(tenant_name)s") % locals()
184 raise exceptions.InvalidConfiguration(msg)
185
186 auth_url = self.config.identity.auth_url
187
188 if self.config.identity.strategy == 'keystone':
189 client_args = (self.config, username, password, auth_url,
190 tenant_name)
191 else:
192 client_args = (self.config, username, password, auth_url)
193
194 self.servers_client = ServersClient(*client_args)
195 self.flavors_client = FlavorsClient(*client_args)
196 self.images_client = ImagesClient(*client_args)
197 self.limits_client = LimitsClient(*client_args)
198 self.extensions_client = ExtensionsClient(*client_args)
199 self.keypairs_client = KeyPairsClient(*client_args)
200 self.security_groups_client = SecurityGroupsClient(*client_args)
201 self.floating_ips_client = FloatingIPsClient(*client_args)
202 self.volumes_client = VolumesClient(*client_args)
203 self.console_outputs_client = ConsoleOutputsClient(*client_args)
204 self.network_client = NetworkClient(*client_args)
205
206
207class ComputeFuzzClientAltManager(Manager):
208
209 """
210 Manager object that uses the alt_XXX credentials for its
211 managed client objects
212 """
213
214 def __init__(self):
215 conf = tempest.config.TempestConfig()
216 super(ComputeFuzzClientAltManager, self).__init__(
217 conf.compute.alt_username,
218 conf.compute.alt_password,
219 conf.compute.alt_tenant_name)
220
221
222class ComputeFuzzClientAdminManager(Manager):
223
224 """
225 Manager object that uses the alt_XXX credentials for its
226 managed client objects
227 """
228
229 def __init__(self):
230 conf = tempest.config.TempestConfig()
231 super(ComputeFuzzClientAdminManager, self).__init__(
232 conf.compute_admin.username,
233 conf.compute_admin.password,
234 conf.compute_admin.tenant_name)