Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 1 | # 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. |
| 14 | from tempest import clients |
| 15 | from tempest import config |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 16 | from tempest.lib import auth |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 17 | |
Paul Glass | 8abae33 | 2016-04-21 15:34:09 +0000 | [diff] [blame] | 18 | from designate_tempest_plugin.services.dns.v2.json.blacklists_client import \ |
| 19 | BlacklistsClient |
sonu.kumar | 4beb93c | 2016-05-05 01:12:43 +0900 | [diff] [blame] | 20 | from designate_tempest_plugin.services.dns.v2.json.pool_client import \ |
| 21 | PoolClient |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame] | 22 | from designate_tempest_plugin.services.dns.v2.json.recordset_client import \ |
| 23 | RecordsetClient |
sonu.kumar | 2de01be | 2016-05-05 10:07:28 +0900 | [diff] [blame] | 24 | from designate_tempest_plugin.services.dns.v2.json.tld_client import \ |
| 25 | TldClient |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame] | 26 | from designate_tempest_plugin.services.dns.v2.json.zones_client import \ |
| 27 | ZonesClient |
Michael Johnson | ac961e5 | 2021-07-09 18:26:04 +0000 | [diff] [blame] | 28 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 29 | |
| 30 | CONF = config.CONF |
| 31 | |
| 32 | |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame] | 33 | class ManagerV2Unauthed(clients.Manager): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 34 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 35 | def __init__(self, credentials=None): |
| 36 | super(ManagerV2Unauthed, self).__init__(credentials) |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 37 | self.auth_provider = self._auth_provider_class()( |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 38 | credentials=self.auth_provider.credentials, |
| 39 | auth_url=self.auth_provider.auth_client.auth_url, |
| 40 | disable_ssl_certificate_validation=self.auth_provider.dscv, |
| 41 | ca_certs=self.auth_provider.ca_certs, |
| 42 | trace_requests=self.auth_provider.trace_requests, |
| 43 | ) |
| 44 | self._init_clients(self._get_params()) |
| 45 | |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame] | 46 | def _init_clients(self, params): |
| 47 | self.zones_client = ZonesClient(**params) |
| 48 | self.blacklists_client = BlacklistsClient(**params) |
| 49 | self.recordset_client = RecordsetClient(**params) |
| 50 | self.pool_client = PoolClient(**params) |
| 51 | self.tld_client = TldClient(**params) |
| 52 | |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 53 | def _auth_provider_class(self): |
| 54 | if CONF.identity.auth_version == 'v3': |
| 55 | return KeystoneV3UnauthedProvider |
| 56 | else: |
| 57 | return KeystoneV2UnauthedProvider |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 58 | |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame] | 59 | def _get_params(self): |
| 60 | params = dict(self.default_params) |
| 61 | params.update({ |
| 62 | 'auth_provider': self.auth_provider, |
| 63 | 'service': CONF.dns.catalog_type, |
| 64 | 'region': CONF.identity.region, |
| 65 | 'endpoint_type': CONF.dns.endpoint_type, |
| 66 | 'build_interval': CONF.dns.build_interval, |
| 67 | 'build_timeout': CONF.dns.build_timeout |
| 68 | }) |
| 69 | return params |
| 70 | |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 71 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 72 | class BaseUnauthedProvider(auth.KeystoneAuthProvider): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 73 | |
| 74 | def _decorate_request(self, filters, method, url, headers=None, body=None, |
| 75 | auth_data=None): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 76 | result = super(BaseUnauthedProvider, self)._decorate_request( |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 77 | filters, method, url, headers=headers, body=body, |
| 78 | auth_data=auth_data) |
| 79 | url, headers, body = result |
| 80 | try: |
| 81 | del headers['X-Auth-Token'] |
| 82 | except KeyError: |
| 83 | pass |
| 84 | return url, headers, body |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 85 | |
| 86 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 87 | class KeystoneV2UnauthedProvider(auth.KeystoneV2AuthProvider, |
| 88 | BaseUnauthedProvider): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 89 | |
| 90 | def _decorate_request(self, *args, **kwargs): |
| 91 | return BaseUnauthedProvider._decorate_request(self, *args, **kwargs) |
| 92 | |
| 93 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 94 | class KeystoneV3UnauthedProvider(auth.KeystoneV3AuthProvider, |
| 95 | BaseUnauthedProvider): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 96 | |
| 97 | def _decorate_request(self, *args, **kwargs): |
| 98 | return BaseUnauthedProvider._decorate_request(self, *args, **kwargs) |