blob: 156df300047ab5a9a7cf5c798b5d65cd08f91952 [file] [log] [blame]
Jay Pipes3f981df2012-03-27 18:59:44 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes3f981df2012-03-27 18:59:44 -04004# 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
Jay Pipesf38eaac2012-06-21 13:37:35 -040018from tempest import config
Daryl Walleck587385b2012-03-03 13:00:26 -060019from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040020from tempest.openstack.common import log as logging
Attila Fazekas1aed6202013-02-11 14:47:45 +010021from tempest.services import botoclients
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090022from tempest.services.compute.json.aggregates_client import \
23 AggregatesClientJSON
Leo Toyodaa5278912013-04-16 15:40:12 +090024from tempest.services.compute.json.availability_zone_client import \
25 AvailabilityZoneClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050026from tempest.services.compute.json.extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053027 ExtensionsClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040028from tempest.services.compute.json.fixed_ips_client import FixedIPsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050029from tempest.services.compute.json.flavors_client import FlavorsClientJSON
30from tempest.services.compute.json.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053031 FloatingIPsClientJSON
Attila Fazekas8e99b992013-02-24 09:53:23 +010032from tempest.services.compute.json.hosts_client import HostsClientJSON
Tony Yang3d5f1632013-06-06 14:17:57 +080033from tempest.services.compute.json.hypervisor_client import \
34 HypervisorClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050035from tempest.services.compute.json.images_client import ImagesClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040036from tempest.services.compute.json.interfaces_client import \
37 InterfacesClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010038from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050039from tempest.services.compute.json.limits_client import LimitsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010040from tempest.services.compute.json.quotas_client import QuotasClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050041from tempest.services.compute.json.security_groups_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053042 SecurityGroupsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010043from tempest.services.compute.json.servers_client import ServersClientJSON
Leo Toyoda3ae31e12013-04-19 11:19:57 +090044from tempest.services.compute.json.services_client import ServicesClientJSON
Leo Toyodad80b6a02013-05-08 12:15:13 +090045from tempest.services.compute.json.tenant_usages_client import \
46 TenantUsagesClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050047from tempest.services.compute.json.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053048 VolumesExtensionsClientJSON
ivan-zhu8f992be2013-07-31 14:56:58 +080049from tempest.services.compute.v3.json.servers_client import \
50 ServersV3ClientJSON
51from tempest.services.compute.v3.xml.servers_client import ServersV3ClientXML
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +090052from tempest.services.compute.xml.aggregates_client import AggregatesClientXML
Leo Toyodaa5278912013-04-16 15:40:12 +090053from tempest.services.compute.xml.availability_zone_client import \
54 AvailabilityZoneClientXML
dwallecke62b9f02012-10-10 23:34:42 -050055from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040056from tempest.services.compute.xml.fixed_ips_client import FixedIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050057from tempest.services.compute.xml.flavors_client import FlavorsClientXML
58from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053059 FloatingIPsClientXML
Tony Yang3d5f1632013-06-06 14:17:57 +080060from tempest.services.compute.xml.hypervisor_client import HypervisorClientXML
dwallecke62b9f02012-10-10 23:34:42 -050061from tempest.services.compute.xml.images_client import ImagesClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040062from tempest.services.compute.xml.interfaces_client import \
63 InterfacesClientXML
dwallecke62b9f02012-10-10 23:34:42 -050064from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
65from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053066from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050067from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053068 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050069from tempest.services.compute.xml.servers_client import ServersClientXML
Leo Toyoda3ae31e12013-04-19 11:19:57 +090070from tempest.services.compute.xml.services_client import ServicesClientXML
Leo Toyodad80b6a02013-05-08 12:15:13 +090071from tempest.services.compute.xml.tenant_usages_client import \
72 TenantUsagesClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050073from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053074 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010075from tempest.services.identity.json.identity_client import IdentityClientJSON
76from tempest.services.identity.json.identity_client import TokenClientJSON
nayna-patel914b4712013-07-16 08:29:05 +000077from tempest.services.identity.v3.json.credentials_client import \
78 CredentialsClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040079from tempest.services.identity.v3.json.endpoints_client import \
80 EndPointClientJSON
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053081from tempest.services.identity.v3.json.identity_client import \
82 IdentityV3ClientJSON
nayna-patelb35f7232013-06-28 07:08:44 +000083from tempest.services.identity.v3.json.identity_client import V3TokenClientJSON
harika-vakadi40e10112013-02-08 14:38:09 +053084from tempest.services.identity.v3.json.policy_client import PolicyClientJSON
harika-vakadia92dd742013-02-19 20:41:22 +053085from tempest.services.identity.v3.json.service_client import \
86 ServiceClientJSON
nayna-patel914b4712013-07-16 08:29:05 +000087from tempest.services.identity.v3.xml.credentials_client import \
88 CredentialsClientXML
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053089from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053090from tempest.services.identity.v3.xml.identity_client import \
91 IdentityV3ClientXML
nayna-patelb35f7232013-06-28 07:08:44 +000092from tempest.services.identity.v3.xml.identity_client import V3TokenClientXML
harika-vakadi40e10112013-02-08 14:38:09 +053093from tempest.services.identity.v3.xml.policy_client import PolicyClientXML
harika-vakadia92dd742013-02-19 20:41:22 +053094from tempest.services.identity.v3.xml.service_client import \
95 ServiceClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010096from tempest.services.identity.xml.identity_client import IdentityClientXML
97from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish6d59c992013-03-01 16:20:04 -050098from tempest.services.image.v1.json.image_client import ImageClientJSON
Matthew Treinisha62347f2013-03-01 16:37:30 -050099from tempest.services.image.v2.json.image_client import ImageClientV2JSON
raiesmh0867698322013-08-20 13:09:01 +0530100from tempest.services.network.json.network_client import NetworkClientJSON
101from tempest.services.network.xml.network_client import NetworkClientXML
dwalleck5d734432012-10-04 01:11:47 -0500102from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +0530103from tempest.services.object_storage.account_client import \
104 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +0100105from tempest.services.object_storage.container_client import ContainerClient
106from tempest.services.object_storage.object_client import ObjectClient
107from tempest.services.object_storage.object_client import \
108 ObjectClientCustomizedHeader
Steve Bakerc60e4e32013-05-06 15:22:41 +1200109from tempest.services.orchestration.json.orchestration_client import \
110 OrchestrationClient
Attila Fazekas6968dd52013-02-15 17:05:53 +0100111from tempest.services.volume.json.admin.volume_types_client import \
112 VolumeTypesClientJSON
113from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
114from tempest.services.volume.json.volumes_client import VolumesClientJSON
115from tempest.services.volume.xml.admin.volume_types_client import \
116 VolumeTypesClientXML
117from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
118from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800119
Jay Pipes3f981df2012-03-27 18:59:44 -0400120LOG = logging.getLogger(__name__)
121
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800122
Daryl Walleck1465d612011-11-02 02:22:15 -0500123class Manager(object):
124
Jay Pipes3f981df2012-03-27 18:59:44 -0400125 """
126 Top level manager for OpenStack Compute clients
127 """
128
James E. Blaire6d8ee12013-01-18 21:33:45 +0000129 def __init__(self, username=None, password=None, tenant_name=None,
130 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400131 """
132 We allow overriding of the credentials used within the various
133 client classes managed by the Manager object. Left as None, the
134 standard username/password/tenant_name is used.
135
136 :param username: Override of the username
137 :param password: Override of the password
138 :param tenant_name: Override of the tenant name
139 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400140 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800141
Jay Pipesf38eaac2012-06-21 13:37:35 -0400142 # If no creds are provided, we fall back on the defaults
143 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100144 self.username = username or self.config.identity.username
145 self.password = password or self.config.identity.password
146 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500147
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700148 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400149 msg = ("Missing required credentials. "
Sean Dague43cd9052013-07-19 12:20:04 -0400150 "username: %(u)s, password: %(p)s, "
151 "tenant_name: %(t)s" %
152 {'u': username, 'p': password, 't': tenant_name})
Jay Pipes3f981df2012-03-27 18:59:44 -0400153 raise exceptions.InvalidConfiguration(msg)
154
Jay Pipes7c88eb22013-01-16 21:32:43 -0500155 self.auth_url = self.config.identity.uri
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500156 self.auth_url_v3 = self.config.identity.uri_v3
Daryl Walleck587385b2012-03-03 13:00:26 -0600157
Li Ma216550f2013-06-12 11:26:08 -0700158 client_args = (self.config, self.username, self.password,
159 self.auth_url, self.tenant_name)
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500160
Li Ma216550f2013-06-12 11:26:08 -0700161 if self.auth_url_v3:
162 auth_version = 'v3'
163 client_args_v3_auth = (self.config, self.username,
164 self.password, self.auth_url_v3,
165 self.tenant_name, auth_version)
Daryl Walleck1465d612011-11-02 02:22:15 -0500166 else:
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500167 client_args_v3_auth = None
168
Attila Fazekas7e678de2013-07-13 14:13:28 +0200169 self.servers_client_v3_auth = None
170
171 if interface == 'xml':
172 self.servers_client = ServersClientXML(*client_args)
ivan-zhu8f992be2013-07-31 14:56:58 +0800173 self.servers_v3_client = ServersV3ClientXML(*client_args)
Attila Fazekas7e678de2013-07-13 14:13:28 +0200174 self.limits_client = LimitsClientXML(*client_args)
175 self.images_client = ImagesClientXML(*client_args)
176 self.keypairs_client = KeyPairsClientXML(*client_args)
177 self.quotas_client = QuotasClientXML(*client_args)
178 self.flavors_client = FlavorsClientXML(*client_args)
179 self.extensions_client = ExtensionsClientXML(*client_args)
180 self.volumes_extensions_client = VolumesExtensionsClientXML(
181 *client_args)
182 self.floating_ips_client = FloatingIPsClientXML(*client_args)
183 self.snapshots_client = SnapshotsClientXML(*client_args)
184 self.volumes_client = VolumesClientXML(*client_args)
185 self.volume_types_client = VolumeTypesClientXML(*client_args)
186 self.identity_client = IdentityClientXML(*client_args)
187 self.identity_v3_client = IdentityV3ClientXML(*client_args)
188 self.token_client = TokenClientXML(self.config)
189 self.security_groups_client = SecurityGroupsClientXML(
190 *client_args)
191 self.interfaces_client = InterfacesClientXML(*client_args)
192 self.endpoints_client = EndPointClientXML(*client_args)
193 self.fixed_ips_client = FixedIPsClientXML(*client_args)
194 self.availability_zone_client = AvailabilityZoneClientXML(
195 *client_args)
196 self.service_client = ServiceClientXML(*client_args)
197 self.aggregates_client = AggregatesClientXML(*client_args)
198 self.services_client = ServicesClientXML(*client_args)
199 self.tenant_usages_client = TenantUsagesClientXML(*client_args)
200 self.policy_client = PolicyClientXML(*client_args)
201 self.hypervisor_client = HypervisorClientXML(*client_args)
202 self.token_v3_client = V3TokenClientXML(*client_args)
203 self.network_client = NetworkClientXML(*client_args)
204 self.credentials_client = CredentialsClientXML(*client_args)
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500205
206 if client_args_v3_auth:
Attila Fazekas7e678de2013-07-13 14:13:28 +0200207 self.servers_client_v3_auth = ServersClientXML(
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500208 *client_args_v3_auth)
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500209
Attila Fazekas7e678de2013-07-13 14:13:28 +0200210 elif interface == 'json':
211 self.servers_client = ServersClientJSON(*client_args)
ivan-zhu8f992be2013-07-31 14:56:58 +0800212 self.servers_v3_client = ServersV3ClientJSON(*client_args)
Attila Fazekas7e678de2013-07-13 14:13:28 +0200213 self.limits_client = LimitsClientJSON(*client_args)
214 self.images_client = ImagesClientJSON(*client_args)
215 self.keypairs_client = KeyPairsClientJSON(*client_args)
216 self.quotas_client = QuotasClientJSON(*client_args)
217 self.flavors_client = FlavorsClientJSON(*client_args)
218 self.extensions_client = ExtensionsClientJSON(*client_args)
219 self.volumes_extensions_client = VolumesExtensionsClientJSON(
220 *client_args)
221 self.floating_ips_client = FloatingIPsClientJSON(*client_args)
222 self.snapshots_client = SnapshotsClientJSON(*client_args)
223 self.volumes_client = VolumesClientJSON(*client_args)
224 self.volume_types_client = VolumeTypesClientJSON(*client_args)
225 self.identity_client = IdentityClientJSON(*client_args)
226 self.identity_v3_client = IdentityV3ClientJSON(*client_args)
227 self.token_client = TokenClientJSON(self.config)
228 self.security_groups_client = SecurityGroupsClientJSON(
229 *client_args)
230 self.interfaces_client = InterfacesClientJSON(*client_args)
231 self.endpoints_client = EndPointClientJSON(*client_args)
232 self.fixed_ips_client = FixedIPsClientJSON(*client_args)
233 self.availability_zone_client = AvailabilityZoneClientJSON(
234 *client_args)
235 self.service_client = ServiceClientJSON(*client_args)
236 self.aggregates_client = AggregatesClientJSON(*client_args)
237 self.services_client = ServicesClientJSON(*client_args)
238 self.tenant_usages_client = TenantUsagesClientJSON(*client_args)
239 self.policy_client = PolicyClientJSON(*client_args)
240 self.hypervisor_client = HypervisorClientJSON(*client_args)
241 self.token_v3_client = V3TokenClientJSON(*client_args)
242 self.network_client = NetworkClientJSON(*client_args)
243 self.credentials_client = CredentialsClientJSON(*client_args)
244
245 if client_args_v3_auth:
246 self.servers_client_v3_auth = ServersClientJSON(
247 *client_args_v3_auth)
248 else:
Dan Smithcf8fab62012-08-14 08:03:48 -0700249 msg = "Unsupported interface type `%s'" % interface
250 raise exceptions.InvalidConfiguration(msg)
Attila Fazekas7e678de2013-07-13 14:13:28 +0200251
252 # common clients
Attila Fazekas8e99b992013-02-24 09:53:23 +0100253 self.hosts_client = HostsClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500254 self.account_client = AccountClient(*client_args)
Frederic Lepiedcf1868b2013-07-28 18:07:15 -0400255 if self.config.service_available.glance:
256 self.image_client = ImageClientJSON(*client_args)
257 self.image_client_v2 = ImageClientV2JSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500258 self.container_client = ContainerClient(*client_args)
259 self.object_client = ObjectClient(*client_args)
Steve Bakerc60e4e32013-05-06 15:22:41 +1200260 self.orchestration_client = OrchestrationClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100261 self.ec2api_client = botoclients.APIClientEC2(*client_args)
262 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530263 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530264 self.custom_account_client = \
265 AccountClientCustomizedHeader(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500266
267
Jay Pipesff10d552012-04-06 14:18:50 -0400268class AltManager(Manager):
269
270 """
271 Manager object that uses the alt_XXX credentials for its
272 managed client objects
273 """
274
275 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400276 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100277 super(AltManager, self).__init__(conf.identity.alt_username,
278 conf.identity.alt_password,
279 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400280
281
282class AdminManager(Manager):
283
284 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100285 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400286 managed client objects
287 """
288
James E. Blaire6d8ee12013-01-18 21:33:45 +0000289 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400290 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100291 super(AdminManager, self).__init__(conf.identity.admin_username,
292 conf.identity.admin_password,
293 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000294 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400295
296
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100297class ComputeAdminManager(Manager):
298
299 """
300 Manager object that uses the compute_admin credentials for its
301 managed client objects
302 """
303
304 def __init__(self, interface='json'):
305 conf = config.TempestConfig()
306 base = super(ComputeAdminManager, self)
307 base.__init__(conf.compute_admin.username,
308 conf.compute_admin.password,
309 conf.compute_admin.tenant_name,
310 interface=interface)
Steve Bakerc60e4e32013-05-06 15:22:41 +1200311
312
313class OrchestrationManager(Manager):
314 """
315 Manager object that uses the admin credentials for its
316 so that heat templates can create users
317 """
318 def __init__(self, interface='json'):
319 conf = config.TempestConfig()
320 base = super(OrchestrationManager, self)
321 base.__init__(conf.identity.admin_username,
322 conf.identity.admin_password,
Steve Bakerfd86f3c2013-06-28 12:51:20 +1200323 conf.identity.tenant_name,
Steve Bakerc60e4e32013-05-06 15:22:41 +1200324 interface=interface)