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 | |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 18 | from designate_tempest_plugin.services.dns.v1.json.domains_client import \ |
| 19 | DomainsClient |
| 20 | from designate_tempest_plugin.services.dns.v1.json.records_client import \ |
| 21 | RecordsClient |
| 22 | from designate_tempest_plugin.services.dns.v1.json.servers_client import \ |
| 23 | ServersClient |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 24 | from designate_tempest_plugin.services.dns.v2.json.zones_client import \ |
| 25 | ZonesClient |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 26 | from designate_tempest_plugin.services.dns.v2.json.zone_imports_client import \ |
| 27 | ZoneImportsClient |
Paul Glass | 8abae33 | 2016-04-21 15:34:09 +0000 | [diff] [blame] | 28 | from designate_tempest_plugin.services.dns.v2.json.blacklists_client import \ |
| 29 | BlacklistsClient |
Graham Hayes | c811498 | 2016-07-04 17:46:08 +0100 | [diff] [blame] | 30 | from designate_tempest_plugin.services.dns.v2.json.quotas_client import \ |
Paul Glass | 89edc11 | 2016-04-21 17:06:33 +0000 | [diff] [blame] | 31 | QuotasClient |
sonu.kumar | c8f7a70 | 2016-04-29 21:07:16 +0900 | [diff] [blame] | 32 | from designate_tempest_plugin.services.dns.v2.json.zone_exports_client import \ |
| 33 | ZoneExportsClient |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 34 | from designate_tempest_plugin.services.dns.v2.json.recordset_client import \ |
| 35 | RecordsetClient |
sonu.kumar | 4beb93c | 2016-05-05 01:12:43 +0900 | [diff] [blame] | 36 | from designate_tempest_plugin.services.dns.v2.json.pool_client import \ |
| 37 | PoolClient |
sonu.kumar | 2de01be | 2016-05-05 10:07:28 +0900 | [diff] [blame] | 38 | from designate_tempest_plugin.services.dns.v2.json.tld_client import \ |
| 39 | TldClient |
Graham Hayes | c811498 | 2016-07-04 17:46:08 +0100 | [diff] [blame] | 40 | from designate_tempest_plugin.services.dns.admin.json.quotas_client import \ |
| 41 | QuotasClient as AdminQuotaClient |
Paul Glass | cf98c26 | 2016-05-13 19:34:37 +0000 | [diff] [blame] | 42 | from designate_tempest_plugin.services.dns.query.query_client import \ |
| 43 | QueryClient |
sonu.kumar | e9785c9 | 2016-05-17 10:56:47 +0900 | [diff] [blame] | 44 | from designate_tempest_plugin.services.dns.v2.json.transfer_request_client \ |
| 45 | import TransferRequestClient |
sonu.kumar | ea0ba08 | 2016-05-16 14:13:47 +0900 | [diff] [blame] | 46 | from designate_tempest_plugin.services.dns.v2.json.transfer_accepts_client \ |
| 47 | import TransferAcceptClient |
sonu.kumar | c311086 | 2016-05-27 14:48:04 +0900 | [diff] [blame] | 48 | from designate_tempest_plugin.services.dns.v2.json.tsigkey_client \ |
| 49 | import TsigkeyClient |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 50 | |
| 51 | CONF = config.CONF |
| 52 | |
| 53 | |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 54 | class ManagerV1(clients.Manager): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 55 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 56 | def __init__(self, credentials=None): |
| 57 | super(ManagerV1, self).__init__(credentials) |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 58 | self._init_clients(self._get_params()) |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 59 | |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 60 | def _init_clients(self, params): |
| 61 | self.domains_client = DomainsClient(**params) |
| 62 | self.records_client = RecordsClient(**params) |
| 63 | self.servers_client = ServersClient(**params) |
| 64 | |
| 65 | def _get_params(self): |
| 66 | params = dict(self.default_params) |
| 67 | params.update({ |
| 68 | 'auth_provider': self.auth_provider, |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 69 | 'service': CONF.dns.catalog_type, |
| 70 | 'region': CONF.identity.region, |
| 71 | 'endpoint_type': CONF.dns.endpoint_type, |
| 72 | 'build_interval': CONF.dns.build_interval, |
| 73 | 'build_timeout': CONF.dns.build_timeout |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 74 | }) |
| 75 | return params |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 76 | |
| 77 | |
| 78 | class ManagerV2(clients.Manager): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 79 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 80 | def __init__(self, credentials=None): |
| 81 | super(ManagerV2, self).__init__(credentials) |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 82 | self._init_clients(self._get_params()) |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 83 | |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 84 | def _init_clients(self, params): |
| 85 | self.zones_client = ZonesClient(**params) |
| 86 | self.zone_imports_client = ZoneImportsClient(**params) |
| 87 | self.blacklists_client = BlacklistsClient(**params) |
| 88 | self.quotas_client = QuotasClient(**params) |
| 89 | self.zone_exports_client = ZoneExportsClient(**params) |
| 90 | self.recordset_client = RecordsetClient(**params) |
| 91 | self.pool_client = PoolClient(**params) |
| 92 | self.tld_client = TldClient(**params) |
| 93 | self.transfer_request_client = TransferRequestClient(**params) |
| 94 | self.transfer_accept_client = TransferAcceptClient(**params) |
| 95 | self.tsigkey_client = TsigkeyClient(**params) |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 96 | |
Paul Glass | cf98c26 | 2016-05-13 19:34:37 +0000 | [diff] [blame] | 97 | self.query_client = QueryClient( |
| 98 | nameservers=CONF.dns.nameservers, |
| 99 | query_timeout=CONF.dns.query_timeout, |
| 100 | build_interval=CONF.dns.build_interval, |
| 101 | build_timeout=CONF.dns.build_timeout, |
| 102 | ) |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 103 | |
| 104 | def _get_params(self): |
| 105 | params = dict(self.default_params) |
| 106 | params.update({ |
| 107 | 'auth_provider': self.auth_provider, |
| 108 | 'service': CONF.dns.catalog_type, |
| 109 | 'region': CONF.identity.region, |
| 110 | 'endpoint_type': CONF.dns.endpoint_type, |
| 111 | 'build_interval': CONF.dns.build_interval, |
| 112 | 'build_timeout': CONF.dns.build_timeout |
| 113 | }) |
| 114 | return params |
| 115 | |
| 116 | |
Graham Hayes | c811498 | 2016-07-04 17:46:08 +0100 | [diff] [blame] | 117 | class ManagerAdmin(clients.Manager): |
| 118 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 119 | def __init__(self, credentials=None): |
| 120 | super(ManagerAdmin, self).__init__(credentials) |
Graham Hayes | c811498 | 2016-07-04 17:46:08 +0100 | [diff] [blame] | 121 | self._init_clients(self._get_params()) |
| 122 | |
| 123 | def _init_clients(self, params): |
| 124 | self.quotas_client = AdminQuotaClient(**params) |
| 125 | |
| 126 | def _get_params(self): |
| 127 | params = dict(self.default_params) |
| 128 | params.update({ |
| 129 | 'auth_provider': self.auth_provider, |
| 130 | 'service': CONF.dns.catalog_type, |
| 131 | 'region': CONF.identity.region, |
| 132 | 'endpoint_type': CONF.dns.endpoint_type, |
| 133 | 'build_interval': CONF.dns.build_interval, |
| 134 | 'build_timeout': CONF.dns.build_timeout |
| 135 | }) |
| 136 | return params |
| 137 | |
| 138 | |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 139 | class ManagerV2Unauthed(ManagerV2): |
| 140 | |
Graham Hayes | c197826 | 2017-01-11 17:17:32 +0000 | [diff] [blame] | 141 | def __init__(self, credentials=None): |
| 142 | super(ManagerV2Unauthed, self).__init__(credentials) |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 143 | self.auth_provider = self._auth_provider_class()( |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 144 | credentials=self.auth_provider.credentials, |
| 145 | auth_url=self.auth_provider.auth_client.auth_url, |
| 146 | disable_ssl_certificate_validation=self.auth_provider.dscv, |
| 147 | ca_certs=self.auth_provider.ca_certs, |
| 148 | trace_requests=self.auth_provider.trace_requests, |
| 149 | ) |
| 150 | self._init_clients(self._get_params()) |
| 151 | |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 152 | def _auth_provider_class(self): |
| 153 | if CONF.identity.auth_version == 'v3': |
| 154 | return KeystoneV3UnauthedProvider |
| 155 | else: |
| 156 | return KeystoneV2UnauthedProvider |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 157 | |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 158 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 159 | class BaseUnauthedProvider(auth.KeystoneAuthProvider): |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 160 | |
| 161 | def _decorate_request(self, filters, method, url, headers=None, body=None, |
| 162 | auth_data=None): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 163 | result = super(BaseUnauthedProvider, self)._decorate_request( |
Paul Glass | d56330a | 2016-06-13 21:03:33 +0000 | [diff] [blame] | 164 | filters, method, url, headers=headers, body=body, |
| 165 | auth_data=auth_data) |
| 166 | url, headers, body = result |
| 167 | try: |
| 168 | del headers['X-Auth-Token'] |
| 169 | except KeyError: |
| 170 | pass |
| 171 | return url, headers, body |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 172 | |
| 173 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 174 | class KeystoneV2UnauthedProvider(auth.KeystoneV2AuthProvider, |
| 175 | BaseUnauthedProvider): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 176 | |
| 177 | def _decorate_request(self, *args, **kwargs): |
| 178 | return BaseUnauthedProvider._decorate_request(self, *args, **kwargs) |
| 179 | |
| 180 | |
Cao Xuan Hoang | a585e94 | 2016-08-29 14:52:30 +0700 | [diff] [blame] | 181 | class KeystoneV3UnauthedProvider(auth.KeystoneV3AuthProvider, |
| 182 | BaseUnauthedProvider): |
Paul Glass | 4b07b38 | 2016-07-13 19:14:02 +0000 | [diff] [blame] | 183 | |
| 184 | def _decorate_request(self, *args, **kwargs): |
| 185 | return BaseUnauthedProvider._decorate_request(self, *args, **kwargs) |