blob: a75870b298df0468986962ac1f1e1e96c5e81178 [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
18from tempest.lib.common.utils import misc as misc_utils
19from 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
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
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
78 caller = misc_utils.find_test_caller()
79
80 if caller:
81 message = '(%s) %s' % (caller, message)
82
83 raise lib_exc.TimeoutException(message)