blob: 6e54a3195c68e9ccae32dd5b1900197f8e7a3e27 [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 Shalamov09b515e2018-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
Kiall Mac Innes4a376792016-05-19 18:05:54 +010025class AssertRaisesDns(object):
26 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
Ritesh Anand6e03c582017-05-11 14:34:56 -070079 @classmethod
80 def setup_credentials(cls):
81 # Do not create network resources for these test.
82 cls.set_network_resources()
83 super(BaseDnsTest, cls).setup_credentials()
84
sonu.kumard8471de2016-04-14 19:20:17 +090085 def assertExpected(self, expected, actual, excluded_keys):
86 for key, value in six.iteritems(expected):
87 if key not in excluded_keys:
88 self.assertIn(key, actual)
89 self.assertEqual(value, actual[key], key)
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +010090
Kiall Mac Innes4a376792016-05-19 18:05:54 +010091 def assertRaisesDns(self, exc, type_, code, callable_=None, *args,
92 **kwargs):
93 """
94 Checks the response that a api call with a exception contains the
95 expected data
96
97 Usable as both a ordinary function, and a context manager
98 """
99 context = AssertRaisesDns(self, exc, type_, code)
100
101 if callable_ is None:
102 return context
103
104 with context:
105 callable_(*args, **kwargs)
106
Maksym Shalamov09b515e2018-12-05 17:17:58 +0200107 def wait_zone_delete(self, zone_client, zone_id, **kwargs):
108 zone_client.delete_zone(zone_id, **kwargs)
109 utils.call_until_true(self._check_zone_deleted,
110 CONF.dns.build_timeout,
111 CONF.dns.build_interval,
112 zone_client,
113 zone_id)
114
115 def _check_zone_deleted(self, zone_client, zone_id):
116 return utils.call_and_ignore_notfound_exc(zone_client.show_zone,
117 zone_id) is None
118
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100119
120class BaseDnsV1Test(BaseDnsTest):
121 """Base class for DNS V1 API tests."""
122
123 # Use the Designate V1 Client Manager
124 client_manager = clients.ManagerV1
125
126 @classmethod
127 def skip_checks(cls):
128 super(BaseDnsV1Test, cls).skip_checks()
129
130 if not CONF.dns_feature_enabled.api_v1:
131 skip_msg = ("%s skipped as designate v1 API is not available"
132 % cls.__name__)
133 raise cls.skipException(skip_msg)
134
135
136class BaseDnsV2Test(BaseDnsTest):
137 """Base class for DNS V2 API tests."""
138
139 # Use the Designate V2 Client Manager
140 client_manager = clients.ManagerV2
141
142 @classmethod
143 def skip_checks(cls):
144 super(BaseDnsV2Test, cls).skip_checks()
145
146 if not CONF.dns_feature_enabled.api_v2:
147 skip_msg = ("%s skipped as designate v2 API is not available"
148 % cls.__name__)
149 raise cls.skipException(skip_msg)
150
151
152class BaseDnsAdminTest(BaseDnsTest):
153 """Base class for DNS Admin API tests."""
154
Graham Hayesc8114982016-07-04 17:46:08 +0100155 # Use the Designate Admin Client Manager
156 client_manager = clients.ManagerAdmin
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100157
158 @classmethod
159 def skip_checks(cls):
160 super(BaseDnsAdminTest, cls).skip_checks()
161 if not CONF.dns_feature_enabled.api_admin:
162 skip_msg = ("%s skipped as designate admin API is not available"
163 % cls.__name__)
164 raise cls.skipException(skip_msg)