blob: 85c2242fc1c1c5c154653ac836b85f4d72e50b7f [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes3f981df2012-03-27 18:59:44 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Jay Pipesf38eaac2012-06-21 13:37:35 -040016from tempest import config
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010017from tempest.lib import auth
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010018from tempest.lib import exceptions as lib_exc
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010019from tempest.lib.services import clients
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +010020from tempest.services import object_storage
Vincent Hou6b8a7b72012-08-25 01:24:33 +080021
Sean Dague86bd8422013-12-20 09:56:44 -050022CONF = config.CONF
Jay Pipes3f981df2012-03-27 18:59:44 -040023
Vincent Hou6b8a7b72012-08-25 01:24:33 +080024
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010025class Manager(clients.ServiceClients):
Ken'ichi Ohmichi2e2ee192015-11-19 09:48:27 +000026 """Top level manager for OpenStack tempest clients"""
Jay Pipes3f981df2012-03-27 18:59:44 -040027
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010028 default_params = config.service_client_config()
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000029
Jordan Pittiere4be9072017-01-04 19:17:35 +010030 def __init__(self, credentials, scope='project'):
ghanshyam4e2be342015-11-27 18:07:46 +090031 """Initialization of Manager class.
Brant Knudsonc7ca3342013-03-28 21:08:50 -050032
ghanshyam4e2be342015-11-27 18:07:46 +090033 Setup all services clients and make them available for tests cases.
34 :param credentials: type Credentials or TestResources
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010035 :param scope: default scope for tokens produced by the auth provider
ghanshyam4e2be342015-11-27 18:07:46 +090036 """
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010037 _, identity_uri = get_auth_provider_class(credentials)
38 super(Manager, self).__init__(
39 credentials=credentials, identity_uri=identity_uri, scope=scope,
Andrea Frittoli7ae56bb2017-05-24 10:56:46 +010040 region=CONF.identity.region)
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010041 # TODO(andreaf) When clients are initialised without the right
42 # parameters available, the calls below will trigger a KeyError.
43 # We should catch that and raise a better error.
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000044 self._set_compute_clients()
45 self._set_identity_clients()
46 self._set_volume_clients()
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +000047 self._set_object_storage_clients()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010048 self._set_image_clients()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010049 self._set_network_clients()
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +000050
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010051 def _set_network_clients(self):
Andrea Frittoli (andreaf)127c1022016-07-05 23:19:50 +010052 self.network_agents_client = self.network.AgentsClient()
53 self.network_extensions_client = self.network.ExtensionsClient()
54 self.networks_client = self.network.NetworksClient()
55 self.subnetpools_client = self.network.SubnetpoolsClient()
56 self.subnets_client = self.network.SubnetsClient()
57 self.ports_client = self.network.PortsClient()
58 self.network_quotas_client = self.network.QuotasClient()
59 self.floating_ips_client = self.network.FloatingIPsClient()
60 self.metering_labels_client = self.network.MeteringLabelsClient()
61 self.metering_label_rules_client = (
62 self.network.MeteringLabelRulesClient())
63 self.routers_client = self.network.RoutersClient()
64 self.security_group_rules_client = (
65 self.network.SecurityGroupRulesClient())
66 self.security_groups_client = self.network.SecurityGroupsClient()
67 self.network_versions_client = self.network.NetworkVersionsClient()
Jordan Pittiere5794632016-07-21 17:34:32 +020068 self.service_providers_client = self.network.ServiceProvidersClient()
Felipe Monteiro11779422017-05-18 06:10:26 +010069 self.tags_client = self.network.TagsClient()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010070
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010071 def _set_image_clients(self):
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010072 if CONF.service_available.glance:
Andrea Frittoli (andreaf)e6a9b3f2016-06-30 16:24:32 +010073 self.image_client = self.image_v1.ImagesClient()
74 self.image_member_client = self.image_v1.ImageMembersClient()
75 self.image_client_v2 = self.image_v2.ImagesClient()
76 self.image_member_client_v2 = self.image_v2.ImageMembersClient()
77 self.namespaces_client = self.image_v2.NamespacesClient()
78 self.resource_types_client = self.image_v2.ResourceTypesClient()
Li Wei37aff3c2016-10-20 19:50:02 +080079 self.namespace_objects_client = \
80 self.image_v2.NamespaceObjectsClient()
Andrea Frittoli (andreaf)e6a9b3f2016-06-30 16:24:32 +010081 self.schemas_client = self.image_v2.SchemasClient()
guo yunxian753e90a2016-11-17 20:12:22 +080082 self.namespace_properties_client = \
83 self.image_v2.NamespacePropertiesClient()
guo yunxian4f67d822016-11-29 11:12:58 +080084 self.namespace_tags_client = \
85 self.image_v2.NamespaceTagsClient()
Ken'ichi Ohmichif72343e2017-03-10 12:53:14 -080086 self.image_versions_client = \
87 self.image_v2.VersionsClient()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010088
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000089 def _set_compute_clients(self):
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +010090 self.agents_client = self.compute.AgentsClient()
91 self.compute_networks_client = self.compute.NetworksClient()
92 self.migrations_client = self.compute.MigrationsClient()
Ken'ichi Ohmichi65225ef2014-11-19 01:06:25 +000093 self.security_group_default_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +010094 self.compute.SecurityGroupDefaultRulesClient())
95 self.certificates_client = self.compute.CertificatesClient()
96 eip = CONF.compute_feature_enabled.enable_instance_password
97 self.servers_client = self.compute.ServersClient(
98 enable_instance_password=eip)
99 self.server_groups_client = self.compute.ServerGroupsClient()
100 self.limits_client = self.compute.LimitsClient()
101 self.compute_images_client = self.compute.ImagesClient()
102 self.keypairs_client = self.compute.KeyPairsClient()
103 self.quotas_client = self.compute.QuotasClient()
104 self.quota_classes_client = self.compute.QuotaClassesClient()
105 self.flavors_client = self.compute.FlavorsClient()
106 self.extensions_client = self.compute.ExtensionsClient()
107 self.floating_ip_pools_client = self.compute.FloatingIPPoolsClient()
108 self.floating_ips_bulk_client = self.compute.FloatingIPsBulkClient()
109 self.compute_floating_ips_client = self.compute.FloatingIPsClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100110 self.compute_security_group_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100111 self.compute.SecurityGroupRulesClient())
112 self.compute_security_groups_client = (
113 self.compute.SecurityGroupsClient())
114 self.interfaces_client = self.compute.InterfacesClient()
115 self.fixed_ips_client = self.compute.FixedIPsClient()
116 self.availability_zone_client = self.compute.AvailabilityZoneClient()
117 self.aggregates_client = self.compute.AggregatesClient()
118 self.services_client = self.compute.ServicesClient()
119 self.tenant_usages_client = self.compute.TenantUsagesClient()
120 self.hosts_client = self.compute.HostsClient()
121 self.hypervisor_client = self.compute.HypervisorClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100122 self.instance_usages_audit_log_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100123 self.compute.InstanceUsagesAuditLogClient())
124 self.tenant_networks_client = self.compute.TenantNetworksClient()
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000125
126 # NOTE: The following client needs special timeout values because
127 # the API is a proxy for the other component.
Andrea Frittoli20322572017-04-09 19:13:13 +0200128 params_volume = {
129 'build_interval': CONF.volume.build_interval,
130 'build_timeout': CONF.volume.build_timeout
131 }
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100132 self.volumes_extensions_client = self.compute.VolumesClient(
133 **params_volume)
134 self.compute_versions_client = self.compute.VersionsClient(
135 **params_volume)
136 self.snapshots_extensions_client = self.compute.SnapshotsClient(
137 **params_volume)
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +0000138
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000139 def _set_identity_clients(self):
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300140 # Clients below use the admin endpoint type of Keystone API v2
ghanshyam68227d62016-12-22 16:17:42 +0900141 params_v2_admin = {
142 'endpoint_type': CONF.identity.v2_admin_endpoint_type}
143 self.endpoints_client = self.identity_v2.EndpointsClient(
144 **params_v2_admin)
145 self.identity_client = self.identity_v2.IdentityClient(
146 **params_v2_admin)
147 self.tenants_client = self.identity_v2.TenantsClient(
148 **params_v2_admin)
149 self.roles_client = self.identity_v2.RolesClient(**params_v2_admin)
150 self.users_client = self.identity_v2.UsersClient(**params_v2_admin)
151 self.identity_services_client = self.identity_v2.ServicesClient(
152 **params_v2_admin)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300153
154 # Clients below use the public endpoint type of Keystone API v2
ghanshyam68227d62016-12-22 16:17:42 +0900155 params_v2_public = {
156 'endpoint_type': CONF.identity.v2_public_endpoint_type}
157 self.identity_public_client = self.identity_v2.IdentityClient(
158 **params_v2_public)
159 self.tenants_public_client = self.identity_v2.TenantsClient(
160 **params_v2_public)
161 self.users_public_client = self.identity_v2.UsersClient(
162 **params_v2_public)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300163
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100164 # Clients below use the endpoint type of Keystone API v3, which is set
165 # in endpoint_type
ghanshyam68227d62016-12-22 16:17:42 +0900166 params_v3 = {'endpoint_type': CONF.identity.v3_endpoint_type}
167 self.domains_client = self.identity_v3.DomainsClient(**params_v3)
168 self.identity_v3_client = self.identity_v3.IdentityClient(**params_v3)
169 self.trusts_client = self.identity_v3.TrustsClient(**params_v3)
170 self.users_v3_client = self.identity_v3.UsersClient(**params_v3)
171 self.endpoints_v3_client = self.identity_v3.EndPointsClient(
172 **params_v3)
173 self.roles_v3_client = self.identity_v3.RolesClient(**params_v3)
174 self.inherited_roles_client = self.identity_v3.InheritedRolesClient(
175 **params_v3)
176 self.role_assignments_client = self.identity_v3.RoleAssignmentsClient(
177 **params_v3)
178 self.identity_services_v3_client = self.identity_v3.ServicesClient(
179 **params_v3)
180 self.policies_client = self.identity_v3.PoliciesClient(**params_v3)
181 self.projects_client = self.identity_v3.ProjectsClient(**params_v3)
182 self.regions_client = self.identity_v3.RegionsClient(**params_v3)
183 self.credentials_client = self.identity_v3.CredentialsClient(
184 **params_v3)
185 self.groups_client = self.identity_v3.GroupsClient(**params_v3)
Ken'ichi Ohmichida26b162017-03-03 15:53:46 -0800186 self.identity_versions_v3_client = self.identity_v3.VersionsClient(
187 **params_v3)
Nicolas Helgeson8e2d4032017-02-14 09:36:37 -0800188 self.oauth_consumers_client = self.identity_v3.OAUTHConsumerClient(
189 **params_v3)
Hemanth Nakkinad9594f52017-04-19 11:14:40 +0530190 self.oauth_token_client = self.identity_v3.OAUTHTokenClient(
191 **params_v3)
Felipe Monteiro94d85772017-04-03 22:04:06 +0100192 self.domain_config_client = self.identity_v3.DomainConfigurationClient(
193 **params_v3)
Pradeep Kumar KS5d52d3a2017-03-18 11:41:15 +0530194 self.endpoint_filter_client = \
195 self.identity_v3.EndPointsFilterClient(**params_v3)
Chi Lod0ed8b02017-04-22 05:35:53 -0500196 self.endpoint_groups_client = self.identity_v3.EndPointGroupsClient(
197 **params_v3)
Megan Guineyd0295162017-05-23 23:57:53 -0700198 self.catalog_client = self.identity_v3.CatalogClient(**params_v3)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300199
Andrea Frittoli90012352015-02-25 21:58:02 +0000200 # Token clients do not use the catalog. They only need default_params.
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100201 # They read auth_url, so they should only be set if the corresponding
202 # API version is marked as enabled
203 if CONF.identity_feature_enabled.api_v2:
204 if CONF.identity.uri:
Andrea Frittoli8b8db532016-12-22 11:21:47 +0000205 self.token_client = self.identity_v2.TokenClient(
206 auth_url=CONF.identity.uri)
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100207 else:
208 msg = 'Identity v2 API enabled, but no identity.uri set'
Matthew Treinish4217a702016-10-07 17:27:11 -0400209 raise lib_exc.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000210 if CONF.identity_feature_enabled.api_v3:
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100211 if CONF.identity.uri_v3:
Andrea Frittoli8b8db532016-12-22 11:21:47 +0000212 self.token_v3_client = self.identity_v3.V3TokenClient(
213 auth_url=CONF.identity.uri_v3)
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100214 else:
215 msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
Matthew Treinish4217a702016-10-07 17:27:11 -0400216 raise lib_exc.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000217
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000218 def _set_volume_clients(self):
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000219
Sean McGinnisff5f0c12017-07-07 16:39:24 -0500220 if CONF.volume_feature_enabled.api_v1:
221 self.backups_client = self.volume_v1.BackupsClient()
222 self.encryption_types_client = \
223 self.volume_v1.EncryptionTypesClient()
224 self.snapshots_client = self.volume_v1.SnapshotsClient()
225 self.volume_availability_zone_client = \
226 self.volume_v1.AvailabilityZoneClient()
227 self.volume_hosts_client = self.volume_v1.HostsClient()
228 self.volume_limits_client = self.volume_v1.LimitsClient()
229 self.volume_qos_client = self.volume_v1.QosSpecsClient()
230 self.volume_quotas_client = self.volume_v1.QuotasClient()
231 self.volume_services_client = self.volume_v1.ServicesClient()
232 self.volume_types_client = self.volume_v1.TypesClient()
233 self.volumes_client = self.volume_v1.VolumesClient()
234 self.volumes_extension_client = self.volume_v1.ExtensionsClient()
235
236 if CONF.volume_feature_enabled.api_v2:
237 self.backups_v2_client = self.volume_v2.BackupsClient()
238 self.encryption_types_v2_client = \
239 self.volume_v2.EncryptionTypesClient()
240 self.snapshot_manage_v2_client = \
241 self.volume_v2.SnapshotManageClient()
242 self.snapshots_v2_client = self.volume_v2.SnapshotsClient()
243 self.volume_capabilities_v2_client = \
244 self.volume_v2.CapabilitiesClient()
245 self.volume_manage_v2_client = self.volume_v2.VolumeManageClient()
246 self.volume_qos_v2_client = self.volume_v2.QosSpecsClient()
247 self.volume_services_v2_client = self.volume_v2.ServicesClient()
248 self.volume_types_v2_client = self.volume_v2.TypesClient()
249 self.volume_hosts_v2_client = self.volume_v2.HostsClient()
250 self.volume_quotas_v2_client = self.volume_v2.QuotasClient()
251 self.volume_quota_classes_v2_client = \
252 self.volume_v2.QuotaClassesClient()
253 self.volume_scheduler_stats_v2_client = \
254 self.volume_v2.SchedulerStatsClient()
255 self.volume_transfers_v2_client = \
256 self.volume_v2.TransfersClient()
257 self.volume_v2_availability_zone_client = \
258 self.volume_v2.AvailabilityZoneClient()
259 self.volume_v2_limits_client = self.volume_v2.LimitsClient()
260 self.volumes_v2_client = self.volume_v2.VolumesClient()
261 self.volumes_v2_extension_client = \
262 self.volume_v2.ExtensionsClient()
263
264 # Set default client for users that don't need explicit version
265 self.volumes_client_latest = self.volumes_v2_client
266
267 if CONF.volume_feature_enabled.api_v3:
268 self.backups_v3_client = self.volume_v3.BackupsClient()
269 self.group_types_v3_client = self.volume_v3.GroupTypesClient()
270 self.groups_v3_client = self.volume_v3.GroupsClient()
271 self.volume_v3_messages_client = self.volume_v3.MessagesClient()
272 self.volume_v3_versions_client = self.volume_v3.VersionsClient()
273 self.volumes_v3_client = self.volume_v3.VolumesClient()
274
275 # Set default client for users that don't need explicit version
276 self.volumes_client_latest = self.volumes_v3_client
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000277
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +0000278 def _set_object_storage_clients(self):
Andrea Frittoli7ae56bb2017-05-24 10:56:46 +0100279 # NOTE(andreaf) Load configuration from config. Once object storage
280 # is in lib, configuration will be pulled directly from the registry
281 # and this will not be required anymore.
282 params = config.service_client_config('object-storage')
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +0000283
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100284 self.account_client = object_storage.AccountClient(self.auth_provider,
285 **params)
ghanshyam36085442016-12-12 15:39:02 +0900286 self.bulk_client = object_storage.BulkMiddlewareClient(
287 self.auth_provider, **params)
ghanshyamf29831d2016-12-12 18:45:23 +0900288 self.capabilities_client = object_storage.CapabilitiesClient(
289 self.auth_provider, **params)
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100290 self.container_client = object_storage.ContainerClient(
291 self.auth_provider, **params)
292 self.object_client = object_storage.ObjectClient(self.auth_provider,
293 **params)
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100294
295
296def get_auth_provider_class(credentials):
297 if isinstance(credentials, auth.KeystoneV3Credentials):
298 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
299 else:
300 return auth.KeystoneV2AuthProvider, CONF.identity.uri
301
302
303def get_auth_provider(credentials, pre_auth=False, scope='project'):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100304 # kwargs for auth provider match the common ones used by service clients
305 default_params = config.service_client_config()
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100306 if credentials is None:
guo yunxian654a9212016-11-02 17:26:42 +0800307 raise lib_exc.InvalidCredentials(
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100308 'Credentials must be specified')
309 auth_provider_class, auth_url = get_auth_provider_class(
310 credentials)
311 _auth_provider = auth_provider_class(credentials, auth_url,
312 scope=scope,
313 **default_params)
314 if pre_auth:
315 _auth_provider.set_auth()
316 return _auth_provider