Yuiko Takada | b652700 | 2015-12-07 11:49:12 +0900 | [diff] [blame] | 1 | # All Rights Reserved. |
| 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 | |
| 16 | import time |
| 17 | |
Lenny Verkhovsky | 8862504 | 2016-03-08 17:44:00 +0200 | [diff] [blame] | 18 | from tempest.lib.common.utils import misc as misc_utils |
| 19 | from tempest.lib import exceptions as lib_exc |
Yuiko Takada | b652700 | 2015-12-07 11:49:12 +0900 | [diff] [blame] | 20 | |
| 21 | |
| 22 | def wait_for_bm_node_status(client, node_id, attr, status): |
| 23 | """Waits for a baremetal node attribute to reach given status. |
| 24 | |
| 25 | The client should have a show_node(node_uuid) method to get the node. |
| 26 | """ |
| 27 | _, node = client.show_node(node_id) |
| 28 | start = int(time.time()) |
| 29 | |
| 30 | while node[attr] != status: |
| 31 | time.sleep(client.build_interval) |
| 32 | _, node = client.show_node(node_id) |
| 33 | status_curr = node[attr] |
| 34 | if status_curr == status: |
| 35 | return |
| 36 | |
| 37 | if int(time.time()) - start >= client.build_timeout: |
| 38 | message = ('Node %(node_id)s failed to reach %(attr)s=%(status)s ' |
| 39 | 'within the required time (%(timeout)s s).' % |
| 40 | {'node_id': node_id, |
| 41 | 'attr': attr, |
| 42 | 'status': status, |
| 43 | 'timeout': client.build_timeout}) |
| 44 | message += ' Current state of %s: %s.' % (attr, status_curr) |
| 45 | caller = misc_utils.find_test_caller() |
| 46 | if caller: |
| 47 | message = '(%s) %s' % (caller, message) |
| 48 | raise lib_exc.TimeoutException(message) |