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 |
| 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 Glass | cf98c26 | 2016-05-13 19:34:37 +0000 | [diff] [blame] | 31 | from designate_tempest_plugin.services.dns.query.query_client import \ |
| 32 | QueryClient |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 33 | |
| 34 | CONF = config.CONF |
| 35 | |
| 36 | |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame^] | 37 | # 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 Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 40 | class ManagerV2(clients.Manager): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 41 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 42 | def __init__(self, credentials=None): |
| 43 | super(ManagerV2, self).__init__(credentials) |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 44 | self._init_clients(self._get_params()) |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 45 | |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 46 | def _init_clients(self, params): |
| 47 | self.zones_client = ZonesClient(**params) |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 48 | |
Paul Glass | cf98c26 | 2016-05-13 19:34:37 +0000 | [diff] [blame] | 49 | 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 Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 55 | |
| 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 Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame^] | 69 | class ManagerV2Unauthed(clients.Manager): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 70 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 71 | def __init__(self, credentials=None): |
| 72 | super(ManagerV2Unauthed, self).__init__(credentials) |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 73 | self.auth_provider = self._auth_provider_class()( |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 74 | 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 Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame^] | 82 | 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 Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 89 | def _auth_provider_class(self): |
| 90 | if CONF.identity.auth_version == 'v3': |
| 91 | return KeystoneV3UnauthedProvider |
| 92 | else: |
| 93 | return KeystoneV2UnauthedProvider |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 94 | |
Michael Johnson | df9fda1 | 2021-07-09 16:39:08 +0000 | [diff] [blame^] | 95 | 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 Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 107 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 108 | class BaseUnauthedProvider(auth.KeystoneAuthProvider): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 109 | |
| 110 | def _decorate_request(self, filters, method, url, headers=None, body=None, |
| 111 | auth_data=None): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 112 | result = super(BaseUnauthedProvider, self)._decorate_request( |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 113 | 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 Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 121 | |
| 122 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 123 | class KeystoneV2UnauthedProvider(auth.KeystoneV2AuthProvider, |
| 124 | BaseUnauthedProvider): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 125 | |
| 126 | def _decorate_request(self, *args, **kwargs): |
| 127 | return BaseUnauthedProvider._decorate_request(self, *args, **kwargs) |
| 128 | |
| 129 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 130 | class KeystoneV3UnauthedProvider(auth.KeystoneV3AuthProvider, |
| 131 | BaseUnauthedProvider): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 132 | |
| 133 | def _decorate_request(self, *args, **kwargs): |
| 134 | return BaseUnauthedProvider._decorate_request(self, *args, **kwargs) |