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 |
| 30 | from tempest.services.nova.json import images_client |
| 31 | from tempest.services.nova.json import flavors_client |
| 32 | from tempest.services.nova.json import servers_client |
| 33 | from tempest.services.nova.json import limits_client |
| 34 | from tempest.services.nova.json import extensions_client |
| 35 | from tempest.services.nova.json import security_groups_client |
| 36 | from tempest.services.nova.json import floating_ips_client |
| 37 | from tempest.services.nova.json import keypairs_client |
| 38 | from tempest.services.nova.json import volumes_client |
| 39 | from tempest.services.nova.json import console_output_client |
| 40 | |
| 41 | NetworkClient = network_client.NetworkClient |
| 42 | ImagesClient = images_client.ImagesClient |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 43 | FlavorsClient = flavors_client.FlavorsClientJSON |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 44 | ServersClient = servers_client.ServersClientJSON |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 45 | LimitsClient = limits_client.LimitsClientJSON |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 46 | ExtensionsClient = extensions_client.ExtensionsClient |
| 47 | SecurityGroupsClient = security_groups_client.SecurityGroupsClient |
| 48 | FloatingIPsClient = floating_ips_client.FloatingIPsClient |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 49 | KeyPairsClient = keypairs_client.KeyPairsClientJSON |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 50 | VolumesClient = volumes_client.VolumesClient |
| 51 | ConsoleOutputsClient = console_output_client.ConsoleOutputsClient |
| 52 | |
| 53 | LOG = logging.getLogger(__name__) |
| 54 | |
| 55 | |
| 56 | class 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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 67 | self.client_attr_names = [] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 68 | |
| 69 | |
| 70 | class 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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 82 | class DefaultClientManager(Manager): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 83 | |
| 84 | """ |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 85 | Manager that provides the default clients to access the various |
| 86 | OpenStack APIs. |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 87 | """ |
| 88 | |
| 89 | NOVACLIENT_VERSION = '2' |
| 90 | |
| 91 | def __init__(self): |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 92 | 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 Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 115 | |
| 116 | if None in (username, password, tenant_name): |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 117 | msg = ("Missing required credentials for compute client. " |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 118 | "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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 128 | return novaclient.client.Client(self.NOVACLIENT_VERSION, |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 129 | *client_args, |
dwalleck | 6427e7d | 2012-08-06 22:54:39 -0500 | [diff] [blame] | 130 | service_type=self.config.compute.catalog_type, |
| 131 | no_cache=True) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 132 | |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 133 | def _get_image_client(self): |
Brian Waldon | c9b99a2 | 2012-09-10 09:24:35 -0700 | [diff] [blame^] | 134 | 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 Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 139 | |
| 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 Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 178 | |
| 179 | |
| 180 | class 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 | |
| 232 | class 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 | |
| 247 | class 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) |