blob: 5c0662397218d97e345dc1c64b18d79e37e518ba [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
21LOG = logging.getLogger(__name__)
22
23
24def wait_for_zone_404(client, zone_id):
25 """Waits for a zone to 404."""
26 LOG.info('Waiting for zone %s to 404', zone_id)
27 start = int(time.time())
28
29 while True:
30 time.sleep(client.build_interval)
31
32 try:
33 _, zone = client.show_zone(zone_id)
34 except lib_exc.NotFound:
35 LOG.info('Zone %s is 404ing', zone_id)
36 return
37
38 if int(time.time()) - start >= client.build_timeout:
39 message = ('Zone %(zone_id)s failed to 404 within the required '
40 'time (%(timeout)s s). Current status: '
41 '%(status_curr)s' %
42 {'zone_id': zone_id,
43 'status_curr': zone['status'],
44 'timeout': client.build_timeout})
45
ZhaoBoade04922017-02-10 10:27:29 +080046 caller = test_utils.find_test_caller()
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010047
48 if caller:
49 message = '(%s) %s' % (caller, message)
50
51 raise lib_exc.TimeoutException(message)
52
53
54def wait_for_zone_status(client, zone_id, status):
55 """Waits for a zone to reach given status."""
56 LOG.info('Waiting for zone %s to reach %s', zone_id, status)
57
58 _, zone = client.show_zone(zone_id)
59 start = int(time.time())
60
61 while zone['status'] != status:
62 time.sleep(client.build_interval)
63 _, zone = client.show_zone(zone_id)
64 status_curr = zone['status']
65 if status_curr == status:
66 LOG.info('Zone %s reached %s', zone_id, status)
67 return
68
69 if int(time.time()) - start >= client.build_timeout:
70 message = ('Zone %(zone_id)s failed to reach status=%(status)s '
71 'within the required time (%(timeout)s s). Current '
72 'status: %(status_curr)s' %
73 {'zone_id': zone_id,
74 'status': status,
75 'status_curr': status_curr,
76 'timeout': client.build_timeout})
77
ZhaoBoade04922017-02-10 10:27:29 +080078 caller = test_utils.find_test_caller()
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010079
80 if caller:
81 message = '(%s) %s' % (caller, message)
82
83 raise lib_exc.TimeoutException(message)
sonu.kumaraec952a2016-04-20 10:08:46 +090084
85
86def wait_for_zone_import_status(client, zone_import_id, status):
87 """Waits for an imported zone to reach the given status."""
88 LOG.info('Waiting for zone import %s to reach %s', zone_import_id, status)
89
90 _, zone_import = client.show_zone_import(zone_import_id)
91 start = int(time.time())
92
93 while zone_import['status'] != status:
94 time.sleep(client.build_interval)
95 _, zone_import = client.show_zone_import(zone_import_id)
96 status_curr = zone_import['status']
97 if status_curr == status:
98 LOG.info('Zone import %s reached %s', zone_import_id, status)
99 return
100
101 if int(time.time()) - start >= client.build_timeout:
102 message = ('Zone import %(zone_import_id)s failed to reach '
103 'status=%(status)s within the required time '
104 '(%(timeout)s s). Current '
105 'status: %(status_curr)s' %
106 {'zone_import_id': zone_import_id,
107 'status': status,
108 'status_curr': status_curr,
109 'timeout': client.build_timeout})
110
ZhaoBoade04922017-02-10 10:27:29 +0800111 caller = test_utils.find_test_caller()
sonu.kumaraec952a2016-04-20 10:08:46 +0900112
113 if caller:
114 message = '(%s) %s' % (caller, message)
115
116 raise lib_exc.TimeoutException(message)
sonu.kumarde24d962016-05-05 00:28:00 +0900117
118
Paul Glass7e2a6402016-06-01 21:50:17 +0000119def wait_for_zone_export_status(client, zone_export_id, status):
120 """Waits for an exported zone to reach the given status."""
121 LOG.info('Waiting for zone export %s to reach %s', zone_export_id, status)
122
123 _, zone_export = client.show_zone_export(zone_export_id)
124 start = int(time.time())
125
126 while zone_export['status'] != status:
127 time.sleep(client.build_interval)
128 _, zone_export = client.show_zone_export(zone_export_id)
129 status_curr = zone_export['status']
130 if status_curr == status:
131 LOG.info('Zone export %s reached %s', zone_export_id, status)
132 return
133
134 if int(time.time()) - start >= client.build_timeout:
135 message = ('Zone export %(zone_export_id)s failed to reach '
136 'status=%(status)s within the required time '
137 '(%(timeout)s s). Current '
138 'status: %(status_curr)s' %
139 {'zone_export_id': zone_export_id,
140 'status': status,
141 'status_curr': status_curr,
142 'timeout': client.build_timeout})
143
ZhaoBoade04922017-02-10 10:27:29 +0800144 caller = test_utils.find_test_caller()
Paul Glass7e2a6402016-06-01 21:50:17 +0000145
146 if caller:
147 message = '(%s) %s' % (caller, message)
148
149 raise lib_exc.TimeoutException(message)
150
151
Eric Larsondc715e12016-08-25 13:21:35 +0100152def wait_for_recordset_status(client, zone_id, recordset_id, status):
sonu.kumarde24d962016-05-05 00:28:00 +0900153 """Waits for a recordset to reach the given status."""
154 LOG.info('Waiting for recordset %s to reach %s',
155 recordset_id, status)
156
Eric Larsondc715e12016-08-25 13:21:35 +0100157 _, recordset = client.show_recordset(zone_id, recordset_id)
sonu.kumarde24d962016-05-05 00:28:00 +0900158 start = int(time.time())
159
160 while recordset['status'] != status:
161 time.sleep(client.build_interval)
Eric Larsondc715e12016-08-25 13:21:35 +0100162 _, recordset = client.show_recordset(zone_id, recordset_id)
sonu.kumarde24d962016-05-05 00:28:00 +0900163 status_curr = recordset['status']
164 if status_curr == status:
165 LOG.info('Recordset %s reached %s', recordset_id, status)
166 return
167
168 if int(time.time()) - start >= client.build_timeout:
169 message = ('Recordset %(recordset_id)s failed to reach '
170 'status=%(status) within the required time '
171 '(%(timeout)s s). Current '
172 'status: %(status_curr)s' %
173 {'recordset_id': recordset_id,
174 'status': status,
175 'status_curr': status_curr,
176 'timeout': client.build_timeout})
177
ZhaoBoade04922017-02-10 10:27:29 +0800178 caller = test_utils.find_test_caller()
sonu.kumarde24d962016-05-05 00:28:00 +0900179
180 if caller:
181 message = '(%s) %s' % (caller, message)
182
Paul Glasscf98c262016-05-13 19:34:37 +0000183 raise lib_exc.TimeoutException(message)
184
185
186def wait_for_query(client, name, rdatatype, found=True):
187 """Query nameservers until the record of the given name and type is found.
188
189 :param client: A QueryClient
190 :param name: The record name for which to query
191 :param rdatatype: The record type for which to query
192 :param found: If True, wait until the record is found. Else, wait until the
193 record disappears.
194 """
195 state = "found" if found else "removed"
196 LOG.info("Waiting for record %s of type %s to be %s on nameservers %s",
197 name, rdatatype, state, client.nameservers)
198 start = int(time.time())
199
200 while True:
201 time.sleep(client.build_interval)
202
203 responses = client.query(name, rdatatype)
204 if found:
205 all_answers_good = all(r.answer for r in responses)
206 else:
207 all_answers_good = all(not r.answer for r in responses)
208
209 if not client.nameservers or all_answers_good:
210 LOG.info("Record %s of type %s was successfully %s on nameservers "
211 "%s", name, rdatatype, state, client.nameservers)
212 return
213
214 if int(time.time()) - start >= client.build_timeout:
215 message = ('Record %(name)s of type %(rdatatype)s not %(state)s '
216 'on nameservers %(nameservers)s within the required '
217 'time (%(timeout)s s)' %
218 {'name': name,
219 'rdatatype': rdatatype,
220 'state': state,
221 'nameservers': client.nameservers,
222 'timeout': client.build_timeout})
223
ZhaoBoade04922017-02-10 10:27:29 +0800224 caller = test_utils.find_test_caller()
Paul Glasscf98c262016-05-13 19:34:37 +0000225 if caller:
226 message = "(%s) %s" % (caller, message)
227
228 raise lib_exc.TimeoutException(message)