Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 1 | # 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 | |
| 15 | import time |
| 16 | |
| 17 | from oslo_log import log as logging |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 18 | from tempest.lib.common.utils import test_utils |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 19 | from tempest.lib import exceptions as lib_exc |
| 20 | |
Michael Johnson | 97cab83 | 2021-12-01 21:51:54 +0000 | [diff] [blame] | 21 | from designate_tempest_plugin.common import constants as const |
| 22 | from designate_tempest_plugin.common import exceptions |
| 23 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 24 | LOG = logging.getLogger(__name__) |
| 25 | |
| 26 | |
| 27 | def 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 Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 36 | zone = client.show_zone(zone_id)[1] |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 37 | except lib_exc.NotFound: |
| 38 | LOG.info('Zone %s is 404ing', zone_id) |
| 39 | return |
| 40 | |
Michael Johnson | 97cab83 | 2021-12-01 21:51:54 +0000 | [diff] [blame] | 41 | if zone['status'] == const.ERROR: |
| 42 | raise exceptions.InvalidStatusError('Zone', zone_id, |
| 43 | zone['status']) |
| 44 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 45 | 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 | |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 53 | caller = test_utils.find_test_caller() |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 54 | |
| 55 | if caller: |
| 56 | message = '(%s) %s' % (caller, message) |
| 57 | |
| 58 | raise lib_exc.TimeoutException(message) |
| 59 | |
| 60 | |
Michael Johnson | a3a2363 | 2021-07-21 21:55:32 +0000 | [diff] [blame] | 61 | def wait_for_zone_status(client, zone_id, status, headers=None): |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 62 | """Waits for a zone to reach given status.""" |
| 63 | LOG.info('Waiting for zone %s to reach %s', zone_id, status) |
| 64 | |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 65 | zone = client.show_zone(zone_id, headers=headers)[1] |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 66 | start = int(time.time()) |
| 67 | |
| 68 | while zone['status'] != status: |
| 69 | time.sleep(client.build_interval) |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 70 | zone = client.show_zone(zone_id, headers=headers)[1] |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 71 | status_curr = zone['status'] |
| 72 | if status_curr == status: |
| 73 | LOG.info('Zone %s reached %s', zone_id, status) |
| 74 | return |
| 75 | |
Michael Johnson | 8e14049 | 2022-01-31 23:18:56 +0000 | [diff] [blame] | 76 | if zone['status'] == const.ERROR: |
| 77 | raise exceptions.InvalidStatusError('Zone', zone_id, |
| 78 | zone['status']) |
| 79 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 80 | 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 | |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 89 | caller = test_utils.find_test_caller() |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 90 | |
| 91 | if caller: |
| 92 | message = '(%s) %s' % (caller, message) |
| 93 | |
| 94 | raise lib_exc.TimeoutException(message) |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 95 | |
| 96 | |
| 97 | def 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 Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 101 | zone_import = client.show_zone_import(zone_import_id)[1] |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 102 | start = int(time.time()) |
| 103 | |
| 104 | while zone_import['status'] != status: |
| 105 | time.sleep(client.build_interval) |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 106 | zone_import = client.show_zone_import(zone_import_id)[1] |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 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 Johnson | 8e14049 | 2022-01-31 23:18:56 +0000 | [diff] [blame] | 112 | if zone_import['status'] == const.ERROR: |
| 113 | raise exceptions.InvalidStatusError('Zone Import', zone_import_id, |
| 114 | zone_import['status']) |
| 115 | |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 116 | 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 | |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 126 | caller = test_utils.find_test_caller() |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 127 | |
| 128 | if caller: |
| 129 | message = '(%s) %s' % (caller, message) |
| 130 | |
| 131 | raise lib_exc.TimeoutException(message) |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 132 | |
| 133 | |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 134 | def wait_for_zone_export_status(client, zone_export_id, status, headers=None): |
Paul Glass | 7e2a640 | 2016-06-01 21:50:17 +0000 | [diff] [blame] | 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 | |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 138 | zone_export = client.show_zone_export(zone_export_id, headers=headers)[1] |
Paul Glass | 7e2a640 | 2016-06-01 21:50:17 +0000 | [diff] [blame] | 139 | start = int(time.time()) |
| 140 | |
| 141 | while zone_export['status'] != status: |
| 142 | time.sleep(client.build_interval) |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 143 | zone_export = client.show_zone_export( |
| 144 | zone_export_id, headers=headers)[1] |
Paul Glass | 7e2a640 | 2016-06-01 21:50:17 +0000 | [diff] [blame] | 145 | 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 Johnson | 8e14049 | 2022-01-31 23:18:56 +0000 | [diff] [blame] | 150 | if zone_export['status'] == const.ERROR: |
| 151 | raise exceptions.InvalidStatusError('Zone Export', zone_export_id, |
| 152 | zone_export['status']) |
| 153 | |
Paul Glass | 7e2a640 | 2016-06-01 21:50:17 +0000 | [diff] [blame] | 154 | 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 | |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 164 | caller = test_utils.find_test_caller() |
Paul Glass | 7e2a640 | 2016-06-01 21:50:17 +0000 | [diff] [blame] | 165 | |
| 166 | if caller: |
| 167 | message = '(%s) %s' % (caller, message) |
| 168 | |
| 169 | raise lib_exc.TimeoutException(message) |
| 170 | |
| 171 | |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 172 | def wait_for_recordset_status( |
| 173 | client, zone_id, recordset_id, status, headers=None): |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 174 | """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 Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 178 | recordset = client.show_recordset( |
| 179 | zone_id, recordset_id, headers=headers)[1] |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 180 | start = int(time.time()) |
| 181 | |
| 182 | while recordset['status'] != status: |
| 183 | time.sleep(client.build_interval) |
Arkady Shtempler | 356c5ae | 2022-02-05 00:16:35 +0200 | [diff] [blame^] | 184 | recordset = client.show_recordset( |
| 185 | zone_id, recordset_id, headers=headers)[1] |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 186 | status_curr = recordset['status'] |
| 187 | if status_curr == status: |
| 188 | LOG.info('Recordset %s reached %s', recordset_id, status) |
| 189 | return |
| 190 | |
Michael Johnson | 8e14049 | 2022-01-31 23:18:56 +0000 | [diff] [blame] | 191 | if recordset['status'] == const.ERROR: |
| 192 | raise exceptions.InvalidStatusError('Recordset', recordset_id, |
| 193 | recordset['status']) |
| 194 | |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 195 | if int(time.time()) - start >= client.build_timeout: |
| 196 | message = ('Recordset %(recordset_id)s failed to reach ' |
Jens Harbott | d8728b4 | 2018-04-16 09:36:00 +0000 | [diff] [blame] | 197 | 'status=%(status)s within the required time ' |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 198 | '(%(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 | |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 205 | caller = test_utils.find_test_caller() |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 206 | |
| 207 | if caller: |
| 208 | message = '(%s) %s' % (caller, message) |
| 209 | |
Paul Glass | cf98c26 | 2016-05-13 19:34:37 +0000 | [diff] [blame] | 210 | raise lib_exc.TimeoutException(message) |
| 211 | |
| 212 | |
| 213 | def 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 | |
ZhaoBo | ade0492 | 2017-02-10 10:27:29 +0800 | [diff] [blame] | 251 | caller = test_utils.find_test_caller() |
Paul Glass | cf98c26 | 2016-05-13 19:34:37 +0000 | [diff] [blame] | 252 | if caller: |
| 253 | message = "(%s) %s" % (caller, message) |
| 254 | |
| 255 | raise lib_exc.TimeoutException(message) |
Arkady Shtempler | b8ea4ca | 2021-06-04 08:55:28 +0300 | [diff] [blame] | 256 | |
| 257 | |
| 258 | def 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 Johnson | 8e14049 | 2022-01-31 23:18:56 +0000 | [diff] [blame] | 273 | if ptr['status'] == const.ERROR: |
| 274 | raise exceptions.InvalidStatusError('PTR', fip_id, |
| 275 | ptr['status']) |
| 276 | |
Arkady Shtempler | b8ea4ca | 2021-06-04 08:55:28 +0300 | [diff] [blame] | 277 | 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) |