blob: 4a447f3008de4c2ad6c215b49607267c248d7be4 [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
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090018from tempest.common import log as logging
Jay Pipes051075a2012-04-28 17:39:37 -040019import tempest.config
20from tempest import exceptions
21# Tempest REST Fuzz testing client libs
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022from tempest.services.compute.json import extensions_client
23from tempest.services.compute.json import flavors_client
24from tempest.services.compute.json import floating_ips_client
Tony Yang3d5f1632013-06-06 14:17:57 +080025from tempest.services.compute.json import hypervisor_client
Matthew Treinisha83a16e2012-12-07 13:44:02 -050026from tempest.services.compute.json import images_client
27from tempest.services.compute.json import keypairs_client
28from tempest.services.compute.json import limits_client
29from tempest.services.compute.json import quotas_client
30from tempest.services.compute.json import security_groups_client
31from tempest.services.compute.json import servers_client
32from tempest.services.compute.json import volumes_extensions_client
Jay Pipes051075a2012-04-28 17:39:37 -040033from tempest.services.network.json import network_client
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010034from tempest.services.volume.json import snapshots_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070035from tempest.services.volume.json import volumes_client
Jay Pipes051075a2012-04-28 17:39:37 -040036
37NetworkClient = network_client.NetworkClient
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040038ImagesClient = images_client.ImagesClientJSON
Tiago Melloeda03b52012-08-22 23:47:29 -030039FlavorsClient = flavors_client.FlavorsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070040ServersClient = servers_client.ServersClientJSON
Matthew Treinish33634462012-08-16 16:51:23 -040041LimitsClient = limits_client.LimitsClientJSON
Tiago Mello89126c32012-08-27 11:14:03 -030042ExtensionsClient = extensions_client.ExtensionsClientJSON
Vincent Hou22f03c72012-08-24 17:55:13 +080043FloatingIPsClient = floating_ips_client.FloatingIPsClientJSON
Vincent Houead03dc2012-08-24 21:35:11 +080044SecurityGroupsClient = security_groups_client.SecurityGroupsClientJSON
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040045KeyPairsClient = keypairs_client.KeyPairsClientJSON
Matthew Treinish4e086902012-08-17 17:52:22 -040046VolumesExtensionsClient = volumes_extensions_client.VolumesExtensionsClientJSON
Matthew Treinish9854d5b2012-09-20 10:22:13 -040047VolumesClient = volumes_client.VolumesClientJSON
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010048SnapshotsClient = snapshots_client.SnapshotsClientJSON
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053049QuotasClient = quotas_client.QuotasClientJSON
Tony Yang3d5f1632013-06-06 14:17:57 +080050HypervisorClient = hypervisor_client.HypervisorClientJSON
Jay Pipes051075a2012-04-28 17:39:37 -040051
52LOG = logging.getLogger(__name__)
53
54
55class 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 Newbydec13ec2012-08-30 11:19:17 -070066 self.client_attr_names = []
Jay Pipes051075a2012-04-28 17:39:37 -040067
68
69class 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 Pipes051075a2012-04-28 17:39:37 -040081class 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 Fazekascadcb1f2013-01-21 23:10:53 +0100102 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 Pipes051075a2012-04-28 17:39:37 -0400105
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 Pipes7c88eb22013-01-16 21:32:43 -0500112 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 Pipes051075a2012-04-28 17:39:37 -0400117
Li Ma216550f2013-06-12 11:26:08 -0700118 client_args = (self.config, username, password, auth_url,
119 tenant_name)
Jay Pipes051075a2012-04-28 17:39:37 -0400120
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 Karajgidd47d7e2012-07-31 04:11:01 -0700129 self.volumes_extensions_client = VolumesExtensionsClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400130 self.volumes_client = VolumesClient(*client_args)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100131 self.snapshots_client = SnapshotsClient(*client_args)
Rohit Karajgi07599c52012-11-02 05:35:16 -0700132 self.quotas_client = QuotasClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400133 self.network_client = NetworkClient(*client_args)
Tony Yang3d5f1632013-06-06 14:17:57 +0800134 self.hypervisor_client = HypervisorClient(*client_args)
Jay Pipes051075a2012-04-28 17:39:37 -0400135
136
137class 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 Fazekascadcb1f2013-01-21 23:10:53 +0100147 conf.identity.alt_username,
148 conf.identity.alt_password,
149 conf.identity.alt_tenant_name)
Jay Pipes051075a2012-04-28 17:39:37 -0400150
151
152class 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-ganesand793d692012-12-25 12:54:50 +0530162 conf.compute_admin.username,
163 conf.compute_admin.password,
164 conf.compute_admin.tenant_name)