blob: 6f2845e47d0b073e32b891ca4c3265eb1d58112f [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
Michael Johnsondf9fda12021-07-09 16:39:08 +000019from designate_tempest_plugin.services.dns.query.query_client import \
20 QueryClient
21
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010022
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010023CONF = config.CONF
24
25
Dmitry Galkin9a0a3602018-11-13 19:42:29 +000026class AssertRaisesDns(test.BaseTestCase):
Kiall Mac Innes4a376792016-05-19 18:05:54 +010027 def __init__(self, test_class, exc, type_, code):
28 self.test_class = test_class
29 self.exc = exc
30 self.type_ = type_
31 self.code = code
32
33 def __enter__(self):
34 pass
35
36 def __exit__(self, exc_type, exc_value, traceback):
37 if exc_type is None:
38 try:
39 exc_name = self.exc.__name__
40 except AttributeError:
41 exc_name = str(self.exc)
42 raise self.failureException(
43 "{0} not raised".format(exc_name))
44
45 if issubclass(exc_type, self.exc):
46 self.test_class.assertEqual(
47 self.code, exc_value.resp_body['code'])
48
49 self.test_class.assertEqual(
50 self.type_, exc_value.resp_body['type'])
51
52 return True
53
54 # Unexpected exceptions will be reraised
55 return False
56
57
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010058class BaseDnsTest(test.BaseTestCase):
Kiall Mac Innes560c89b2016-04-13 11:21:56 +010059 """Base class for DNS tests."""
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010060
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010061 # NOTE(andreaf) credentials holds a list of the credentials to be allocated
62 # at class setup time. Credential types can be 'primary', 'alt', 'admin' or
63 # a list of roles - the first element of the list being a label, and the
64 # rest the actual roles.
Graham Hayesbbc01e32018-02-15 14:40:54 +000065 # NOTE(kiall) primary will result in a manager @ cls.os_primary, alt will
66 # have cls.os_alt, and admin will have cls.os_admin.
Kiall Mac Innes560c89b2016-04-13 11:21:56 +010067 # NOTE(kiall) We should default to only primary, and request additional
68 # credentials in the tests that require them.
69 credentials = ['primary']
sonu.kumard8471de2016-04-14 19:20:17 +090070
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010071 @classmethod
72 def skip_checks(cls):
73 super(BaseDnsTest, cls).skip_checks()
74
75 if not CONF.service_available.designate:
76 skip_msg = ("%s skipped as designate is not available"
77 % cls.__name__)
78 raise cls.skipException(skip_msg)
79
Michael Johnsondf9fda12021-07-09 16:39:08 +000080 @classmethod
81 def setup_clients(cls):
82 super(BaseDnsTest, cls).setup_clients()
83 # The Query Client is not an OpenStack client which means
84 # we should not set it up through the tempest client manager.
85 # Set it up here so all tests have access to it.
86 cls.query_client = QueryClient(
87 nameservers=CONF.dns.nameservers,
88 query_timeout=CONF.dns.query_timeout,
89 build_interval=CONF.dns.build_interval,
90 build_timeout=CONF.dns.build_timeout,
91 )
92
sonu.kumard8471de2016-04-14 19:20:17 +090093 def assertExpected(self, expected, actual, excluded_keys):
94 for key, value in six.iteritems(expected):
95 if key not in excluded_keys:
96 self.assertIn(key, actual)
97 self.assertEqual(value, actual[key], key)
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010098
Kiall Mac Innes4a376792016-05-19 18:05:54 +010099 def assertRaisesDns(self, exc, type_, code, callable_=None, *args,
100 **kwargs):
101 """
102 Checks the response that a api call with a exception contains the
103 expected data
104
105 Usable as both a ordinary function, and a context manager
106 """
107 context = AssertRaisesDns(self, exc, type_, code)
108
109 if callable_ is None:
110 return context
111
112 with context:
113 callable_(*args, **kwargs)
114
Erik Olof Gunnar Anderssonfa6f78c2021-06-19 00:05:51 -0700115 def transfer_request_delete(self, transfer_client, transfer_request_id):
116 return utils.call_and_ignore_notfound_exc(
117 transfer_client.delete_transfer_request, transfer_request_id)
118
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200119 def wait_zone_delete(self, zone_client, zone_id, **kwargs):
Erik Olof Gunnar Anderssone8ba5cc2021-06-14 23:02:17 -0700120 self._delete_zone(zone_client, zone_id, **kwargs)
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200121 utils.call_until_true(self._check_zone_deleted,
122 CONF.dns.build_timeout,
123 CONF.dns.build_interval,
124 zone_client,
125 zone_id)
126
Erik Olof Gunnar Anderssone8ba5cc2021-06-14 23:02:17 -0700127 def _delete_zone(self, zone_client, zone_id, **kwargs):
128 return utils.call_and_ignore_notfound_exc(zone_client.delete_zone,
129 zone_id, **kwargs)
130
Maksym Shalamov2da1d6e2018-12-05 17:17:58 +0200131 def _check_zone_deleted(self, zone_client, zone_id):
132 return utils.call_and_ignore_notfound_exc(zone_client.show_zone,
133 zone_id) is None
134
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100135
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100136class BaseDnsV2Test(BaseDnsTest):
137 """Base class for DNS V2 API tests."""
138
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100139 @classmethod
140 def skip_checks(cls):
141 super(BaseDnsV2Test, cls).skip_checks()
142
143 if not CONF.dns_feature_enabled.api_v2:
144 skip_msg = ("%s skipped as designate v2 API is not available"
145 % cls.__name__)
146 raise cls.skipException(skip_msg)
147
148
149class BaseDnsAdminTest(BaseDnsTest):
150 """Base class for DNS Admin API tests."""
151
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100152 @classmethod
153 def skip_checks(cls):
154 super(BaseDnsAdminTest, cls).skip_checks()
155 if not CONF.dns_feature_enabled.api_admin:
156 skip_msg = ("%s skipped as designate admin API is not available"
157 % cls.__name__)
158 raise cls.skipException(skip_msg)