fullstack: retry on updating port's IP address

If the update_port call failed with error IpAddressAlreadyAllocatedClient,
retry a few more times in order to find IP addresses that are available.

Change-Id: I7c5d51b01fa56083b1a689fa629a9a34c8b77012
Closes-Bug: #1808595
This commit is contained in:
Hongbin Lu 2018-12-14 22:04:48 +00:00
parent a9f408242c
commit ae4b331725
2 changed files with 17 additions and 4 deletions

View File

@ -15,6 +15,7 @@
from concurrent import futures
import os
import netaddr
from oslo_config import cfg
from oslo_log import log as logging
@ -121,3 +122,18 @@ class BaseFullStackTestCase(testlib_api.MySQLTestCaseMixin,
exception=RuntimeError("Could not ping the other VM, "
"re-starting %s leads to network "
"disruption" % agent_names))
def _find_available_ips(self, network, subnet, num):
ports = self.safe_client.list_ports(network_id=network['id'])
used_ips = [ip['ip_address']
for port in ports for ip in port['fixed_ips']]
used_ips.append(subnet['gateway_ip'])
available_ips = []
for ip in netaddr.IPNetwork(subnet['cidr']).iter_hosts():
ip = str(ip)
if ip not in used_ips:
available_ips.append(ip)
if len(available_ips) >= num:
return available_ips
self.fail("Cannot find enough free IP addresses.")

View File

@ -107,10 +107,7 @@ class TestL3Agent(base.BaseFullStackTestCase):
gateway_port = self.safe_client.list_ports(
device_id=router['id'],
device_owner=constants.DEVICE_OWNER_ROUTER_GW)[0]
ip_1 = str(netaddr.IPNetwork(
ext_sub['gateway_ip']).next(100)).split('/')[0]
ip_2 = str(netaddr.IPNetwork(
ext_sub['gateway_ip']).next(101)).split('/')[0]
ip_1, ip_2 = self._find_available_ips(ext_net, ext_sub, 2)
self.safe_client.update_port(gateway_port['id'], fixed_ips=[
{'ip_address': ip_1},
{'ip_address': ip_2}])