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 | |
Mitsuhiko Yamazaki | 46818aa | 2013-04-18 17:49:17 +0900 | [diff] [blame] | 18 | from tempest.common import log as logging |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 19 | import tempest.config |
| 20 | from tempest import exceptions |
| 21 | # Tempest REST Fuzz testing client libs |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 22 | from tempest.services.compute.json import extensions_client |
| 23 | from tempest.services.compute.json import flavors_client |
| 24 | from tempest.services.compute.json import floating_ips_client |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 25 | from tempest.services.compute.json import hypervisor_client |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 26 | from tempest.services.compute.json import images_client |
| 27 | from tempest.services.compute.json import keypairs_client |
| 28 | from tempest.services.compute.json import limits_client |
| 29 | from tempest.services.compute.json import quotas_client |
| 30 | from tempest.services.compute.json import security_groups_client |
| 31 | from tempest.services.compute.json import servers_client |
| 32 | from tempest.services.compute.json import volumes_extensions_client |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 33 | from tempest.services.network.json import network_client |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 34 | from tempest.services.volume.json import snapshots_client |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 35 | from tempest.services.volume.json import volumes_client |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 36 | |
| 37 | NetworkClient = network_client.NetworkClient |
Mauro S. M. Rodrigues | 6e37324 | 2012-08-27 18:59:19 -0400 | [diff] [blame] | 38 | ImagesClient = images_client.ImagesClientJSON |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 39 | FlavorsClient = flavors_client.FlavorsClientJSON |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 40 | ServersClient = servers_client.ServersClientJSON |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 41 | LimitsClient = limits_client.LimitsClientJSON |
Tiago Mello | 89126c3 | 2012-08-27 11:14:03 -0300 | [diff] [blame] | 42 | ExtensionsClient = extensions_client.ExtensionsClientJSON |
Vincent Hou | 22f03c7 | 2012-08-24 17:55:13 +0800 | [diff] [blame] | 43 | FloatingIPsClient = floating_ips_client.FloatingIPsClientJSON |
Vincent Hou | ead03dc | 2012-08-24 21:35:11 +0800 | [diff] [blame] | 44 | SecurityGroupsClient = security_groups_client.SecurityGroupsClientJSON |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 45 | KeyPairsClient = keypairs_client.KeyPairsClientJSON |
Matthew Treinish | 4e08690 | 2012-08-17 17:52:22 -0400 | [diff] [blame] | 46 | VolumesExtensionsClient = volumes_extensions_client.VolumesExtensionsClientJSON |
Matthew Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 47 | VolumesClient = volumes_client.VolumesClientJSON |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 48 | SnapshotsClient = snapshots_client.SnapshotsClientJSON |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 49 | QuotasClient = quotas_client.QuotasClientJSON |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 50 | HypervisorClient = hypervisor_client.HypervisorClientJSON |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 51 | |
| 52 | LOG = logging.getLogger(__name__) |
| 53 | |
| 54 | |
| 55 | class Manager(object): |
| 56 | |
| 57 | """ |
| 58 | Base manager class |
| 59 | |
| 60 | Manager objects are responsible for providing a configuration object |
| 61 | and a client object for a test case to use in performing actions. |
| 62 | """ |
| 63 | |
| 64 | def __init__(self): |
| 65 | self.config = tempest.config.TempestConfig() |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 66 | self.client_attr_names = [] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 67 | |
| 68 | |
| 69 | class FuzzClientManager(Manager): |
| 70 | |
| 71 | """ |
| 72 | Manager class that indicates the client provided by the manager |
| 73 | is a fuzz-testing client that Tempest contains. These fuzz-testing |
| 74 | clients are used to be able to throw random or invalid data at |
| 75 | an endpoint and check for appropriate error messages returned |
| 76 | from the endpoint. |
| 77 | """ |
| 78 | pass |
| 79 | |
| 80 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 81 | class ComputeFuzzClientManager(FuzzClientManager): |
| 82 | |
| 83 | """ |
| 84 | Manager that uses the Tempest REST client that can send |
| 85 | random or invalid data at the OpenStack Compute API |
| 86 | """ |
| 87 | |
| 88 | def __init__(self, username=None, password=None, tenant_name=None): |
| 89 | """ |
| 90 | We allow overriding of the credentials used within the various |
| 91 | client classes managed by the Manager object. Left as None, the |
| 92 | standard username/password/tenant_name is used. |
| 93 | |
| 94 | :param username: Override of the username |
| 95 | :param password: Override of the password |
| 96 | :param tenant_name: Override of the tenant name |
| 97 | """ |
| 98 | super(ComputeFuzzClientManager, self).__init__() |
| 99 | |
| 100 | # If no creds are provided, we fall back on the defaults |
| 101 | # in the config file for the Compute API. |
Attila Fazekas | cadcb1f | 2013-01-21 23:10:53 +0100 | [diff] [blame] | 102 | username = username or self.config.identity.username |
| 103 | password = password or self.config.identity.password |
| 104 | tenant_name = tenant_name or self.config.identity.tenant_name |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 105 | |
| 106 | if None in (username, password, tenant_name): |
| 107 | msg = ("Missing required credentials. " |
| 108 | "username: %(username)s, password: %(password)s, " |
| 109 | "tenant_name: %(tenant_name)s") % locals() |
| 110 | raise exceptions.InvalidConfiguration(msg) |
| 111 | |
Jay Pipes | 7c88eb2 | 2013-01-16 21:32:43 -0500 | [diff] [blame] | 112 | auth_url = self.config.identity.uri |
| 113 | |
| 114 | # Ensure /tokens is in the URL for Keystone... |
| 115 | if 'tokens' not in auth_url: |
| 116 | auth_url = auth_url.rstrip('/') + '/tokens' |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 117 | |
Li Ma | 216550f | 2013-06-12 11:26:08 -0700 | [diff] [blame] | 118 | client_args = (self.config, username, password, auth_url, |
| 119 | tenant_name) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 120 | |
| 121 | self.servers_client = ServersClient(*client_args) |
| 122 | self.flavors_client = FlavorsClient(*client_args) |
| 123 | self.images_client = ImagesClient(*client_args) |
| 124 | self.limits_client = LimitsClient(*client_args) |
| 125 | self.extensions_client = ExtensionsClient(*client_args) |
| 126 | self.keypairs_client = KeyPairsClient(*client_args) |
| 127 | self.security_groups_client = SecurityGroupsClient(*client_args) |
| 128 | self.floating_ips_client = FloatingIPsClient(*client_args) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 129 | self.volumes_extensions_client = VolumesExtensionsClient(*client_args) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 130 | self.volumes_client = VolumesClient(*client_args) |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 131 | self.snapshots_client = SnapshotsClient(*client_args) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 132 | self.quotas_client = QuotasClient(*client_args) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 133 | self.network_client = NetworkClient(*client_args) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 134 | self.hypervisor_client = HypervisorClient(*client_args) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 135 | |
| 136 | |
| 137 | class ComputeFuzzClientAltManager(Manager): |
| 138 | |
| 139 | """ |
| 140 | Manager object that uses the alt_XXX credentials for its |
| 141 | managed client objects |
| 142 | """ |
| 143 | |
| 144 | def __init__(self): |
| 145 | conf = tempest.config.TempestConfig() |
| 146 | super(ComputeFuzzClientAltManager, self).__init__( |
Attila Fazekas | cadcb1f | 2013-01-21 23:10:53 +0100 | [diff] [blame] | 147 | conf.identity.alt_username, |
| 148 | conf.identity.alt_password, |
| 149 | conf.identity.alt_tenant_name) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 150 | |
| 151 | |
| 152 | class ComputeFuzzClientAdminManager(Manager): |
| 153 | |
| 154 | """ |
| 155 | Manager object that uses the alt_XXX credentials for its |
| 156 | managed client objects |
| 157 | """ |
| 158 | |
| 159 | def __init__(self): |
| 160 | conf = tempest.config.TempestConfig() |
| 161 | super(ComputeFuzzClientAdminManager, self).__init__( |
rajalakshmi-ganesan | d793d69 | 2012-12-25 12:54:50 +0530 | [diff] [blame] | 162 | conf.compute_admin.username, |
| 163 | conf.compute_admin.password, |
| 164 | conf.compute_admin.tenant_name) |