blob: 72fe2a68c3c93fa1d27075835b55a8960e906fe8 [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.
14
15import time
16
17from oslo_log import log as logging
ZhaoBoade04922017-02-10 10:27:29 +080018from tempest.lib.common.utils import test_utils
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010019from tempest.lib import exceptions as lib_exc
20
Michael Johnson97cab832021-12-01 21:51:54 +000021from designate_tempest_plugin.common import constants as const
22from designate_tempest_plugin.common import exceptions
23
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010024LOG = logging.getLogger(__name__)
25
26
27def wait_for_zone_404(client, zone_id):
28 """Waits for a zone to 404."""
29 LOG.info('Waiting for zone %s to 404', zone_id)
30 start = int(time.time())
31
32 while True:
33 time.sleep(client.build_interval)
34
35 try:
Arkady Shtempler356c5ae2022-02-05 00:16:35 +020036 zone = client.show_zone(zone_id)[1]
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010037 except lib_exc.NotFound:
38 LOG.info('Zone %s is 404ing', zone_id)
39 return
40
Michael Johnson97cab832021-12-01 21:51:54 +000041 if zone['status'] == const.ERROR:
42 raise exceptions.InvalidStatusError('Zone', zone_id,
43 zone['status'])
44
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010045 if int(time.time()) - start >= client.build_timeout:
46 message = ('Zone %(zone_id)s failed to 404 within the required '
47 'time (%(timeout)s s). Current status: '
48 '%(status_curr)s' %
49 {'zone_id': zone_id,
50 'status_curr': zone['status'],
51 'timeout': client.build_timeout})
52
ZhaoBoade04922017-02-10 10:27:29 +080053 caller = test_utils.find_test_caller()
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010054
55 if caller:
56 message = '(%s) %s' % (caller, message)
57
58 raise lib_exc.TimeoutException(message)
59
60
Michael Johnsona3a23632021-07-21 21:55:32 +000061def wait_for_zone_status(client, zone_id, status, headers=None):
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010062 """Waits for a zone to reach given status."""
63 LOG.info('Waiting for zone %s to reach %s', zone_id, status)
64
Arkady Shtempler356c5ae2022-02-05 00:16:35 +020065 zone = client.show_zone(zone_id, headers=headers)[1]
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010066 start = int(time.time())
67
68 while zone['status'] != status:
69 time.sleep(client.build_interval)
Arkady Shtempler356c5ae2022-02-05 00:16:35 +020070 zone = client.show_zone(zone_id, headers=headers)[1]
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010071 status_curr = zone['status']
72 if status_curr == status:
73 LOG.info('Zone %s reached %s', zone_id, status)
74 return
75
Michael Johnson8e140492022-01-31 23:18:56 +000076 if zone['status'] == const.ERROR:
77 raise exceptions.InvalidStatusError('Zone', zone_id,
78 zone['status'])
79
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010080 if int(time.time()) - start >= client.build_timeout:
81 message = ('Zone %(zone_id)s failed to reach status=%(status)s '
82 'within the required time (%(timeout)s s). Current '
83 'status: %(status_curr)s' %
84 {'zone_id': zone_id,
85 'status': status,
86 'status_curr': status_curr,
87 'timeout': client.build_timeout})
88
ZhaoBoade04922017-02-10 10:27:29 +080089 caller = test_utils.find_test_caller()
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010090
91 if caller:
92 message = '(%s) %s' % (caller, message)
93
94 raise lib_exc.TimeoutException(message)
sonu.kumaraec952a2016-04-20 10:08:46 +090095
96
97def wait_for_zone_import_status(client, zone_import_id, status):
98 """Waits for an imported zone to reach the given status."""
99 LOG.info('Waiting for zone import %s to reach %s', zone_import_id, status)
100
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200101 zone_import = client.show_zone_import(zone_import_id)[1]
sonu.kumaraec952a2016-04-20 10:08:46 +0900102 start = int(time.time())
103
104 while zone_import['status'] != status:
105 time.sleep(client.build_interval)
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200106 zone_import = client.show_zone_import(zone_import_id)[1]
sonu.kumaraec952a2016-04-20 10:08:46 +0900107 status_curr = zone_import['status']
108 if status_curr == status:
109 LOG.info('Zone import %s reached %s', zone_import_id, status)
110 return
111
Michael Johnson8e140492022-01-31 23:18:56 +0000112 if zone_import['status'] == const.ERROR:
113 raise exceptions.InvalidStatusError('Zone Import', zone_import_id,
114 zone_import['status'])
115
sonu.kumaraec952a2016-04-20 10:08:46 +0900116 if int(time.time()) - start >= client.build_timeout:
117 message = ('Zone import %(zone_import_id)s failed to reach '
118 'status=%(status)s within the required time '
119 '(%(timeout)s s). Current '
120 'status: %(status_curr)s' %
121 {'zone_import_id': zone_import_id,
122 'status': status,
123 'status_curr': status_curr,
124 'timeout': client.build_timeout})
125
ZhaoBoade04922017-02-10 10:27:29 +0800126 caller = test_utils.find_test_caller()
sonu.kumaraec952a2016-04-20 10:08:46 +0900127
128 if caller:
129 message = '(%s) %s' % (caller, message)
130
131 raise lib_exc.TimeoutException(message)
sonu.kumarde24d962016-05-05 00:28:00 +0900132
133
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200134def wait_for_zone_export_status(client, zone_export_id, status, headers=None):
Paul Glass7e2a6402016-06-01 21:50:17 +0000135 """Waits for an exported zone to reach the given status."""
136 LOG.info('Waiting for zone export %s to reach %s', zone_export_id, status)
137
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200138 zone_export = client.show_zone_export(zone_export_id, headers=headers)[1]
Paul Glass7e2a6402016-06-01 21:50:17 +0000139 start = int(time.time())
140
141 while zone_export['status'] != status:
142 time.sleep(client.build_interval)
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200143 zone_export = client.show_zone_export(
144 zone_export_id, headers=headers)[1]
Paul Glass7e2a6402016-06-01 21:50:17 +0000145 status_curr = zone_export['status']
146 if status_curr == status:
147 LOG.info('Zone export %s reached %s', zone_export_id, status)
148 return
149
Michael Johnson8e140492022-01-31 23:18:56 +0000150 if zone_export['status'] == const.ERROR:
151 raise exceptions.InvalidStatusError('Zone Export', zone_export_id,
152 zone_export['status'])
153
Paul Glass7e2a6402016-06-01 21:50:17 +0000154 if int(time.time()) - start >= client.build_timeout:
155 message = ('Zone export %(zone_export_id)s failed to reach '
156 'status=%(status)s within the required time '
157 '(%(timeout)s s). Current '
158 'status: %(status_curr)s' %
159 {'zone_export_id': zone_export_id,
160 'status': status,
161 'status_curr': status_curr,
162 'timeout': client.build_timeout})
163
ZhaoBoade04922017-02-10 10:27:29 +0800164 caller = test_utils.find_test_caller()
Paul Glass7e2a6402016-06-01 21:50:17 +0000165
166 if caller:
167 message = '(%s) %s' % (caller, message)
168
169 raise lib_exc.TimeoutException(message)
170
171
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200172def wait_for_recordset_status(
173 client, zone_id, recordset_id, status, headers=None):
sonu.kumarde24d962016-05-05 00:28:00 +0900174 """Waits for a recordset to reach the given status."""
175 LOG.info('Waiting for recordset %s to reach %s',
176 recordset_id, status)
177
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200178 recordset = client.show_recordset(
179 zone_id, recordset_id, headers=headers)[1]
sonu.kumarde24d962016-05-05 00:28:00 +0900180 start = int(time.time())
181
182 while recordset['status'] != status:
183 time.sleep(client.build_interval)
Arkady Shtempler356c5ae2022-02-05 00:16:35 +0200184 recordset = client.show_recordset(
185 zone_id, recordset_id, headers=headers)[1]
sonu.kumarde24d962016-05-05 00:28:00 +0900186 status_curr = recordset['status']
187 if status_curr == status:
188 LOG.info('Recordset %s reached %s', recordset_id, status)
189 return
190
Michael Johnson8e140492022-01-31 23:18:56 +0000191 if recordset['status'] == const.ERROR:
192 raise exceptions.InvalidStatusError('Recordset', recordset_id,
193 recordset['status'])
194
sonu.kumarde24d962016-05-05 00:28:00 +0900195 if int(time.time()) - start >= client.build_timeout:
196 message = ('Recordset %(recordset_id)s failed to reach '
Jens Harbottd8728b42018-04-16 09:36:00 +0000197 'status=%(status)s within the required time '
sonu.kumarde24d962016-05-05 00:28:00 +0900198 '(%(timeout)s s). Current '
199 'status: %(status_curr)s' %
200 {'recordset_id': recordset_id,
201 'status': status,
202 'status_curr': status_curr,
203 'timeout': client.build_timeout})
204
ZhaoBoade04922017-02-10 10:27:29 +0800205 caller = test_utils.find_test_caller()
sonu.kumarde24d962016-05-05 00:28:00 +0900206
207 if caller:
208 message = '(%s) %s' % (caller, message)
209
Mykyta Karpin1c609392025-09-10 15:30:39 +0200210 LOG.debug("Checking recordset %s propagation", recordset_id)
211 try:
212 wait_for_query(client.query_client, recordset['name'],
213 recordset['type'], timeout=30)
214 LOG.debug("Recordset %s was propagated to backend",
215 recordset_id)
216 except Exception:
217 LOG.exception(
218 "Failed to wait for recordset %s propagation.",
219 recordset_id)
220 # Get latest recordset status, to check if status is recovered
221 rset = client.show_recordset(
222 zone_id, recordset_id, headers=headers)[1]
223 LOG.debug("Recordset %s details: %s", recordset_id, rset)
Paul Glasscf98c262016-05-13 19:34:37 +0000224 raise lib_exc.TimeoutException(message)
225
226
Mykyta Karpin1c609392025-09-10 15:30:39 +0200227def wait_for_query(client, name, rdatatype, found=True, timeout=None):
Paul Glasscf98c262016-05-13 19:34:37 +0000228 """Query nameservers until the record of the given name and type is found.
229
230 :param client: A QueryClient
231 :param name: The record name for which to query
232 :param rdatatype: The record type for which to query
233 :param found: If True, wait until the record is found. Else, wait until the
234 record disappears.
Mykyta Karpin1c609392025-09-10 15:30:39 +0200235 :param timeout: Number of seconds to wait for record.
Paul Glasscf98c262016-05-13 19:34:37 +0000236 """
237 state = "found" if found else "removed"
Mykyta Karpin1c609392025-09-10 15:30:39 +0200238 timeout = timeout or client.build_timeout
Paul Glasscf98c262016-05-13 19:34:37 +0000239 LOG.info("Waiting for record %s of type %s to be %s on nameservers %s",
240 name, rdatatype, state, client.nameservers)
241 start = int(time.time())
242
243 while True:
244 time.sleep(client.build_interval)
245
246 responses = client.query(name, rdatatype)
247 if found:
248 all_answers_good = all(r.answer for r in responses)
249 else:
250 all_answers_good = all(not r.answer for r in responses)
251
Lukáš Piwowarski4f2367f2022-10-27 11:11:31 +0200252 if all_answers_good:
Paul Glasscf98c262016-05-13 19:34:37 +0000253 LOG.info("Record %s of type %s was successfully %s on nameservers "
254 "%s", name, rdatatype, state, client.nameservers)
255 return
256
Mykyta Karpin1c609392025-09-10 15:30:39 +0200257 if int(time.time()) - start >= timeout:
Paul Glasscf98c262016-05-13 19:34:37 +0000258 message = ('Record %(name)s of type %(rdatatype)s not %(state)s '
259 'on nameservers %(nameservers)s within the required '
260 'time (%(timeout)s s)' %
261 {'name': name,
262 'rdatatype': rdatatype,
263 'state': state,
264 'nameservers': client.nameservers,
Mykyta Karpin1c609392025-09-10 15:30:39 +0200265 'timeout': timeout})
Paul Glasscf98c262016-05-13 19:34:37 +0000266
ZhaoBoade04922017-02-10 10:27:29 +0800267 caller = test_utils.find_test_caller()
Paul Glasscf98c262016-05-13 19:34:37 +0000268 if caller:
269 message = "(%s) %s" % (caller, message)
270
271 raise lib_exc.TimeoutException(message)
Arkady Shtemplerb8ea4ca2021-06-04 08:55:28 +0300272
273
274def wait_for_ptr_status(client, fip_id, status):
275 """Waits for a PTR associated with FIP to reach given status."""
276 LOG.info('Waiting for PTR %s to reach %s', fip_id, status)
277
278 ptr = client.show_ptr_record(fip_id)
279 start = int(time.time())
280
281 while ptr['status'] != status:
282 time.sleep(client.build_interval)
283 ptr = client.show_ptr_record(fip_id)
284 status_curr = ptr['status']
285 if status_curr == status:
286 LOG.info('PTR %s reached %s', fip_id, status)
287 return
288
Michael Johnson8e140492022-01-31 23:18:56 +0000289 if ptr['status'] == const.ERROR:
290 raise exceptions.InvalidStatusError('PTR', fip_id,
291 ptr['status'])
292
Arkady Shtemplerb8ea4ca2021-06-04 08:55:28 +0300293 if int(time.time()) - start >= client.build_timeout:
294 message = ('PTR for FIP: %(fip_id)s failed to reach '
295 'status=%(status)s within the required time '
296 '(%(timeout)s s). Current status: %(status_curr)s' %
297 {'fip_id': fip_id,
298 'status': status,
299 'status_curr': status_curr,
300 'timeout': client.build_timeout})
301
302 caller = test_utils.find_test_caller()
303
304 if caller:
305 message = '(%s) %s' % (caller, message)
306
307 raise lib_exc.TimeoutException(message)