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. |
sonu.kumar | d8471de | 2016-04-14 19:20:17 +0900 | [diff] [blame] | 14 | import six |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 15 | from tempest import test |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 16 | from tempest import config |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 17 | |
| 18 | from designate_tempest_plugin import clients |
| 19 | |
| 20 | |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
| 23 | |
Kiall Mac Innes | 4a37679 | 2016-05-19 18:05:54 +0100 | [diff] [blame] | 24 | class AssertRaisesDns(object): |
| 25 | def __init__(self, test_class, exc, type_, code): |
| 26 | self.test_class = test_class |
| 27 | self.exc = exc |
| 28 | self.type_ = type_ |
| 29 | self.code = code |
| 30 | |
| 31 | def __enter__(self): |
| 32 | pass |
| 33 | |
| 34 | def __exit__(self, exc_type, exc_value, traceback): |
| 35 | if exc_type is None: |
| 36 | try: |
| 37 | exc_name = self.exc.__name__ |
| 38 | except AttributeError: |
| 39 | exc_name = str(self.exc) |
| 40 | raise self.failureException( |
| 41 | "{0} not raised".format(exc_name)) |
| 42 | |
| 43 | if issubclass(exc_type, self.exc): |
| 44 | self.test_class.assertEqual( |
| 45 | self.code, exc_value.resp_body['code']) |
| 46 | |
| 47 | self.test_class.assertEqual( |
| 48 | self.type_, exc_value.resp_body['type']) |
| 49 | |
| 50 | return True |
| 51 | |
| 52 | # Unexpected exceptions will be reraised |
| 53 | return False |
| 54 | |
| 55 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 56 | class BaseDnsTest(test.BaseTestCase): |
Kiall Mac Innes | 560c89b | 2016-04-13 11:21:56 +0100 | [diff] [blame] | 57 | """Base class for DNS tests.""" |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 58 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 59 | # NOTE(andreaf) credentials holds a list of the credentials to be allocated |
| 60 | # at class setup time. Credential types can be 'primary', 'alt', 'admin' or |
| 61 | # a list of roles - the first element of the list being a label, and the |
| 62 | # rest the actual roles. |
| 63 | # NOTE(kiall) primary will result in a manager @ cls.os, alt will have |
| 64 | # cls.os_alt, and admin will have cls.os_adm. |
Kiall Mac Innes | 560c89b | 2016-04-13 11:21:56 +0100 | [diff] [blame] | 65 | # NOTE(kiall) We should default to only primary, and request additional |
| 66 | # credentials in the tests that require them. |
| 67 | credentials = ['primary'] |
sonu.kumar | d8471de | 2016-04-14 19:20:17 +0900 | [diff] [blame] | 68 | |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 69 | @classmethod |
| 70 | def skip_checks(cls): |
| 71 | super(BaseDnsTest, cls).skip_checks() |
| 72 | |
| 73 | if not CONF.service_available.designate: |
| 74 | skip_msg = ("%s skipped as designate is not available" |
| 75 | % cls.__name__) |
| 76 | raise cls.skipException(skip_msg) |
| 77 | |
Ritesh Anand | 6e03c58 | 2017-05-11 14:34:56 -0700 | [diff] [blame^] | 78 | @classmethod |
| 79 | def setup_credentials(cls): |
| 80 | # Do not create network resources for these test. |
| 81 | cls.set_network_resources() |
| 82 | super(BaseDnsTest, cls).setup_credentials() |
| 83 | |
sonu.kumar | d8471de | 2016-04-14 19:20:17 +0900 | [diff] [blame] | 84 | def assertExpected(self, expected, actual, excluded_keys): |
| 85 | for key, value in six.iteritems(expected): |
| 86 | if key not in excluded_keys: |
| 87 | self.assertIn(key, actual) |
| 88 | self.assertEqual(value, actual[key], key) |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 89 | |
Kiall Mac Innes | 4a37679 | 2016-05-19 18:05:54 +0100 | [diff] [blame] | 90 | def assertRaisesDns(self, exc, type_, code, callable_=None, *args, |
| 91 | **kwargs): |
| 92 | """ |
| 93 | Checks the response that a api call with a exception contains the |
| 94 | expected data |
| 95 | |
| 96 | Usable as both a ordinary function, and a context manager |
| 97 | """ |
| 98 | context = AssertRaisesDns(self, exc, type_, code) |
| 99 | |
| 100 | if callable_ is None: |
| 101 | return context |
| 102 | |
| 103 | with context: |
| 104 | callable_(*args, **kwargs) |
| 105 | |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 106 | |
| 107 | class BaseDnsV1Test(BaseDnsTest): |
| 108 | """Base class for DNS V1 API tests.""" |
| 109 | |
| 110 | # Use the Designate V1 Client Manager |
| 111 | client_manager = clients.ManagerV1 |
| 112 | |
| 113 | @classmethod |
| 114 | def skip_checks(cls): |
| 115 | super(BaseDnsV1Test, cls).skip_checks() |
| 116 | |
| 117 | if not CONF.dns_feature_enabled.api_v1: |
| 118 | skip_msg = ("%s skipped as designate v1 API is not available" |
| 119 | % cls.__name__) |
| 120 | raise cls.skipException(skip_msg) |
| 121 | |
| 122 | |
| 123 | class BaseDnsV2Test(BaseDnsTest): |
| 124 | """Base class for DNS V2 API tests.""" |
| 125 | |
| 126 | # Use the Designate V2 Client Manager |
| 127 | client_manager = clients.ManagerV2 |
| 128 | |
| 129 | @classmethod |
| 130 | def skip_checks(cls): |
| 131 | super(BaseDnsV2Test, cls).skip_checks() |
| 132 | |
| 133 | if not CONF.dns_feature_enabled.api_v2: |
| 134 | skip_msg = ("%s skipped as designate v2 API is not available" |
| 135 | % cls.__name__) |
| 136 | raise cls.skipException(skip_msg) |
| 137 | |
| 138 | |
| 139 | class BaseDnsAdminTest(BaseDnsTest): |
| 140 | """Base class for DNS Admin API tests.""" |
| 141 | |
Graham Hayes | c811498 | 2016-07-04 17:46:08 +0100 | [diff] [blame] | 142 | # Use the Designate Admin Client Manager |
| 143 | client_manager = clients.ManagerAdmin |
Kiall Mac Innes | 8ae796c | 2016-04-21 13:47:25 +0100 | [diff] [blame] | 144 | |
| 145 | @classmethod |
| 146 | def skip_checks(cls): |
| 147 | super(BaseDnsAdminTest, cls).skip_checks() |
| 148 | if not CONF.dns_feature_enabled.api_admin: |
| 149 | skip_msg = ("%s skipped as designate admin API is not available" |
| 150 | % cls.__name__) |
| 151 | raise cls.skipException(skip_msg) |