blob: a606fda5bc0b7f4bc3fc685f5c27d62a74c9d4cb [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:
36 _, zone = client.show_zone(zone_id)
37 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
Michael Johnsona3a23632021-07-21 21:55:32 +000065 _, zone = client.show_zone(zone_id, headers=headers)
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)
Michael Johnsona3a23632021-07-21 21:55:32 +000070 _, zone = client.show_zone(zone_id, headers=headers)
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
101 _, zone_import = client.show_zone_import(zone_import_id)
102 start = int(time.time())
103
104 while zone_import['status'] != status:
105 time.sleep(client.build_interval)
106 _, zone_import = client.show_zone_import(zone_import_id)
107 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
Paul Glass7e2a6402016-06-01 21:50:17 +0000134def wait_for_zone_export_status(client, zone_export_id, status):
135 """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
138 _, zone_export = client.show_zone_export(zone_export_id)
139 start = int(time.time())
140
141 while zone_export['status'] != status:
142 time.sleep(client.build_interval)
143 _, zone_export = client.show_zone_export(zone_export_id)
144 status_curr = zone_export['status']
145 if status_curr == status:
146 LOG.info('Zone export %s reached %s', zone_export_id, status)
147 return
148
Michael Johnson8e140492022-01-31 23:18:56 +0000149 if zone_export['status'] == const.ERROR:
150 raise exceptions.InvalidStatusError('Zone Export', zone_export_id,
151 zone_export['status'])
152
Paul Glass7e2a6402016-06-01 21:50:17 +0000153 if int(time.time()) - start >= client.build_timeout:
154 message = ('Zone export %(zone_export_id)s failed to reach '
155 'status=%(status)s within the required time '
156 '(%(timeout)s s). Current '
157 'status: %(status_curr)s' %
158 {'zone_export_id': zone_export_id,
159 'status': status,
160 'status_curr': status_curr,
161 'timeout': client.build_timeout})
162
ZhaoBoade04922017-02-10 10:27:29 +0800163 caller = test_utils.find_test_caller()
Paul Glass7e2a6402016-06-01 21:50:17 +0000164
165 if caller:
166 message = '(%s) %s' % (caller, message)
167
168 raise lib_exc.TimeoutException(message)
169
170
Eric Larsondc715e12016-08-25 13:21:35 +0100171def wait_for_recordset_status(client, zone_id, recordset_id, status):
sonu.kumarde24d962016-05-05 00:28:00 +0900172 """Waits for a recordset to reach the given status."""
173 LOG.info('Waiting for recordset %s to reach %s',
174 recordset_id, status)
175
Eric Larsondc715e12016-08-25 13:21:35 +0100176 _, recordset = client.show_recordset(zone_id, recordset_id)
sonu.kumarde24d962016-05-05 00:28:00 +0900177 start = int(time.time())
178
179 while recordset['status'] != status:
180 time.sleep(client.build_interval)
Eric Larsondc715e12016-08-25 13:21:35 +0100181 _, recordset = client.show_recordset(zone_id, recordset_id)
sonu.kumarde24d962016-05-05 00:28:00 +0900182 status_curr = recordset['status']
183 if status_curr == status:
184 LOG.info('Recordset %s reached %s', recordset_id, status)
185 return
186
Michael Johnson8e140492022-01-31 23:18:56 +0000187 if recordset['status'] == const.ERROR:
188 raise exceptions.InvalidStatusError('Recordset', recordset_id,
189 recordset['status'])
190
sonu.kumarde24d962016-05-05 00:28:00 +0900191 if int(time.time()) - start >= client.build_timeout:
192 message = ('Recordset %(recordset_id)s failed to reach '
Jens Harbottd8728b42018-04-16 09:36:00 +0000193 'status=%(status)s within the required time '
sonu.kumarde24d962016-05-05 00:28:00 +0900194 '(%(timeout)s s). Current '
195 'status: %(status_curr)s' %
196 {'recordset_id': recordset_id,
197 'status': status,
198 'status_curr': status_curr,
199 'timeout': client.build_timeout})
200
ZhaoBoade04922017-02-10 10:27:29 +0800201 caller = test_utils.find_test_caller()
sonu.kumarde24d962016-05-05 00:28:00 +0900202
203 if caller:
204 message = '(%s) %s' % (caller, message)
205
Paul Glasscf98c262016-05-13 19:34:37 +0000206 raise lib_exc.TimeoutException(message)
207
208
209def wait_for_query(client, name, rdatatype, found=True):
210 """Query nameservers until the record of the given name and type is found.
211
212 :param client: A QueryClient
213 :param name: The record name for which to query
214 :param rdatatype: The record type for which to query
215 :param found: If True, wait until the record is found. Else, wait until the
216 record disappears.
217 """
218 state = "found" if found else "removed"
219 LOG.info("Waiting for record %s of type %s to be %s on nameservers %s",
220 name, rdatatype, state, client.nameservers)
221 start = int(time.time())
222
223 while True:
224 time.sleep(client.build_interval)
225
226 responses = client.query(name, rdatatype)
227 if found:
228 all_answers_good = all(r.answer for r in responses)
229 else:
230 all_answers_good = all(not r.answer for r in responses)
231
232 if not client.nameservers or all_answers_good:
233 LOG.info("Record %s of type %s was successfully %s on nameservers "
234 "%s", name, rdatatype, state, client.nameservers)
235 return
236
237 if int(time.time()) - start >= client.build_timeout:
238 message = ('Record %(name)s of type %(rdatatype)s not %(state)s '
239 'on nameservers %(nameservers)s within the required '
240 'time (%(timeout)s s)' %
241 {'name': name,
242 'rdatatype': rdatatype,
243 'state': state,
244 'nameservers': client.nameservers,
245 'timeout': client.build_timeout})
246
ZhaoBoade04922017-02-10 10:27:29 +0800247 caller = test_utils.find_test_caller()
Paul Glasscf98c262016-05-13 19:34:37 +0000248 if caller:
249 message = "(%s) %s" % (caller, message)
250
251 raise lib_exc.TimeoutException(message)
Arkady Shtemplerb8ea4ca2021-06-04 08:55:28 +0300252
253
254def wait_for_ptr_status(client, fip_id, status):
255 """Waits for a PTR associated with FIP to reach given status."""
256 LOG.info('Waiting for PTR %s to reach %s', fip_id, status)
257
258 ptr = client.show_ptr_record(fip_id)
259 start = int(time.time())
260
261 while ptr['status'] != status:
262 time.sleep(client.build_interval)
263 ptr = client.show_ptr_record(fip_id)
264 status_curr = ptr['status']
265 if status_curr == status:
266 LOG.info('PTR %s reached %s', fip_id, status)
267 return
268
Michael Johnson8e140492022-01-31 23:18:56 +0000269 if ptr['status'] == const.ERROR:
270 raise exceptions.InvalidStatusError('PTR', fip_id,
271 ptr['status'])
272
Arkady Shtemplerb8ea4ca2021-06-04 08:55:28 +0300273 if int(time.time()) - start >= client.build_timeout:
274 message = ('PTR for FIP: %(fip_id)s failed to reach '
275 'status=%(status)s within the required time '
276 '(%(timeout)s s). Current status: %(status_curr)s' %
277 {'fip_id': fip_id,
278 'status': status,
279 'status_curr': status_curr,
280 'timeout': client.build_timeout})
281
282 caller = test_utils.find_test_caller()
283
284 if caller:
285 message = '(%s) %s' % (caller, message)
286
287 raise lib_exc.TimeoutException(message)