blob: 5ba888d40c5f0699b059653f3345ddbd6bb6a168 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
ChangBo Guo(gcb)9f147892016-09-21 14:01:32 +080017
Jay Pipesf38eaac2012-06-21 13:37:35 -040018from tempest import config
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010019from tempest.lib import auth
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010020from tempest.lib import exceptions as lib_exc
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010021from tempest.lib.services import clients
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +010022from tempest.services import object_storage
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010023from tempest.services import orchestration
Vincent Hou6b8a7b72012-08-25 01:24:33 +080024
Sean Dague86bd8422013-12-20 09:56:44 -050025CONF = config.CONF
Jay Pipes3f981df2012-03-27 18:59:44 -040026LOG = logging.getLogger(__name__)
27
Vincent Hou6b8a7b72012-08-25 01:24:33 +080028
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010029class Manager(clients.ServiceClients):
Ken'ichi Ohmichi2e2ee192015-11-19 09:48:27 +000030 """Top level manager for OpenStack tempest clients"""
Jay Pipes3f981df2012-03-27 18:59:44 -040031
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010032 default_params = config.service_client_config()
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000033
Jordan Pittiere4be9072017-01-04 19:17:35 +010034 def __init__(self, credentials, scope='project'):
ghanshyam4e2be342015-11-27 18:07:46 +090035 """Initialization of Manager class.
Brant Knudsonc7ca3342013-03-28 21:08:50 -050036
ghanshyam4e2be342015-11-27 18:07:46 +090037 Setup all services clients and make them available for tests cases.
38 :param credentials: type Credentials or TestResources
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010039 :param scope: default scope for tokens produced by the auth provider
ghanshyam4e2be342015-11-27 18:07:46 +090040 """
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010041 _, identity_uri = get_auth_provider_class(credentials)
42 super(Manager, self).__init__(
43 credentials=credentials, identity_uri=identity_uri, scope=scope,
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010044 region=CONF.identity.region,
45 client_parameters=self._prepare_configuration())
46 # TODO(andreaf) When clients are initialised without the right
47 # parameters available, the calls below will trigger a KeyError.
48 # We should catch that and raise a better error.
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000049 self._set_compute_clients()
50 self._set_identity_clients()
51 self._set_volume_clients()
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +000052 self._set_object_storage_clients()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010053 self._set_image_clients()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010054 self._set_network_clients()
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +000055
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010056 self.orchestration_client = orchestration.OrchestrationClient(
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000057 self.auth_provider,
58 CONF.orchestration.catalog_type,
59 CONF.orchestration.region or CONF.identity.region,
60 endpoint_type=CONF.orchestration.endpoint_type,
61 build_interval=CONF.orchestration.build_interval,
62 build_timeout=CONF.orchestration.build_timeout,
63 **self.default_params)
64
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010065 def _prepare_configuration(self):
66 """Map values from CONF into Manager parameters
67
68 This uses `config.service_client_config` for all services to collect
69 most configuration items needed to init the clients.
70 """
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +010071 # NOTE(andreaf) Once all service clients in Tempest are migrated
72 # to tempest.lib, their configuration will be picked up from the
73 # registry, and this method will become redundant.
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010074
75 configuration = {}
76
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +010077 # Setup the parameters for all Tempest services which are not in lib.
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010078 # NOTE(andreaf) Since client.py is an internal module of Tempest,
79 # it doesn't have to consider plugin configuration.
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +010080 for service in clients._tempest_internal_modules():
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010081 try:
82 # NOTE(andreaf) Use the unversioned service name to fetch
83 # the configuration since configuration is not versioned.
84 service_for_config = service.split('.')[0]
85 if service_for_config not in configuration:
86 configuration[service_for_config] = (
87 config.service_client_config(service_for_config))
88 except lib_exc.UnknownServiceClient:
Cao Xuan Hoang738ffcb2016-09-26 15:35:23 +070089 LOG.warning(
Jordan Pittier525ec712016-12-07 17:51:26 +010090 'Could not load configuration for service %s', service)
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010091
92 return configuration
93
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010094 def _set_network_clients(self):
Andrea Frittoli (andreaf)127c1022016-07-05 23:19:50 +010095 self.network_agents_client = self.network.AgentsClient()
96 self.network_extensions_client = self.network.ExtensionsClient()
97 self.networks_client = self.network.NetworksClient()
98 self.subnetpools_client = self.network.SubnetpoolsClient()
99 self.subnets_client = self.network.SubnetsClient()
100 self.ports_client = self.network.PortsClient()
101 self.network_quotas_client = self.network.QuotasClient()
102 self.floating_ips_client = self.network.FloatingIPsClient()
103 self.metering_labels_client = self.network.MeteringLabelsClient()
104 self.metering_label_rules_client = (
105 self.network.MeteringLabelRulesClient())
106 self.routers_client = self.network.RoutersClient()
107 self.security_group_rules_client = (
108 self.network.SecurityGroupRulesClient())
109 self.security_groups_client = self.network.SecurityGroupsClient()
110 self.network_versions_client = self.network.NetworkVersionsClient()
Jordan Pittiere5794632016-07-21 17:34:32 +0200111 self.service_providers_client = self.network.ServiceProvidersClient()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100112
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100113 def _set_image_clients(self):
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100114 if CONF.service_available.glance:
Andrea Frittoli (andreaf)e6a9b3f2016-06-30 16:24:32 +0100115 self.image_client = self.image_v1.ImagesClient()
116 self.image_member_client = self.image_v1.ImageMembersClient()
117 self.image_client_v2 = self.image_v2.ImagesClient()
118 self.image_member_client_v2 = self.image_v2.ImageMembersClient()
119 self.namespaces_client = self.image_v2.NamespacesClient()
120 self.resource_types_client = self.image_v2.ResourceTypesClient()
Li Wei37aff3c2016-10-20 19:50:02 +0800121 self.namespace_objects_client = \
122 self.image_v2.NamespaceObjectsClient()
Andrea Frittoli (andreaf)e6a9b3f2016-06-30 16:24:32 +0100123 self.schemas_client = self.image_v2.SchemasClient()
guo yunxian753e90a2016-11-17 20:12:22 +0800124 self.namespace_properties_client = \
125 self.image_v2.NamespacePropertiesClient()
guo yunxian4f67d822016-11-29 11:12:58 +0800126 self.namespace_tags_client = \
127 self.image_v2.NamespaceTagsClient()
Ken'ichi Ohmichif72343e2017-03-10 12:53:14 -0800128 self.image_versions_client = \
129 self.image_v2.VersionsClient()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100130
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000131 def _set_compute_clients(self):
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100132 self.agents_client = self.compute.AgentsClient()
133 self.compute_networks_client = self.compute.NetworksClient()
134 self.migrations_client = self.compute.MigrationsClient()
Ken'ichi Ohmichi65225ef2014-11-19 01:06:25 +0000135 self.security_group_default_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100136 self.compute.SecurityGroupDefaultRulesClient())
137 self.certificates_client = self.compute.CertificatesClient()
138 eip = CONF.compute_feature_enabled.enable_instance_password
139 self.servers_client = self.compute.ServersClient(
140 enable_instance_password=eip)
141 self.server_groups_client = self.compute.ServerGroupsClient()
142 self.limits_client = self.compute.LimitsClient()
143 self.compute_images_client = self.compute.ImagesClient()
144 self.keypairs_client = self.compute.KeyPairsClient()
145 self.quotas_client = self.compute.QuotasClient()
146 self.quota_classes_client = self.compute.QuotaClassesClient()
147 self.flavors_client = self.compute.FlavorsClient()
148 self.extensions_client = self.compute.ExtensionsClient()
149 self.floating_ip_pools_client = self.compute.FloatingIPPoolsClient()
150 self.floating_ips_bulk_client = self.compute.FloatingIPsBulkClient()
151 self.compute_floating_ips_client = self.compute.FloatingIPsClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100152 self.compute_security_group_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100153 self.compute.SecurityGroupRulesClient())
154 self.compute_security_groups_client = (
155 self.compute.SecurityGroupsClient())
156 self.interfaces_client = self.compute.InterfacesClient()
157 self.fixed_ips_client = self.compute.FixedIPsClient()
158 self.availability_zone_client = self.compute.AvailabilityZoneClient()
159 self.aggregates_client = self.compute.AggregatesClient()
160 self.services_client = self.compute.ServicesClient()
161 self.tenant_usages_client = self.compute.TenantUsagesClient()
162 self.hosts_client = self.compute.HostsClient()
163 self.hypervisor_client = self.compute.HypervisorClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100164 self.instance_usages_audit_log_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100165 self.compute.InstanceUsagesAuditLogClient())
166 self.tenant_networks_client = self.compute.TenantNetworksClient()
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000167
168 # NOTE: The following client needs special timeout values because
169 # the API is a proxy for the other component.
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100170 params_volume = {}
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100171 for _key in ('build_interval', 'build_timeout'):
172 _value = self.parameters['volume'].get(_key)
173 if _value:
174 params_volume[_key] = _value
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100175 self.volumes_extensions_client = self.compute.VolumesClient(
176 **params_volume)
177 self.compute_versions_client = self.compute.VersionsClient(
178 **params_volume)
179 self.snapshots_extensions_client = self.compute.SnapshotsClient(
180 **params_volume)
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +0000181
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000182 def _set_identity_clients(self):
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300183 # Clients below use the admin endpoint type of Keystone API v2
ghanshyam68227d62016-12-22 16:17:42 +0900184 params_v2_admin = {
185 'endpoint_type': CONF.identity.v2_admin_endpoint_type}
186 self.endpoints_client = self.identity_v2.EndpointsClient(
187 **params_v2_admin)
188 self.identity_client = self.identity_v2.IdentityClient(
189 **params_v2_admin)
190 self.tenants_client = self.identity_v2.TenantsClient(
191 **params_v2_admin)
192 self.roles_client = self.identity_v2.RolesClient(**params_v2_admin)
193 self.users_client = self.identity_v2.UsersClient(**params_v2_admin)
194 self.identity_services_client = self.identity_v2.ServicesClient(
195 **params_v2_admin)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300196
197 # Clients below use the public endpoint type of Keystone API v2
ghanshyam68227d62016-12-22 16:17:42 +0900198 params_v2_public = {
199 'endpoint_type': CONF.identity.v2_public_endpoint_type}
200 self.identity_public_client = self.identity_v2.IdentityClient(
201 **params_v2_public)
202 self.tenants_public_client = self.identity_v2.TenantsClient(
203 **params_v2_public)
204 self.users_public_client = self.identity_v2.UsersClient(
205 **params_v2_public)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300206
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100207 # Clients below use the endpoint type of Keystone API v3, which is set
208 # in endpoint_type
ghanshyam68227d62016-12-22 16:17:42 +0900209 params_v3 = {'endpoint_type': CONF.identity.v3_endpoint_type}
210 self.domains_client = self.identity_v3.DomainsClient(**params_v3)
211 self.identity_v3_client = self.identity_v3.IdentityClient(**params_v3)
212 self.trusts_client = self.identity_v3.TrustsClient(**params_v3)
213 self.users_v3_client = self.identity_v3.UsersClient(**params_v3)
214 self.endpoints_v3_client = self.identity_v3.EndPointsClient(
215 **params_v3)
216 self.roles_v3_client = self.identity_v3.RolesClient(**params_v3)
217 self.inherited_roles_client = self.identity_v3.InheritedRolesClient(
218 **params_v3)
219 self.role_assignments_client = self.identity_v3.RoleAssignmentsClient(
220 **params_v3)
221 self.identity_services_v3_client = self.identity_v3.ServicesClient(
222 **params_v3)
223 self.policies_client = self.identity_v3.PoliciesClient(**params_v3)
224 self.projects_client = self.identity_v3.ProjectsClient(**params_v3)
225 self.regions_client = self.identity_v3.RegionsClient(**params_v3)
226 self.credentials_client = self.identity_v3.CredentialsClient(
227 **params_v3)
228 self.groups_client = self.identity_v3.GroupsClient(**params_v3)
Ken'ichi Ohmichida26b162017-03-03 15:53:46 -0800229 self.identity_versions_v3_client = self.identity_v3.VersionsClient(
230 **params_v3)
Nicolas Helgeson8e2d4032017-02-14 09:36:37 -0800231 self.oauth_consumers_client = self.identity_v3.OAUTHConsumerClient(
232 **params_v3)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300233
Andrea Frittoli90012352015-02-25 21:58:02 +0000234 # Token clients do not use the catalog. They only need default_params.
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100235 # They read auth_url, so they should only be set if the corresponding
236 # API version is marked as enabled
237 if CONF.identity_feature_enabled.api_v2:
238 if CONF.identity.uri:
Andrea Frittoli8b8db532016-12-22 11:21:47 +0000239 self.token_client = self.identity_v2.TokenClient(
240 auth_url=CONF.identity.uri)
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100241 else:
242 msg = 'Identity v2 API enabled, but no identity.uri set'
Matthew Treinish4217a702016-10-07 17:27:11 -0400243 raise lib_exc.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000244 if CONF.identity_feature_enabled.api_v3:
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100245 if CONF.identity.uri_v3:
Andrea Frittoli8b8db532016-12-22 11:21:47 +0000246 self.token_v3_client = self.identity_v3.V3TokenClient(
247 auth_url=CONF.identity.uri_v3)
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100248 else:
249 msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
Matthew Treinish4217a702016-10-07 17:27:11 -0400250 raise lib_exc.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000251
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000252 def _set_volume_clients(self):
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000253
lkuchlan3fce7fb2016-10-31 15:40:35 +0200254 self.volume_qos_client = self.volume_v1.QosSpecsClient()
255 self.volume_qos_v2_client = self.volume_v2.QosSpecsClient()
256 self.volume_services_client = self.volume_v1.ServicesClient()
257 self.volume_services_v2_client = self.volume_v2.ServicesClient()
258 self.backups_client = self.volume_v1.BackupsClient()
259 self.backups_v2_client = self.volume_v2.BackupsClient()
260 self.encryption_types_client = self.volume_v1.EncryptionTypesClient()
261 self.encryption_types_v2_client = \
262 self.volume_v2.EncryptionTypesClient()
lkuchlancb2f8592016-07-17 15:18:01 +0300263 self.snapshot_manage_v2_client = self.volume_v2.SnapshotManageClient()
lkuchlan3fce7fb2016-10-31 15:40:35 +0200264 self.snapshots_client = self.volume_v1.SnapshotsClient()
265 self.snapshots_v2_client = self.volume_v2.SnapshotsClient()
jeremy.zhangf4fbf302017-03-22 11:25:53 +0800266 self.volume_manage_v2_client = self.volume_v2.VolumeManageClient()
lkuchlan3fce7fb2016-10-31 15:40:35 +0200267 self.volumes_client = self.volume_v1.VolumesClient()
268 self.volumes_v2_client = self.volume_v2.VolumesClient()
Benny Kopilov37b2bee2016-11-06 09:07:19 +0200269 self.volume_v3_messages_client = self.volume_v3.MessagesClient()
Ken'ichi Ohmichi4adae2f2017-03-15 15:47:44 -0700270 self.volume_v3_versions_client = self.volume_v3.VersionsClient()
lkuchlan3fce7fb2016-10-31 15:40:35 +0200271 self.volume_types_client = self.volume_v1.TypesClient()
272 self.volume_types_v2_client = self.volume_v2.TypesClient()
273 self.volume_hosts_client = self.volume_v1.HostsClient()
274 self.volume_hosts_v2_client = self.volume_v2.HostsClient()
275 self.volume_quotas_client = self.volume_v1.QuotasClient()
276 self.volume_quotas_v2_client = self.volume_v2.QuotasClient()
jeremy.zhang644b01d2017-04-13 12:59:49 +0800277 self.volume_quota_classes_v2_client = \
278 self.volume_v2.QuotaClassesClient()
lkuchlan3fce7fb2016-10-31 15:40:35 +0200279 self.volumes_extension_client = self.volume_v1.ExtensionsClient()
280 self.volumes_v2_extension_client = self.volume_v2.ExtensionsClient()
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000281 self.volume_availability_zone_client = \
lkuchlan3fce7fb2016-10-31 15:40:35 +0200282 self.volume_v1.AvailabilityZoneClient()
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000283 self.volume_v2_availability_zone_client = \
lkuchlan3fce7fb2016-10-31 15:40:35 +0200284 self.volume_v2.AvailabilityZoneClient()
bkopilov14193082016-05-31 10:01:28 +0300285 self.volume_limits_client = self.volume_v1.LimitsClient()
286 self.volume_v2_limits_client = self.volume_v2.LimitsClient()
lkuchlan7bba16c2016-09-04 12:36:04 +0300287 self.volume_capabilities_v2_client = \
288 self.volume_v2.CapabilitiesClient()
289 self.volume_scheduler_stats_v2_client = \
290 self.volume_v2.SchedulerStatsClient()
ghanshyam59614b42017-02-24 16:32:02 +0000291 self.volume_transfers_v2_client = \
292 self.volume_v2.TransfersClient()
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000293
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +0000294 def _set_object_storage_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100295 # Mandatory parameters (always defined)
296 params = self.parameters['object-storage']
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +0000297
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100298 self.account_client = object_storage.AccountClient(self.auth_provider,
299 **params)
ghanshyamf29831d2016-12-12 18:45:23 +0900300 self.capabilities_client = object_storage.CapabilitiesClient(
301 self.auth_provider, **params)
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100302 self.container_client = object_storage.ContainerClient(
303 self.auth_provider, **params)
304 self.object_client = object_storage.ObjectClient(self.auth_provider,
305 **params)
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100306
307
308def get_auth_provider_class(credentials):
309 if isinstance(credentials, auth.KeystoneV3Credentials):
310 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
311 else:
312 return auth.KeystoneV2AuthProvider, CONF.identity.uri
313
314
315def get_auth_provider(credentials, pre_auth=False, scope='project'):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100316 # kwargs for auth provider match the common ones used by service clients
317 default_params = config.service_client_config()
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100318 if credentials is None:
guo yunxian654a9212016-11-02 17:26:42 +0800319 raise lib_exc.InvalidCredentials(
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100320 'Credentials must be specified')
321 auth_provider_class, auth_url = get_auth_provider_class(
322 credentials)
323 _auth_provider = auth_provider_class(credentials, auth_url,
324 scope=scope,
325 **default_params)
326 if pre_auth:
327 _auth_provider.set_auth()
328 return _auth_provider