From feca5bef45280589bee7347164530176844f43b3 Mon Sep 17 00:00:00 2001 From: Sylvain Afchain Date: Thu, 20 Nov 2014 14:25:58 +0000 Subject: [PATCH] Fix floating-ips in error state in dvr mode Before this fix an exception was raised when creating the veth between the fip namespace and the qrouter namespace when the veth was already present. This fix add a check to only create the veth if not present. Change-Id: Iefea9778223aac885bedfdacfdeacfce74776333 Closes-Bug: #1376013 --- neutron/agent/l3_agent.py | 18 ++++++++++-------- neutron/tests/unit/test_l3_agent.py | 12 ++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py index 728df02351..8f912b9659 100644 --- a/neutron/agent/l3_agent.py +++ b/neutron/agent/l3_agent.py @@ -1600,14 +1600,16 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, rtr_2_fip, fip_2_rtr = ri.rtr_fip_subnet.get_pair() ip_wrapper = ip_lib.IPWrapper(self.root_helper, namespace=ri.ns_name) - int_dev = ip_wrapper.add_veth(rtr_2_fip_name, - fip_2_rtr_name, fip_ns_name) - self.internal_ns_interface_added(str(rtr_2_fip), - rtr_2_fip_name, ri.ns_name) - self.internal_ns_interface_added(str(fip_2_rtr), - fip_2_rtr_name, fip_ns_name) - int_dev[0].link.set_up() - int_dev[1].link.set_up() + if not ip_lib.device_exists(rtr_2_fip_name, self.root_helper, + namespace=ri.ns_name): + int_dev = ip_wrapper.add_veth(rtr_2_fip_name, + fip_2_rtr_name, fip_ns_name) + self.internal_ns_interface_added(str(rtr_2_fip), + rtr_2_fip_name, ri.ns_name) + self.internal_ns_interface_added(str(fip_2_rtr), + fip_2_rtr_name, fip_ns_name) + int_dev[0].link.set_up() + int_dev[1].link.set_up() # add default route for the link local interface device = ip_lib.IPDevice(rtr_2_fip_name, self.root_helper, namespace=ri.ns_name) diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index 73bd841a05..a63ea2dbf2 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -2107,6 +2107,7 @@ vrrp_instance VR_1 { fip_ns_name = agent.get_fip_ns_name(str(fip['floating_network_id'])) with mock.patch.object(l3_agent.LinkLocalAllocator, '_write'): + self.device_exists.return_value = False agent.create_rtr_2_fip_link(ri, fip['floating_network_id']) self.mock_ip.add_veth.assert_called_with(rtr_2_fip_name, fip_2_rtr_name, fip_ns_name) @@ -2116,6 +2117,17 @@ vrrp_instance VR_1 { # TODO(mrsmith): test _create_agent_gateway_port + def test_create_rtr_2_fip_link_already_exists(self): + agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) + router = prepare_router_data() + + ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, + router=router) + self.device_exists.return_value = True + with mock.patch.object(l3_agent.LinkLocalAllocator, '_write'): + agent.create_rtr_2_fip_link(ri, {}) + self.assertFalse(self.mock_ip.add_veth.called) + def test_floating_ip_added_dist(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) router = prepare_router_data()