blob: d412ff58de86a0583bdcafdf4f601bf4024c5a2c [file] [log] [blame]
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +01001# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14from tempest import clients
15from tempest import config
Cao Xuan Hoanga585e942016-08-29 14:52:30 +070016from tempest.lib import auth
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010017
Paul Glass8abae332016-04-21 15:34:09 +000018from designate_tempest_plugin.services.dns.v2.json.blacklists_client import \
19 BlacklistsClient
sonu.kumar4beb93c2016-05-05 01:12:43 +090020from designate_tempest_plugin.services.dns.v2.json.pool_client import \
21 PoolClient
Michael Johnsondf9fda12021-07-09 16:39:08 +000022from designate_tempest_plugin.services.dns.v2.json.recordset_client import \
23 RecordsetClient
sonu.kumar2de01be2016-05-05 10:07:28 +090024from designate_tempest_plugin.services.dns.v2.json.tld_client import \
25 TldClient
Michael Johnsondf9fda12021-07-09 16:39:08 +000026from designate_tempest_plugin.services.dns.v2.json.zones_client import \
27 ZonesClient
28# TODO(johnsom) remove once neutron-tempest-plugin test_dns_integration
29# has been updated
30# https://review.opendev.org/c/openstack/neutron-tempest-plugin/+/800291
Paul Glasscf98c262016-05-13 19:34:37 +000031from designate_tempest_plugin.services.dns.query.query_client import \
32 QueryClient
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010033
34CONF = config.CONF
35
36
Michael Johnsondf9fda12021-07-09 16:39:08 +000037# TODO(johnsom) remove once neutron-tempest-plugin test_dns_integration
38# has been updated
39# https://review.opendev.org/c/openstack/neutron-tempest-plugin/+/800291
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010040class ManagerV2(clients.Manager):
Paul Glassd56330a2016-06-13 21:03:33 +000041
Graham Hayesc1978262017-01-11 17:17:32 +000042 def __init__(self, credentials=None):
43 super(ManagerV2, self).__init__(credentials)
Paul Glassd56330a2016-06-13 21:03:33 +000044 self._init_clients(self._get_params())
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010045
Paul Glassd56330a2016-06-13 21:03:33 +000046 def _init_clients(self, params):
47 self.zones_client = ZonesClient(**params)
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010048
Paul Glasscf98c262016-05-13 19:34:37 +000049 self.query_client = QueryClient(
50 nameservers=CONF.dns.nameservers,
51 query_timeout=CONF.dns.query_timeout,
52 build_interval=CONF.dns.build_interval,
53 build_timeout=CONF.dns.build_timeout,
54 )
Paul Glassd56330a2016-06-13 21:03:33 +000055
56 def _get_params(self):
57 params = dict(self.default_params)
58 params.update({
59 'auth_provider': self.auth_provider,
60 'service': CONF.dns.catalog_type,
61 'region': CONF.identity.region,
62 'endpoint_type': CONF.dns.endpoint_type,
63 'build_interval': CONF.dns.build_interval,
64 'build_timeout': CONF.dns.build_timeout
65 })
66 return params
67
68
Michael Johnsondf9fda12021-07-09 16:39:08 +000069class ManagerV2Unauthed(clients.Manager):
Paul Glassd56330a2016-06-13 21:03:33 +000070
Graham Hayesc1978262017-01-11 17:17:32 +000071 def __init__(self, credentials=None):
72 super(ManagerV2Unauthed, self).__init__(credentials)
Paul Glass4b07b382016-07-13 19:14:02 +000073 self.auth_provider = self._auth_provider_class()(
Paul Glassd56330a2016-06-13 21:03:33 +000074 credentials=self.auth_provider.credentials,
75 auth_url=self.auth_provider.auth_client.auth_url,
76 disable_ssl_certificate_validation=self.auth_provider.dscv,
77 ca_certs=self.auth_provider.ca_certs,
78 trace_requests=self.auth_provider.trace_requests,
79 )
80 self._init_clients(self._get_params())
81
Michael Johnsondf9fda12021-07-09 16:39:08 +000082 def _init_clients(self, params):
83 self.zones_client = ZonesClient(**params)
84 self.blacklists_client = BlacklistsClient(**params)
85 self.recordset_client = RecordsetClient(**params)
86 self.pool_client = PoolClient(**params)
87 self.tld_client = TldClient(**params)
88
Paul Glass4b07b382016-07-13 19:14:02 +000089 def _auth_provider_class(self):
90 if CONF.identity.auth_version == 'v3':
91 return KeystoneV3UnauthedProvider
92 else:
93 return KeystoneV2UnauthedProvider
Paul Glassd56330a2016-06-13 21:03:33 +000094
Michael Johnsondf9fda12021-07-09 16:39:08 +000095 def _get_params(self):
96 params = dict(self.default_params)
97 params.update({
98 'auth_provider': self.auth_provider,
99 'service': CONF.dns.catalog_type,
100 'region': CONF.identity.region,
101 'endpoint_type': CONF.dns.endpoint_type,
102 'build_interval': CONF.dns.build_interval,
103 'build_timeout': CONF.dns.build_timeout
104 })
105 return params
106
Paul Glass4b07b382016-07-13 19:14:02 +0000107
Cao Xuan Hoanga585e942016-08-29 14:52:30 +0700108class BaseUnauthedProvider(auth.KeystoneAuthProvider):
Paul Glassd56330a2016-06-13 21:03:33 +0000109
110 def _decorate_request(self, filters, method, url, headers=None, body=None,
111 auth_data=None):
Paul Glass4b07b382016-07-13 19:14:02 +0000112 result = super(BaseUnauthedProvider, self)._decorate_request(
Paul Glassd56330a2016-06-13 21:03:33 +0000113 filters, method, url, headers=headers, body=body,
114 auth_data=auth_data)
115 url, headers, body = result
116 try:
117 del headers['X-Auth-Token']
118 except KeyError:
119 pass
120 return url, headers, body
Paul Glass4b07b382016-07-13 19:14:02 +0000121
122
Cao Xuan Hoanga585e942016-08-29 14:52:30 +0700123class KeystoneV2UnauthedProvider(auth.KeystoneV2AuthProvider,
124 BaseUnauthedProvider):
Paul Glass4b07b382016-07-13 19:14:02 +0000125
126 def _decorate_request(self, *args, **kwargs):
127 return BaseUnauthedProvider._decorate_request(self, *args, **kwargs)
128
129
Cao Xuan Hoanga585e942016-08-29 14:52:30 +0700130class KeystoneV3UnauthedProvider(auth.KeystoneV3AuthProvider,
131 BaseUnauthedProvider):
Paul Glass4b07b382016-07-13 19:14:02 +0000132
133 def _decorate_request(self, *args, **kwargs):
134 return BaseUnauthedProvider._decorate_request(self, *args, **kwargs)