blob: 5a352559405ba8f028cd2980dce5783252bbf951 [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
76 if int(time.time()) - start >= client.build_timeout:
77 message = ('Zone %(zone_id)s failed to reach status=%(status)s '
78 'within the required time (%(timeout)s s). Current '
79 'status: %(status_curr)s' %
80 {'zone_id': zone_id,
81 'status': status,
82 'status_curr': status_curr,
83 'timeout': client.build_timeout})
84
ZhaoBoade04922017-02-10 10:27:29 +080085 caller = test_utils.find_test_caller()
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010086
87 if caller:
88 message = '(%s) %s' % (caller, message)
89
90 raise lib_exc.TimeoutException(message)
sonu.kumaraec952a2016-04-20 10:08:46 +090091
92
93def wait_for_zone_import_status(client, zone_import_id, status):
94 """Waits for an imported zone to reach the given status."""
95 LOG.info('Waiting for zone import %s to reach %s', zone_import_id, status)
96
97 _, zone_import = client.show_zone_import(zone_import_id)
98 start = int(time.time())
99
100 while zone_import['status'] != status:
101 time.sleep(client.build_interval)
102 _, zone_import = client.show_zone_import(zone_import_id)
103 status_curr = zone_import['status']
104 if status_curr == status:
105 LOG.info('Zone import %s reached %s', zone_import_id, status)
106 return
107
108 if int(time.time()) - start >= client.build_timeout:
109 message = ('Zone import %(zone_import_id)s failed to reach '
110 'status=%(status)s within the required time '
111 '(%(timeout)s s). Current '
112 'status: %(status_curr)s' %
113 {'zone_import_id': zone_import_id,
114 'status': status,
115 'status_curr': status_curr,
116 'timeout': client.build_timeout})
117
ZhaoBoade04922017-02-10 10:27:29 +0800118 caller = test_utils.find_test_caller()
sonu.kumaraec952a2016-04-20 10:08:46 +0900119
120 if caller:
121 message = '(%s) %s' % (caller, message)
122
123 raise lib_exc.TimeoutException(message)
sonu.kumarde24d962016-05-05 00:28:00 +0900124
125
Paul Glass7e2a6402016-06-01 21:50:17 +0000126def wait_for_zone_export_status(client, zone_export_id, status):
127 """Waits for an exported zone to reach the given status."""
128 LOG.info('Waiting for zone export %s to reach %s', zone_export_id, status)
129
130 _, zone_export = client.show_zone_export(zone_export_id)
131 start = int(time.time())
132
133 while zone_export['status'] != status:
134 time.sleep(client.build_interval)
135 _, zone_export = client.show_zone_export(zone_export_id)
136 status_curr = zone_export['status']
137 if status_curr == status:
138 LOG.info('Zone export %s reached %s', zone_export_id, status)
139 return
140
141 if int(time.time()) - start >= client.build_timeout:
142 message = ('Zone export %(zone_export_id)s failed to reach '
143 'status=%(status)s within the required time '
144 '(%(timeout)s s). Current '
145 'status: %(status_curr)s' %
146 {'zone_export_id': zone_export_id,
147 'status': status,
148 'status_curr': status_curr,
149 'timeout': client.build_timeout})
150
ZhaoBoade04922017-02-10 10:27:29 +0800151 caller = test_utils.find_test_caller()
Paul Glass7e2a6402016-06-01 21:50:17 +0000152
153 if caller:
154 message = '(%s) %s' % (caller, message)
155
156 raise lib_exc.TimeoutException(message)
157
158
Eric Larsondc715e12016-08-25 13:21:35 +0100159def wait_for_recordset_status(client, zone_id, recordset_id, status):
sonu.kumarde24d962016-05-05 00:28:00 +0900160 """Waits for a recordset to reach the given status."""
161 LOG.info('Waiting for recordset %s to reach %s',
162 recordset_id, status)
163
Eric Larsondc715e12016-08-25 13:21:35 +0100164 _, recordset = client.show_recordset(zone_id, recordset_id)
sonu.kumarde24d962016-05-05 00:28:00 +0900165 start = int(time.time())
166
167 while recordset['status'] != status:
168 time.sleep(client.build_interval)
Eric Larsondc715e12016-08-25 13:21:35 +0100169 _, recordset = client.show_recordset(zone_id, recordset_id)
sonu.kumarde24d962016-05-05 00:28:00 +0900170 status_curr = recordset['status']
171 if status_curr == status:
172 LOG.info('Recordset %s reached %s', recordset_id, status)
173 return
174
175 if int(time.time()) - start >= client.build_timeout:
176 message = ('Recordset %(recordset_id)s failed to reach '
Jens Harbottd8728b42018-04-16 09:36:00 +0000177 'status=%(status)s within the required time '
sonu.kumarde24d962016-05-05 00:28:00 +0900178 '(%(timeout)s s). Current '
179 'status: %(status_curr)s' %
180 {'recordset_id': recordset_id,
181 'status': status,
182 'status_curr': status_curr,
183 'timeout': client.build_timeout})
184
ZhaoBoade04922017-02-10 10:27:29 +0800185 caller = test_utils.find_test_caller()
sonu.kumarde24d962016-05-05 00:28:00 +0900186
187 if caller:
188 message = '(%s) %s' % (caller, message)
189
Paul Glasscf98c262016-05-13 19:34:37 +0000190 raise lib_exc.TimeoutException(message)
191
192
193def wait_for_query(client, name, rdatatype, found=True):
194 """Query nameservers until the record of the given name and type is found.
195
196 :param client: A QueryClient
197 :param name: The record name for which to query
198 :param rdatatype: The record type for which to query
199 :param found: If True, wait until the record is found. Else, wait until the
200 record disappears.
201 """
202 state = "found" if found else "removed"
203 LOG.info("Waiting for record %s of type %s to be %s on nameservers %s",
204 name, rdatatype, state, client.nameservers)
205 start = int(time.time())
206
207 while True:
208 time.sleep(client.build_interval)
209
210 responses = client.query(name, rdatatype)
211 if found:
212 all_answers_good = all(r.answer for r in responses)
213 else:
214 all_answers_good = all(not r.answer for r in responses)
215
216 if not client.nameservers or all_answers_good:
217 LOG.info("Record %s of type %s was successfully %s on nameservers "
218 "%s", name, rdatatype, state, client.nameservers)
219 return
220
221 if int(time.time()) - start >= client.build_timeout:
222 message = ('Record %(name)s of type %(rdatatype)s not %(state)s '
223 'on nameservers %(nameservers)s within the required '
224 'time (%(timeout)s s)' %
225 {'name': name,
226 'rdatatype': rdatatype,
227 'state': state,
228 'nameservers': client.nameservers,
229 'timeout': client.build_timeout})
230
ZhaoBoade04922017-02-10 10:27:29 +0800231 caller = test_utils.find_test_caller()
Paul Glasscf98c262016-05-13 19:34:37 +0000232 if caller:
233 message = "(%s) %s" % (caller, message)
234
235 raise lib_exc.TimeoutException(message)