Merge "fullstack: retry on updating port's IP address"
This commit is contained in:
commit
b832508066
@ -15,6 +15,7 @@
|
|||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import netaddr
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
@ -121,3 +122,18 @@ class BaseFullStackTestCase(testlib_api.MySQLTestCaseMixin,
|
|||||||
exception=RuntimeError("Could not ping the other VM, "
|
exception=RuntimeError("Could not ping the other VM, "
|
||||||
"re-starting %s leads to network "
|
"re-starting %s leads to network "
|
||||||
"disruption" % agent_names))
|
"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.")
|
||||||
|
@ -107,10 +107,7 @@ class TestL3Agent(base.BaseFullStackTestCase):
|
|||||||
gateway_port = self.safe_client.list_ports(
|
gateway_port = self.safe_client.list_ports(
|
||||||
device_id=router['id'],
|
device_id=router['id'],
|
||||||
device_owner=constants.DEVICE_OWNER_ROUTER_GW)[0]
|
device_owner=constants.DEVICE_OWNER_ROUTER_GW)[0]
|
||||||
ip_1 = str(netaddr.IPNetwork(
|
ip_1, ip_2 = self._find_available_ips(ext_net, ext_sub, 2)
|
||||||
ext_sub['gateway_ip']).next(100)).split('/')[0]
|
|
||||||
ip_2 = str(netaddr.IPNetwork(
|
|
||||||
ext_sub['gateway_ip']).next(101)).split('/')[0]
|
|
||||||
self.safe_client.update_port(gateway_port['id'], fixed_ips=[
|
self.safe_client.update_port(gateway_port['id'], fixed_ips=[
|
||||||
{'ip_address': ip_1},
|
{'ip_address': ip_1},
|
||||||
{'ip_address': ip_2}])
|
{'ip_address': ip_2}])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user