blob: b960edbb1884ccc2212931baab670694e1acdcae [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
42ServersClient = servers_client.ServersClient
43LimitsClient = limits_client.LimitsClient
44ExtensionsClient = extensions_client.ExtensionsClient
45SecurityGroupsClient = security_groups_client.SecurityGroupsClient
46FloatingIPsClient = floating_ips_client.FloatingIPsClient
47KeyPairsClient = keypairs_client.KeyPairsClient
48VolumesClient = 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,
118 service_type=self.config.compute.catalog_type)
119
120
121class GlanceDefaultClientManager(DefaultClientManager):
122 """
123 Manager that provides the default glance client object to access
124 the OpenStack Images API
125 """
126 def __init__(self):
127 super(GlanceDefaultClientManager, self).__init__()
128 host = self.config.images.host
129 port = self.config.images.port
130 strategy = self.config.identity.strategy
131 auth_url = self.config.identity.auth_url
132 username = self.config.images.username
133 password = self.config.images.password
134 tenant_name = self.config.images.tenant_name
135
136 if None in (host, port, username, password, tenant_name):
137 msg = ("Missing required credentials. "
138 "host:%(host)s, port: %(port)s username: %(username)s, "
139 "password: %(password)s, "
140 "tenant_name: %(tenant_name)s") % locals()
141 raise exceptions.InvalidConfiguration(msg)
142 auth_url = self.config.identity.auth_url.rstrip('tokens')
143
144 creds = {'strategy': strategy,
145 'username': username,
146 'password': password,
147 'tenant': tenant_name,
148 'auth_url': auth_url}
149
150 # Create our default Glance client to use in testing
151 self.client = glance.client.Client(host, port, creds=creds)
152
153
154class ComputeFuzzClientManager(FuzzClientManager):
155
156 """
157 Manager that uses the Tempest REST client that can send
158 random or invalid data at the OpenStack Compute API
159 """
160
161 def __init__(self, username=None, password=None, tenant_name=None):
162 """
163 We allow overriding of the credentials used within the various
164 client classes managed by the Manager object. Left as None, the
165 standard username/password/tenant_name is used.
166
167 :param username: Override of the username
168 :param password: Override of the password
169 :param tenant_name: Override of the tenant name
170 """
171 super(ComputeFuzzClientManager, self).__init__()
172
173 # If no creds are provided, we fall back on the defaults
174 # in the config file for the Compute API.
175 username = username or self.config.compute.username
176 password = password or self.config.compute.password
177 tenant_name = tenant_name or self.config.compute.tenant_name
178
179 if None in (username, password, tenant_name):
180 msg = ("Missing required credentials. "
181 "username: %(username)s, password: %(password)s, "
182 "tenant_name: %(tenant_name)s") % locals()
183 raise exceptions.InvalidConfiguration(msg)
184
185 auth_url = self.config.identity.auth_url
186
187 if self.config.identity.strategy == 'keystone':
188 client_args = (self.config, username, password, auth_url,
189 tenant_name)
190 else:
191 client_args = (self.config, username, password, auth_url)
192
193 self.servers_client = ServersClient(*client_args)
194 self.flavors_client = FlavorsClient(*client_args)
195 self.images_client = ImagesClient(*client_args)
196 self.limits_client = LimitsClient(*client_args)
197 self.extensions_client = ExtensionsClient(*client_args)
198 self.keypairs_client = KeyPairsClient(*client_args)
199 self.security_groups_client = SecurityGroupsClient(*client_args)
200 self.floating_ips_client = FloatingIPsClient(*client_args)
201 self.volumes_client = VolumesClient(*client_args)
202 self.console_outputs_client = ConsoleOutputsClient(*client_args)
203 self.network_client = NetworkClient(*client_args)
204
205
206class ComputeFuzzClientAltManager(Manager):
207
208 """
209 Manager object that uses the alt_XXX credentials for its
210 managed client objects
211 """
212
213 def __init__(self):
214 conf = tempest.config.TempestConfig()
215 super(ComputeFuzzClientAltManager, self).__init__(
216 conf.compute.alt_username,
217 conf.compute.alt_password,
218 conf.compute.alt_tenant_name)
219
220
221class ComputeFuzzClientAdminManager(Manager):
222
223 """
224 Manager object that uses the alt_XXX credentials for its
225 managed client objects
226 """
227
228 def __init__(self):
229 conf = tempest.config.TempestConfig()
230 super(ComputeFuzzClientAdminManager, self).__init__(
231 conf.compute_admin.username,
232 conf.compute_admin.password,
233 conf.compute_admin.tenant_name)