Ignore exception when deleting linux bridge if doesn't exist

Linux bridge is not handling RuntimeError exception when it is trying
to delete network's bridge, which is deleted in parallel by nova.
Fullstack test has similar scenario, it creates network's bridge for
agent and deletes the bridge after the test, like nova.

Linux bridge agent has to ignore RuntimeError exception if the bridge
doesn't exist.

Closes-bug: #1561040
Change-Id: I428384fd42181ff6bc33f29369a7ff5ec163b532
This commit is contained in:
venkata anil 2016-03-23 15:24:01 +00:00
parent 3d6cb95f19
commit 16b2ffdfd8
2 changed files with 31 additions and 7 deletions

View File

@ -508,13 +508,23 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase):
elif interface not in physical_interfaces:
self.delete_interface(interface)
LOG.debug("Deleting bridge %s", bridge_name)
if bridge_device.link.set_down():
return
if bridge_device.delbr():
return
LOG.debug("Done deleting bridge %s", bridge_name)
try:
LOG.debug("Deleting bridge %s", bridge_name)
if bridge_device.link.set_down():
return
if bridge_device.delbr():
return
LOG.debug("Done deleting bridge %s", bridge_name)
except RuntimeError:
with excutils.save_and_reraise_exception() as ctxt:
if not bridge_device.exists():
# the exception was likely a side effect of the bridge
# being removed by nova during handling,
# so we just return
ctxt.reraise = False
LOG.debug("Cannot delete bridge %s; it does not exist",
bridge_name)
return
else:
LOG.debug("Cannot delete bridge %s; it does not exist",
bridge_name)

View File

@ -597,6 +597,20 @@ class TestLinuxBridgeManager(base.BaseTestCase):
updif_fn.assert_called_with("eth1", "br0", "ips", "gateway")
delif_fn.assert_called_with("vxlan-1002")
def test_delete_bridge_not_exist(self):
self.lbm.interface_mappings.update({})
bridge_device = mock.Mock()
with mock.patch.object(bridge_lib, "BridgeDevice",
return_value=bridge_device):
bridge_device.exists.side_effect = [True, False]
bridge_device.get_interfaces.return_value = []
bridge_device.link.set_down.side_effect = RuntimeError
self.lbm.delete_bridge("br0")
self.assertEqual(2, bridge_device.exists.call_count)
bridge_device.exists.side_effect = [True, True]
self.assertRaises(RuntimeError, self.lbm.delete_bridge, "br0")
def test_delete_bridge_with_ip(self):
bridge_device = mock.Mock()
with mock.patch.object(ip_lib, "device_exists") as de_fn,\