diff options
author | Artom Lifshitz <alifshit@redhat.com> | 2021-09-27 12:09:12 -0400 |
---|---|---|
committer | Artom Lifshitz <alifshit@redhat.com> | 2021-10-14 10:44:57 -0400 |
commit | 8a959ead1edcd71a55ac0570db407040a36e29b9 (patch) | |
tree | a26e991b0806bc2e123cca9ab992ba19cad30161 /tempest/common/waiters.py | |
parent | ae41052a51f5dbb748eb6bf4f23e9145853f4639 (diff) | |
download | tempest-8a959ead1edcd71a55ac0570db407040a36e29b9.tar.gz |
Add floating IP waiter
In bug 1923194, a floating IP is associated to a server. Upon
performing the operation, Neutron sends Nova a network-vif-changed
external event, causing Nova to update its network info cache. Until
Nova does this, the new floating IP is not reflected in `server show`.
Tempest's `server show` is racing with this process, causing
intermittent failures when the new floating IP does not show up in
`server show` in time.
This patch adds a new waiter that waits for a floating IP to either
appear to disappear in the `server show` output, and modifies two
tests to use the new helper.
Closes bug: 1923194
Change-Id: I0f7e1c9096dc1903903fb31c5e854f07800efbfd
Diffstat (limited to 'tempest/common/waiters.py')
-rw-r--r-- | tempest/common/waiters.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py index f6a4555fe..ae6eec7c7 100644 --- a/tempest/common/waiters.py +++ b/tempest/common/waiters.py @@ -525,3 +525,45 @@ def wait_for_guest_os_boot(client, server_id): server_id) return time.sleep(client.build_interval) + + +def wait_for_server_floating_ip(servers_client, server, floating_ip, + wait_for_disassociate=False): + """Wait for floating IP association or disassociation. + + :param servers_client: The servers client to use when querying the server's + floating IPs. + :param server: The server JSON dict on which to wait. + :param floating_ip: The floating IP JSON dict on which to wait. + :param wait_for_disassociate: Boolean indiating whether to wait for + disassociation instead of association. + """ + + def _get_floating_ip_in_server_addresses(floating_ip, server): + for addresses in server['addresses'].values(): + for address in addresses: + if ( + address['OS-EXT-IPS:type'] == 'floating' and + address['addr'] == floating_ip['floating_ip_address'] + ): + return address + return None + + start_time = int(time.time()) + while True: + server = servers_client.show_server(server['id'])['server'] + address = _get_floating_ip_in_server_addresses(floating_ip, server) + if address is None and wait_for_disassociate: + return None + if not wait_for_disassociate and address: + return address + + if int(time.time()) - start_time >= servers_client.build_timeout: + if wait_for_disassociate: + msg = ('Floating ip %s failed to disassociate from server %s ' + 'in time.' % (floating_ip, server['id'])) + else: + msg = ('Floating ip %s failed to associate with server %s ' + 'in time.' % (floating_ip, server['id'])) + raise lib_exc.TimeoutException(msg) + time.sleep(servers_client.build_interval) |