From f39c8965d9679971afa3db101c09ca2740b39a91 Mon Sep 17 00:00:00 2001 From: Sylvain Afchain Date: Thu, 17 Oct 2013 02:16:15 +0200 Subject: [PATCH] Fix lb doesn't remove vxlan int. if no int. map LinuxBridge agent doesn't remove vxlan interfaces if interface_mappings is not set. Fixes bug: 1240742 Change-Id: I163f1ac8cbd46b8d8836152e2be8cb7608a8ca22 --- .../agent/linuxbridge_neutron_agent.py | 7 +++-- .../unit/linuxbridge/test_lb_neutron_agent.py | 28 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index d7159a37b51..95ba0c46077 100755 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -418,6 +418,11 @@ class LinuxBridgeManager: interfaces_on_bridge = self.get_interfaces_on_bridge(bridge_name) for interface in interfaces_on_bridge: self.remove_interface(bridge_name, interface) + + if interface.startswith(VXLAN_INTERFACE_PREFIX): + self.delete_vxlan(interface) + continue + for physical_interface in self.interface_mappings.itervalues(): if physical_interface == interface: # This is a flat network => return IP's from bridge to @@ -428,8 +433,6 @@ class LinuxBridgeManager: ips, gateway) elif interface.startswith(physical_interface): self.delete_vlan(interface) - elif interface.startswith(VXLAN_INTERFACE_PREFIX): - self.delete_vxlan(interface) LOG.debug(_("Deleting bridge %s"), bridge_name) if utils.execute(['ip', 'link', 'set', bridge_name, 'down'], diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index f115733695d..9dd652cd3a2 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -506,20 +506,44 @@ class TestLinuxBridgeManager(base.BaseTestCase): mock.patch.object(self.lbm, "get_interface_details"), mock.patch.object(self.lbm, "update_interface_ip_details"), mock.patch.object(self.lbm, "delete_vlan"), + mock.patch.object(self.lbm, "delete_vxlan"), mock.patch.object(utils, "execute") ) as (de_fn, getif_fn, remif_fn, if_det_fn, - updif_fn, del_vlan, exec_fn): + updif_fn, del_vlan, del_vxlan, exec_fn): de_fn.return_value = False self.lbm.delete_vlan_bridge("br0") self.assertFalse(getif_fn.called) de_fn.return_value = True - getif_fn.return_value = ["eth0", "eth1.1", "eth1"] + getif_fn.return_value = ["eth0", "eth1.1", "eth1", "vxlan-1002"] if_det_fn.return_value = ("ips", "gateway") exec_fn.return_value = False self.lbm.delete_vlan_bridge("br0") updif_fn.assert_called_with("eth1", "br0", "ips", "gateway") del_vlan.assert_called_with("eth1.1") + del_vxlan.assert_called_with("vxlan-1002") + + def test_delete_vxlan_bridge_no_int_mappings(self): + interface_mappings = {} + lbm = linuxbridge_neutron_agent.LinuxBridgeManager( + interface_mappings, self.root_helper) + + with contextlib.nested( + mock.patch.object(lbm, "device_exists"), + mock.patch.object(lbm, "get_interfaces_on_bridge"), + mock.patch.object(lbm, "remove_interface"), + mock.patch.object(lbm, "delete_vxlan"), + mock.patch.object(utils, "execute") + ) as (de_fn, getif_fn, remif_fn, del_vxlan, exec_fn): + de_fn.return_value = False + lbm.delete_vlan_bridge("br0") + self.assertFalse(getif_fn.called) + + de_fn.return_value = True + getif_fn.return_value = ["vxlan-1002"] + exec_fn.return_value = False + lbm.delete_vlan_bridge("br0") + del_vxlan.assert_called_with("vxlan-1002") def test_remove_empty_bridges(self): self.lbm.network_map = {'net1': mock.Mock(), 'net2': mock.Mock()}