Merge "Ignore exception when deleting linux bridge if doesn't exist"
This commit is contained in:
commit
097bb4eafa
@ -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)
|
||||
|
@ -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,\
|
||||
|
Loading…
x
Reference in New Issue
Block a user