Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 1 | # 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 | |
| 18 | import logging |
| 19 | |
| 20 | # Default client libs |
Brian Waldon | c9b99a2 | 2012-09-10 09:24:35 -0700 | [diff] [blame] | 21 | import glanceclient |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 22 | import keystoneclient.v2_0.client |
| 23 | import novaclient.client |
| 24 | import quantumclient.v2_0.client |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 25 | |
| 26 | import tempest.config |
| 27 | from tempest import exceptions |
| 28 | # Tempest REST Fuzz testing client libs |
| 29 | from tempest.services.network.json import network_client |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 30 | from tempest.services.volume.json import volumes_client |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 31 | from tempest.services.nova.json import images_client |
| 32 | from tempest.services.nova.json import flavors_client |
| 33 | from tempest.services.nova.json import servers_client |
| 34 | from tempest.services.nova.json import limits_client |
| 35 | from tempest.services.nova.json import extensions_client |
| 36 | from tempest.services.nova.json import security_groups_client |
| 37 | from tempest.services.nova.json import floating_ips_client |
| 38 | from tempest.services.nova.json import keypairs_client |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 39 | from tempest.services.nova.json import volumes_extensions_client |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 40 | from tempest.services.nova.json import console_output_client |
| 41 | |
| 42 | NetworkClient = network_client.NetworkClient |
| 43 | ImagesClient = images_client.ImagesClient |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 44 | FlavorsClient = flavors_client.FlavorsClientJSON |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 45 | ServersClient = servers_client.ServersClientJSON |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 46 | LimitsClient = limits_client.LimitsClientJSON |
Tiago Mello | 89126c3 | 2012-08-27 11:14:03 -0300 | [diff] [blame] | 47 | ExtensionsClient = extensions_client.ExtensionsClientJSON |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 48 | SecurityGroupsClient = security_groups_client.SecurityGroupsClient |
| 49 | FloatingIPsClient = floating_ips_client.FloatingIPsClient |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 50 | KeyPairsClient = keypairs_client.KeyPairsClientJSON |
Matthew Treinish | 4e08690 | 2012-08-17 17:52:22 -0400 | [diff] [blame^] | 51 | VolumesExtensionsClient = volumes_extensions_client.VolumesExtensionsClientJSON |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 52 | VolumesClient = volumes_client.VolumesClient |
| 53 | ConsoleOutputsClient = console_output_client.ConsoleOutputsClient |
| 54 | |
| 55 | LOG = logging.getLogger(__name__) |
| 56 | |
| 57 | |
| 58 | class 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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 69 | self.client_attr_names = [] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 70 | |
| 71 | |
| 72 | class 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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 84 | class DefaultClientManager(Manager): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 85 | |
| 86 | """ |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 87 | Manager that provides the default clients to access the various |
| 88 | OpenStack APIs. |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 89 | """ |
| 90 | |
| 91 | NOVACLIENT_VERSION = '2' |
| 92 | |
| 93 | def __init__(self): |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 94 | 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 Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 117 | |
| 118 | if None in (username, password, tenant_name): |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 119 | msg = ("Missing required credentials for compute client. " |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 120 | "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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 130 | return novaclient.client.Client(self.NOVACLIENT_VERSION, |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 131 | *client_args, |
dwalleck | 6427e7d | 2012-08-06 22:54:39 -0500 | [diff] [blame] | 132 | service_type=self.config.compute.catalog_type, |
| 133 | no_cache=True) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 134 | |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 135 | def _get_image_client(self): |
Brian Waldon | c9b99a2 | 2012-09-10 09:24:35 -0700 | [diff] [blame] | 136 | 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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 141 | |
| 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 Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 180 | |
| 181 | |
| 182 | class 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 229 | self.volumes_extensions_client = VolumesExtensionsClient(*client_args) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 230 | self.volumes_client = VolumesClient(*client_args) |
| 231 | self.console_outputs_client = ConsoleOutputsClient(*client_args) |
| 232 | self.network_client = NetworkClient(*client_args) |
| 233 | |
| 234 | |
| 235 | class 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 | |
| 250 | class 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) |