prefix=FIP_EXT_DEV_PREFIX)
ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips'])
- self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name)
+ self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name,
+ clean_connections=True)
for fixed_ip in ex_gw_port['fixed_ips']:
ip_lib.send_gratuitous_arp(ns_name,
gateway_ips=gateway_ips,
extra_subnets=ex_gw_port.get('extra_subnets', []),
preserve_ips=preserve_ips,
- enable_ra_on_gw=enable_ra_on_gw)
+ enable_ra_on_gw=enable_ra_on_gw,
+ clean_connections=True)
for fixed_ip in ex_gw_port['fixed_ips']:
ip_lib.send_gratuitous_arp(ns_name,
interface_name,
def init_l3(self, device_name, ip_cidrs, namespace=None,
preserve_ips=[], gateway_ips=None, extra_subnets=[],
- enable_ra_on_gw=False):
+ enable_ra_on_gw=False, clean_connections=False):
"""Set the L3 settings for the interface using data from the port.
ip_cidrs: list of 'X.X.X.X/YY' strings
preserve_ips: list of ip cidrs that should not be removed from device
gateway_ips: For gateway ports, list of external gateway ip addresses
enable_ra_on_gw: Boolean to indicate configuring acceptance of IPv6 RA
+ clean_connections: Boolean to indicate if we should cleanup connections
+ associated to removed ips
"""
device = ip_lib.IPDevice(device_name, namespace=namespace)
# clean up any old addresses
for ip_cidr in previous:
if ip_cidr not in preserve_ips:
- device.delete_addr_and_conntrack_state(ip_cidr)
+ if clean_connections:
+ device.delete_addr_and_conntrack_state(ip_cidr)
+ else:
+ device.addr.delete(ip_cidr)
for gateway_ip in gateway_ips or []:
device.route.add_gateway(gateway_ip)
'gateway_ips': gateway_ips,
'namespace': 'qrouter-' + router['id'],
'extra_subnets': [],
- 'enable_ra_on_gw': enable_ra_on_gw}
+ 'enable_ra_on_gw': enable_ra_on_gw,
+ 'clean_connections': True}
else:
exp_arp_calls = [mock.call(ri.ns_name, interface_name,
'20.0.0.30', mock.ANY)]
'gateway_ips': gateway_ips,
'namespace': 'qrouter-' + router['id'],
'extra_subnets': [{'cidr': '172.16.0.0/24'}],
- 'enable_ra_on_gw': enable_ra_on_gw}
+ 'enable_ra_on_gw': enable_ra_on_gw,
+ 'clean_connections': True}
self.mock_driver.init_l3.assert_called_with(interface_name,
ip_cidrs,
**kwargs)
'gateway_ips': gateway_ips,
'namespace': 'qrouter-' + router['id'],
'extra_subnets': [{'cidr': '172.16.0.0/24'}],
- 'enable_ra_on_gw': False}
+ 'enable_ra_on_gw': False,
+ 'clean_connections': True}
self.mock_driver.init_l3.assert_called_with(interface_name,
ip_cidrs,
**kwargs)
[mock.call('tap0', namespace=ns),
mock.call().addr.list(filters=['permanent']),
mock.call().addr.add('192.168.1.2/24'),
- mock.call().delete_addr_and_conntrack_state('172.16.77.240/24'),
+ mock.call().addr.delete('172.16.77.240/24'),
mock.call().route.list_onlink_routes(constants.IP_VERSION_4),
mock.call().route.list_onlink_routes(constants.IP_VERSION_6),
mock.call().route.add_onlink_route('172.20.0.0/24')])
self.assertFalse(self.ip_dev().addr.delete.called)
self.assertFalse(self.ip_dev().delete_addr_and_conntrack_state.called)
+ def _test_l3_init_clean_connections(self, clean_connections):
+ addresses = [
+ dict(scope='global', dynamic=False, cidr='10.0.0.1/24'),
+ dict(scope='global', dynamic=False, cidr='10.0.0.3/32')]
+ self.ip_dev().addr.list = mock.Mock(return_value=addresses)
+
+ bc = BaseChild(self.conf)
+ ns = '12345678-1234-5678-90ab-ba0987654321'
+ bc.init_l3('tap0', ['10.0.0.1/24'], namespace=ns,
+ clean_connections=clean_connections)
+
+ delete = self.ip_dev().delete_addr_and_conntrack_state
+ if clean_connections:
+ delete.assert_called_once_with('10.0.0.3/32')
+ else:
+ self.assertFalse(delete.called)
+
+ def test_l3_init_with_clean_connections(self):
+ self._test_l3_init_clean_connections(True)
+
+ def test_l3_init_without_clean_connections(self):
+ self._test_l3_init_clean_connections(False)
+
def _test_l3_init_with_ipv6(self, include_gw_ip):
addresses = [dict(scope='global',
dynamic=False,
[mock.call('tap0', namespace=ns),
mock.call().addr.list(filters=['permanent']),
mock.call().addr.add('2001:db8:a::124/64'),
- mock.call().delete_addr_and_conntrack_state(
- '2001:db8:a::123/64')])
+ mock.call().addr.delete('2001:db8:a::123/64')])
if include_gw_ip:
expected_calls += (
[mock.call().route.add_gateway('2001:db8:a::1')])
mock.call().addr.list(filters=['permanent']),
mock.call().addr.add('192.168.1.2/24'),
mock.call().addr.add('2001:db8:a::124/64'),
- mock.call().delete_addr_and_conntrack_state('172.16.77.240/24'),
- mock.call().delete_addr_and_conntrack_state('2001:db8:a::123/64'),
+ mock.call().addr.delete('172.16.77.240/24'),
+ mock.call().addr.delete('2001:db8:a::123/64'),
mock.call().route.list_onlink_routes(constants.IP_VERSION_4),
mock.call().route.list_onlink_routes(constants.IP_VERSION_6),
mock.call().route.add_onlink_route('172.20.0.0/24')],