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 |
| 18 | from tempest.lib.common.utils import misc as misc_utils |
| 19 | from tempest.lib import exceptions as lib_exc |
| 20 | |
| 21 | LOG = logging.getLogger(__name__) |
| 22 | |
| 23 | |
| 24 | def 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 | |
| 46 | caller = misc_utils.find_test_caller() |
| 47 | |
| 48 | if caller: |
| 49 | message = '(%s) %s' % (caller, message) |
| 50 | |
| 51 | raise lib_exc.TimeoutException(message) |
| 52 | |
| 53 | |
| 54 | def 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 | |
| 78 | caller = misc_utils.find_test_caller() |
| 79 | |
| 80 | if caller: |
| 81 | message = '(%s) %s' % (caller, message) |
| 82 | |
| 83 | raise lib_exc.TimeoutException(message) |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 84 | |
| 85 | |
| 86 | def 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 | |
| 111 | caller = misc_utils.find_test_caller() |
| 112 | |
| 113 | if caller: |
| 114 | message = '(%s) %s' % (caller, message) |
| 115 | |
| 116 | raise lib_exc.TimeoutException(message) |
sonu.kumar | de24d96 | 2016-05-05 00:28:00 +0900 | [diff] [blame] | 117 | |
| 118 | |
| 119 | def wait_for_recordset_status(client, recordset_id, status): |
| 120 | """Waits for a recordset to reach the given status.""" |
| 121 | LOG.info('Waiting for recordset %s to reach %s', |
| 122 | recordset_id, status) |
| 123 | |
| 124 | _, recordset = client.show_recordset(recordset_id) |
| 125 | start = int(time.time()) |
| 126 | |
| 127 | while recordset['status'] != status: |
| 128 | time.sleep(client.build_interval) |
| 129 | _, recordset = client.show_recordset(recordset_id) |
| 130 | status_curr = recordset['status'] |
| 131 | if status_curr == status: |
| 132 | LOG.info('Recordset %s reached %s', recordset_id, status) |
| 133 | return |
| 134 | |
| 135 | if int(time.time()) - start >= client.build_timeout: |
| 136 | message = ('Recordset %(recordset_id)s failed to reach ' |
| 137 | 'status=%(status) within the required time ' |
| 138 | '(%(timeout)s s). Current ' |
| 139 | 'status: %(status_curr)s' % |
| 140 | {'recordset_id': recordset_id, |
| 141 | 'status': status, |
| 142 | 'status_curr': status_curr, |
| 143 | 'timeout': client.build_timeout}) |
| 144 | |
| 145 | caller = misc_utils.find_test_caller() |
| 146 | |
| 147 | if caller: |
| 148 | message = '(%s) %s' % (caller, message) |
| 149 | |
| 150 | raise lib_exc.TimeoutException(message) |