blob: 6d33d81d85dd19a7beb22fd00b4b74ae7f3b4957 [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):
102 zone_client.delete_zone(zone_id, **kwargs)
103 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
109 def _check_zone_deleted(self, zone_client, zone_id):
110 return utils.call_and_ignore_notfound_exc(zone_client.show_zone,
111 zone_id) is None
112
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100113
114class BaseDnsV1Test(BaseDnsTest):
115 """Base class for DNS V1 API tests."""
116
117 # Use the Designate V1 Client Manager
118 client_manager = clients.ManagerV1
119
120 @classmethod
121 def skip_checks(cls):
122 super(BaseDnsV1Test, cls).skip_checks()
123
124 if not CONF.dns_feature_enabled.api_v1:
125 skip_msg = ("%s skipped as designate v1 API is not available"
126 % cls.__name__)
127 raise cls.skipException(skip_msg)
128
129
130class BaseDnsV2Test(BaseDnsTest):
131 """Base class for DNS V2 API tests."""
132
133 # Use the Designate V2 Client Manager
134 client_manager = clients.ManagerV2
135
136 @classmethod
137 def skip_checks(cls):
138 super(BaseDnsV2Test, cls).skip_checks()
139
140 if not CONF.dns_feature_enabled.api_v2:
141 skip_msg = ("%s skipped as designate v2 API is not available"
142 % cls.__name__)
143 raise cls.skipException(skip_msg)
144
145
146class BaseDnsAdminTest(BaseDnsTest):
147 """Base class for DNS Admin API tests."""
148
Graham Hayesc8114982016-07-04 17:46:08 +0100149 # Use the Designate Admin Client Manager
150 client_manager = clients.ManagerAdmin
Kiall Mac Innes8ae796c2016-04-21 13:47:25 +0100151
152 @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)