Delete gateway conntrack state when remove external gateway

This fixed the problem that a gateway ip conntrack state not cleared
when user clears a router external gateway.

Change-Id: I77f22d9504430259b01366e6296a99ba1cd6a046
Closes-Bug: #1488730
This commit is contained in:
Yi Zhao 2015-08-27 15:24:21 +08:00 committed by Zhao Yi
parent 397fc4dcb5
commit 37430d4bd0
4 changed files with 23 additions and 4 deletions

View File

@ -362,10 +362,10 @@ class HaRouter(router.RouterInfo):
interface_name)
def delete(self, agent):
super(HaRouter, self).delete(agent)
self.destroy_state_change_monitor(self.process_monitor)
self.ha_network_removed()
self.disable_keepalived()
super(HaRouter, self).delete(agent)
def process(self, agent):
super(HaRouter, self).process(agent)

View File

@ -202,6 +202,9 @@ class RouterInfo(object):
def remove_floating_ip(self, device, ip_cidr):
device.delete_addr_and_conntrack_state(ip_cidr)
def remove_external_gateway_ip(self, device, ip_cidr):
device.delete_addr_and_conntrack_state(ip_cidr)
def get_router_cidrs(self, device):
return set([addr['cidr'] for addr in device.addr.list()])
@ -538,6 +541,12 @@ class RouterInfo(object):
def external_gateway_removed(self, ex_gw_port, interface_name):
LOG.debug("External gateway removed: port(%s), interface(%s)",
ex_gw_port, interface_name)
device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
for ip_addr in ex_gw_port['fixed_ips']:
self.remove_external_gateway_ip(device,
common_utils.ip_to_cidr(
ip_addr['ip_address'],
ip_addr['prefixlen']))
self.driver.unplug(interface_name,
bridge=self.agent_conf.external_network_bridge,
namespace=self.ns_name,

View File

@ -231,9 +231,10 @@ class IPDevice(SubProcessBase):
This terminates any active connections through an IP.
cidr: the IP address for which state should be removed. This can be
passed as a string with or without /NN. A netaddr.IPAddress or
netaddr.Network representing the IP address can also be passed.
:param cidr: the IP address for which state should be removed.
This can be passed as a string with or without /NN.
A netaddr.IPAddress or netaddr.Network representing the IP address
can also be passed.
"""
self.addr.delete(cidr)

View File

@ -48,6 +48,15 @@ class TestBasicRouterOperations(BasicRouterTestCaseFramework):
device.delete_addr_and_conntrack_state.assert_called_once_with(cidr)
def test_remove_external_gateway_ip(self):
ri = self._create_router(mock.MagicMock())
device = mock.Mock()
cidr = '172.16.0.0/24'
ri.remove_external_gateway_ip(device, cidr)
device.delete_addr_and_conntrack_state.assert_called_once_with(cidr)
@mock.patch.object(ip_lib, 'send_ip_addr_adv_notif')
class TestAddFloatingIpWithMockGarp(BasicRouterTestCaseFramework):