blob: affe3326186c6a6451d9b028ad58ecb396b66519 [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
Paul Glasscf98c262016-05-13 19:34:37 +0000210 raise lib_exc.TimeoutException(message)
211
212
213def wait_for_query(client, name, rdatatype, found=True):
214 """Query nameservers until the record of the given name and type is found.
215
216 :param client: A QueryClient
217 :param name: The record name for which to query
218 :param rdatatype: The record type for which to query
219 :param found: If True, wait until the record is found. Else, wait until the
220 record disappears.
221 """
222 state = "found" if found else "removed"
223 LOG.info("Waiting for record %s of type %s to be %s on nameservers %s",
224 name, rdatatype, state, client.nameservers)
225 start = int(time.time())
226
227 while True:
228 time.sleep(client.build_interval)
229
230 responses = client.query(name, rdatatype)
231 if found:
232 all_answers_good = all(r.answer for r in responses)
233 else:
234 all_answers_good = all(not r.answer for r in responses)
235
236 if not client.nameservers or all_answers_good:
237 LOG.info("Record %s of type %s was successfully %s on nameservers "
238 "%s", name, rdatatype, state, client.nameservers)
239 return
240
241 if int(time.time()) - start >= client.build_timeout:
242 message = ('Record %(name)s of type %(rdatatype)s not %(state)s '
243 'on nameservers %(nameservers)s within the required '
244 'time (%(timeout)s s)' %
245 {'name': name,
246 'rdatatype': rdatatype,
247 'state': state,
248 'nameservers': client.nameservers,
249 'timeout': client.build_timeout})
250
ZhaoBoade04922017-02-10 10:27:29 +0800251 caller = test_utils.find_test_caller()
Paul Glasscf98c262016-05-13 19:34:37 +0000252 if caller:
253 message = "(%s) %s" % (caller, message)
254
255 raise lib_exc.TimeoutException(message)
Arkady Shtemplerb8ea4ca2021-06-04 08:55:28 +0300256
257
258def wait_for_ptr_status(client, fip_id, status):
259 """Waits for a PTR associated with FIP to reach given status."""
260 LOG.info('Waiting for PTR %s to reach %s', fip_id, status)
261
262 ptr = client.show_ptr_record(fip_id)
263 start = int(time.time())
264
265 while ptr['status'] != status:
266 time.sleep(client.build_interval)
267 ptr = client.show_ptr_record(fip_id)
268 status_curr = ptr['status']
269 if status_curr == status:
270 LOG.info('PTR %s reached %s', fip_id, status)
271 return
272
Michael Johnson8e140492022-01-31 23:18:56 +0000273 if ptr['status'] == const.ERROR:
274 raise exceptions.InvalidStatusError('PTR', fip_id,
275 ptr['status'])
276
Arkady Shtemplerb8ea4ca2021-06-04 08:55:28 +0300277 if int(time.time()) - start >= client.build_timeout:
278 message = ('PTR for FIP: %(fip_id)s failed to reach '
279 'status=%(status)s within the required time '
280 '(%(timeout)s s). Current status: %(status_curr)s' %
281 {'fip_id': fip_id,
282 'status': status,
283 'status_curr': status_curr,
284 'timeout': client.build_timeout})
285
286 caller = test_utils.find_test_caller()
287
288 if caller:
289 message = '(%s) %s' % (caller, message)
290
291 raise lib_exc.TimeoutException(message)