Merge "Split the FIP Namespace delete in L3 agent for DVR" into stable/liberty

This commit is contained in:
Jenkins 2016-04-12 11:05:01 +00:00 committed by Gerrit Code Review
commit 720e40bf77
3 changed files with 13 additions and 58 deletions

View File

@ -139,26 +139,10 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
self.fip_ns.local_subnets.release(self.router_id)
self.rtr_fip_subnet = None
ns_ip.del_veth(fip_2_rtr_name)
is_last = self.fip_ns.unsubscribe(self.router_id)
if is_last:
# TODO(Carl) I can't help but think that another router could
# come in and want to start using this namespace while this is
# destroying it. The two could end up conflicting on
# creating/destroying interfaces and such. I think I'd like a
# semaphore to sync creation/deletion of this namespace.
# NOTE (Swami): Since we are deleting the namespace here we
# should be able to delete the floatingip agent gateway port
# for the provided external net since we don't need it anymore.
if self.fip_ns.agent_gateway_port:
LOG.debug('Removed last floatingip, so requesting the '
'server to delete Floatingip Agent Gateway port:'
'%s', self.fip_ns.agent_gateway_port)
self.agent.plugin_rpc.delete_agent_gateway_port(
self.agent.context,
self.fip_ns.agent_gateway_port['network_id'])
self.fip_ns.delete()
self.fip_ns = None
self.fip_ns.unsubscribe(self.router_id)
# NOTE (Swami): The fg interface and the namespace will be deleted
# when the external gateway port is removed. This will be
# initiated from the server through an RPC call.
def add_floating_ip(self, fip, interface_name, device):
if not self._add_fip_addr_to_device(fip, device):

View File

@ -1154,7 +1154,6 @@ class TestDvrRouter(L3AgentTestFramework):
self._assert_extra_routes(router, namespace=snat_ns_name)
self._delete_router(self.agent, router.router_id)
self._assert_interfaces_deleted_from_ovs()
self._assert_router_does_not_exist(router)
def generate_dvr_router_info(self,
@ -1358,7 +1357,7 @@ class TestDvrRouter(L3AgentTestFramework):
router1.router[l3_constants.FLOATINGIP_KEY] = []
self.manage_router(restarted_agent, router1.router)
self._assert_dvr_snat_gateway(router1)
self.assertFalse(self._namespace_exists(fip_ns))
self.assertTrue(self._namespace_exists(fip_ns))
def test_dvr_router_add_fips_on_restarted_agent(self):
self.agent.conf.agent_mode = 'dvr'
@ -1517,30 +1516,6 @@ class TestDvrRouter(L3AgentTestFramework):
self.assertFalse(sg_device)
self.assertTrue(qg_device)
def test_dvr_router_calls_delete_agent_gateway_if_last_fip(self):
"""Test to validate delete fip if it is last fip managed by agent."""
self.agent.conf.agent_mode = 'dvr_snat'
router_info = self.generate_dvr_router_info(enable_snat=True)
router1 = self.manage_router(self.agent, router_info)
floating_agent_gw_port = (
router1.router[l3_constants.FLOATINGIP_AGENT_INTF_KEY])
self.assertTrue(floating_agent_gw_port)
fip_ns = router1.fip_ns.get_name()
router1.fip_ns.agent_gw_port = floating_agent_gw_port
self.assertTrue(self._namespace_exists(router1.ns_name))
self.assertTrue(self._namespace_exists(fip_ns))
self._assert_dvr_floating_ips(router1)
self._assert_dvr_snat_gateway(router1)
router1.router[l3_constants.FLOATINGIP_KEY] = []
rpc_mock = mock.patch.object(
self.agent.plugin_rpc, 'delete_agent_gateway_port').start()
self.agent._process_updated_router(router1.router)
self.assertTrue(rpc_mock.called)
rpc_mock.assert_called_once_with(
self.agent.context,
floating_agent_gw_port[0]['network_id'])
self.assertFalse(self._namespace_exists(fip_ns))
def test_dvr_router_static_routes(self):
"""Test to validate the extra routes on dvr routers."""
self.agent.conf.agent_mode = 'dvr_snat'

View File

@ -259,18 +259,14 @@ class TestDvrRouterOperations(base.BaseTestCase):
ri.fip_ns.local_subnets.allocate.return_value = s1
_, fip_to_rtr = s1.get_pair()
fip_ns = ri.fip_ns
with mock.patch.object(self.plugin_api,
'delete_agent_gateway_port') as del_fip_gw:
ri.floating_ip_removed_dist(fip_cidr)
self.assertTrue(del_fip_gw.called)
self.assertTrue(fip_ns.destroyed)
mIPWrapper().del_veth.assert_called_once_with(
fip_ns.get_int_device_name(router['id']))
mIPDevice().route.delete_gateway.assert_called_once_with(
str(fip_to_rtr.ip), table=16)
fip_ns.unsubscribe.assert_called_once_with(ri.router_id)
fip_ns.local_subnets.allocate.assert_called_once_with(
ri.router_id)
ri.floating_ip_removed_dist(fip_cidr)
self.assertTrue(fip_ns.destroyed)
mIPWrapper().del_veth.assert_called_once_with(
fip_ns.get_int_device_name(router['id']))
mIPDevice().route.delete_gateway.assert_called_once_with(
str(fip_to_rtr.ip), table=16)
fip_ns.unsubscribe.assert_called_once_with(ri.router_id)
fip_ns.local_subnets.allocate.assert_called_once_with(ri.router_id)
def _test_add_floating_ip(self, ri, fip, is_failure):
ri._add_fip_addr_to_device = mock.Mock(return_value=is_failure)