blob: a44db45dabda8bf95e7df47cc8f0227bced0dade [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
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200101 def wait_zone_delete(self, zone_client, zone_id, **kwargs):
Erik Olof Gunnar Anderssone8ba5cc2021-06-14 23:02:17 -0700102 self._delete_zone(zone_client, zone_id, **kwargs)
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200103 utils.call_until_true(self._check_zone_deleted,
104 CONF.dns.build_timeout,
105 CONF.dns.build_interval,
106 zone_client,
107 zone_id)
108
Erik Olof Gunnar Anderssone8ba5cc2021-06-14 23:02:17 -0700109 def _delete_zone(self, zone_client, zone_id, **kwargs):
110 return utils.call_and_ignore_notfound_exc(zone_client.delete_zone,
111 zone_id, **kwargs)
112
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200113 def _check_zone_deleted(self, zone_client, zone_id):
114 return utils.call_and_ignore_notfound_exc(zone_client.show_zone,
115 zone_id) is None
116
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100117
118class BaseDnsV1Test(BaseDnsTest):
119 """Base class for DNS V1 API tests."""
120
121 # Use the Designate V1 Client Manager
122 client_manager = clients.ManagerV1
123
124 @classmethod
125 def skip_checks(cls):
126 super(BaseDnsV1Test, cls).skip_checks()
127
128 if not CONF.dns_feature_enabled.api_v1:
129 skip_msg = ("%s skipped as designate v1 API is not available"
130 % cls.__name__)
131 raise cls.skipException(skip_msg)
132
133
134class BaseDnsV2Test(BaseDnsTest):
135 """Base class for DNS V2 API tests."""
136
137 # Use the Designate V2 Client Manager
138 client_manager = clients.ManagerV2
139
140 @classmethod
141 def skip_checks(cls):
142 super(BaseDnsV2Test, cls).skip_checks()
143
144 if not CONF.dns_feature_enabled.api_v2:
145 skip_msg = ("%s skipped as designate v2 API is not available"
146 % cls.__name__)
147 raise cls.skipException(skip_msg)
148
149
150class BaseDnsAdminTest(BaseDnsTest):
151 """Base class for DNS Admin API tests."""
152
Graham Hayesc8114982016-07-04 17:46:08 +0100153 # Use the Designate Admin Client Manager
154 client_manager = clients.ManagerAdmin
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100155
156 @classmethod
157 def skip_checks(cls):
158 super(BaseDnsAdminTest, cls).skip_checks()
159 if not CONF.dns_feature_enabled.api_admin:
160 skip_msg = ("%s skipped as designate admin API is not available"
161 % cls.__name__)
162 raise cls.skipException(skip_msg)