File 0001-Wait-and-retry-while-getting-server-port-and-ipv4.patch of Package openstack-tempest
From 54c591b0ab0cf1462bd1cc60ade88b0fe13892e4 Mon Sep 17 00:00:00 2001
From: Thomas Bechtold <tbechtold@suse.com>
Date: Mon, 8 Feb 2016 18:40:26 +0100
Subject: [PATCH] Wait and retry while getting server port and ipv4
When creating a floating IP and getting the server port and ip address(es)
it may take some seconds until the port is in 'ACTIVE' state.
In a test environment with Xen+libvirt the test failed because the port was
initially in 'DOWN' stateand after ~1s it was active.
So wait and retry to fix the test case race.
Change-Id: I664b7fa234e431f229dac51e62c529f9ace5d389
---
tempest/scenario/manager.py | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
Index: tempest-7.0.0/tempest/scenario/manager.py
===================================================================
--- tempest-7.0.0.orig/tempest/scenario/manager.py
+++ tempest-7.0.0/tempest/scenario/manager.py
@@ -31,6 +31,7 @@ from tempest import config
from tempest import exceptions
from tempest.services.network import resources as net_resources
import tempest.test
+import time
CONF = config.CONF
@@ -750,6 +751,18 @@ class NetworkScenarioTest(ScenarioTest):
def _get_server_port_id_and_ip4(self, server, ip_addr=None):
ports = self._list_ports(device_id=server['id'], status='ACTIVE',
fixed_ip=ip_addr)
+ # it could take a bit of time to have a 'ACTIVE' port. The port is
+ # maybe in 'DOWN' state so retry some seconds
+ now = time.time()
+ timeout = now + 10
+ while now < timeout:
+ ports = self._list_ports(device_id=server['id'], status='ACTIVE',
+ fixed_ip=ip_addr)
+ if len(ports):
+ break
+ time.sleep(2)
+ now = time.time()
+
# it might happen here that this port has more then one ip address
# as in case of dual stack- when this port is created on 2 subnets
port_map = [(p["id"], fxip["ip_address"])