blob: a9a5e034e0400400f332793dacc02c564c8210d8 [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.
sonu.kumard8471de2016-04-14 19:20:17 +090014import six
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010015from tempest import test
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010016from tempest import config
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +020017from tempest.lib.common.utils import test_utils as utils
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010018
19from designate_tempest_plugin import clients
20
21
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010022CONF = config.CONF
23
24
Dmitry Galkin9a0a3602018-11-13 19:42:29 +000025class AssertRaisesDns(test.BaseTestCase):
Kiall Mac Innes4a376792016-05-19 18:05:54 +010026 def __init__(self, test_class, exc, type_, code):
27 self.test_class = test_class
28 self.exc = exc
29 self.type_ = type_
30 self.code = code
31
32 def __enter__(self):
33 pass
34
35 def __exit__(self, exc_type, exc_value, traceback):
36 if exc_type is None:
37 try:
38 exc_name = self.exc.__name__
39 except AttributeError:
40 exc_name = str(self.exc)
41 raise self.failureException(
42 "{0} not raised".format(exc_name))
43
44 if issubclass(exc_type, self.exc):
45 self.test_class.assertEqual(
46 self.code, exc_value.resp_body['code'])
47
48 self.test_class.assertEqual(
49 self.type_, exc_value.resp_body['type'])
50
51 return True
52
53 # Unexpected exceptions will be reraised
54 return False
55
56
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010057class BaseDnsTest(test.BaseTestCase):
Kiall Mac Innes560c89b2016-04-13 11:21:56 +010058 """Base class for DNS tests."""
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010059
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010060 # NOTE(andreaf) credentials holds a list of the credentials to be allocated
61 # at class setup time. Credential types can be 'primary', 'alt', 'admin' or
62 # a list of roles - the first element of the list being a label, and the
63 # rest the actual roles.
Graham Hayesbbc01e32018-02-15 14:40:54 +000064 # NOTE(kiall) primary will result in a manager @ cls.os_primary, alt will
65 # have cls.os_alt, and admin will have cls.os_admin.
Kiall Mac Innes560c89b2016-04-13 11:21:56 +010066 # NOTE(kiall) We should default to only primary, and request additional
67 # credentials in the tests that require them.
68 credentials = ['primary']
sonu.kumard8471de2016-04-14 19:20:17 +090069
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010070 @classmethod
71 def skip_checks(cls):
72 super(BaseDnsTest, cls).skip_checks()
73
74 if not CONF.service_available.designate:
75 skip_msg = ("%s skipped as designate is not available"
76 % cls.__name__)
77 raise cls.skipException(skip_msg)
78
sonu.kumard8471de2016-04-14 19:20:17 +090079 def assertExpected(self, expected, actual, excluded_keys):
80 for key, value in six.iteritems(expected):
81 if key not in excluded_keys:
82 self.assertIn(key, actual)
83 self.assertEqual(value, actual[key], key)
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010084
Kiall Mac Innes4a376792016-05-19 18:05:54 +010085 def assertRaisesDns(self, exc, type_, code, callable_=None, *args,
86 **kwargs):
87 """
88 Checks the response that a api call with a exception contains the
89 expected data
90
91 Usable as both a ordinary function, and a context manager
92 """
93 context = AssertRaisesDns(self, exc, type_, code)
94
95 if callable_ is None:
96 return context
97
98 with context:
99 callable_(*args, **kwargs)
100
Erik Olof Gunnar Anderssonfa6f78c2021-06-19 00:05:51 -0700101 def transfer_request_delete(self, transfer_client, transfer_request_id):
102 return utils.call_and_ignore_notfound_exc(
103 transfer_client.delete_transfer_request, transfer_request_id)
104
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200105 def wait_zone_delete(self, zone_client, zone_id, **kwargs):
Erik Olof Gunnar Anderssone8ba5cc2021-06-14 23:02:17 -0700106 self._delete_zone(zone_client, zone_id, **kwargs)
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200107 utils.call_until_true(self._check_zone_deleted,
108 CONF.dns.build_timeout,
109 CONF.dns.build_interval,
110 zone_client,
111 zone_id)
112
Erik Olof Gunnar Anderssone8ba5cc2021-06-14 23:02:17 -0700113 def _delete_zone(self, zone_client, zone_id, **kwargs):
114 return utils.call_and_ignore_notfound_exc(zone_client.delete_zone,
115 zone_id, **kwargs)
116
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200117 def _check_zone_deleted(self, zone_client, zone_id):
118 return utils.call_and_ignore_notfound_exc(zone_client.show_zone,
119 zone_id) is None
120
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100121
122class BaseDnsV1Test(BaseDnsTest):
123 """Base class for DNS V1 API tests."""
124
125 # Use the Designate V1 Client Manager
126 client_manager = clients.ManagerV1
127
128 @classmethod
129 def skip_checks(cls):
130 super(BaseDnsV1Test, cls).skip_checks()
131
132 if not CONF.dns_feature_enabled.api_v1:
133 skip_msg = ("%s skipped as designate v1 API is not available"
134 % cls.__name__)
135 raise cls.skipException(skip_msg)
136
137
138class BaseDnsV2Test(BaseDnsTest):
139 """Base class for DNS V2 API tests."""
140
141 # Use the Designate V2 Client Manager
142 client_manager = clients.ManagerV2
143
144 @classmethod
145 def skip_checks(cls):
146 super(BaseDnsV2Test, cls).skip_checks()
147
148 if not CONF.dns_feature_enabled.api_v2:
149 skip_msg = ("%s skipped as designate v2 API is not available"
150 % cls.__name__)
151 raise cls.skipException(skip_msg)
152
153
154class BaseDnsAdminTest(BaseDnsTest):
155 """Base class for DNS Admin API tests."""
156
Graham Hayesc8114982016-07-04 17:46:08 +0100157 # Use the Designate Admin Client Manager
158 client_manager = clients.ManagerAdmin
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100159
160 @classmethod
161 def skip_checks(cls):
162 super(BaseDnsAdminTest, cls).skip_checks()
163 if not CONF.dns_feature_enabled.api_admin:
164 skip_msg = ("%s skipped as designate admin API is not available"
165 % cls.__name__)
166 raise cls.skipException(skip_msg)