Merge "Have LB agent use ip_lib.ensure_device_is_ready()"
This commit is contained in:
commit
b6a984003d
@ -420,21 +420,10 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase):
|
||||
|
||||
return updated
|
||||
|
||||
def _bridge_exists_and_ensure_up(self, bridge_name):
|
||||
"""Check if the bridge exists and make sure it is up."""
|
||||
br = ip_lib.IPDevice(bridge_name)
|
||||
br.set_log_fail_as_error(False)
|
||||
try:
|
||||
# If the device doesn't exist this will throw a RuntimeError
|
||||
br.link.set_up()
|
||||
except RuntimeError:
|
||||
return False
|
||||
return True
|
||||
|
||||
def ensure_bridge(self, bridge_name, interface=None,
|
||||
update_interface=True):
|
||||
"""Create a bridge unless it already exists."""
|
||||
# _bridge_exists_and_ensure_up instead of device_exists is used here
|
||||
# ensure_device_is_ready instead of device_exists is used here
|
||||
# because there are cases where the bridge exists but it's not UP,
|
||||
# for example:
|
||||
# 1) A greenthread was executing this function and had not yet executed
|
||||
@ -442,7 +431,7 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase):
|
||||
# thread running the same function
|
||||
# 2) The Nova VIF driver was running concurrently and had just created
|
||||
# the bridge, but had not yet put it UP
|
||||
if not self._bridge_exists_and_ensure_up(bridge_name):
|
||||
if not ip_lib.ensure_device_is_ready(bridge_name):
|
||||
LOG.debug("Starting bridge %(bridge_name)s for subinterface "
|
||||
"%(interface)s",
|
||||
{'bridge_name': bridge_name, 'interface': interface})
|
||||
|
@ -495,21 +495,11 @@ class TestLinuxBridgeManager(base.BaseTestCase):
|
||||
self.assertTrue(addgw_fn.called)
|
||||
self.assertTrue(delgw_fn.called)
|
||||
|
||||
def test_bridge_exists_and_ensure_up(self):
|
||||
ip_lib_mock = mock.Mock()
|
||||
with mock.patch.object(ip_lib, 'IPDevice', return_value=ip_lib_mock):
|
||||
# device exists
|
||||
self.assertTrue(self.lbm._bridge_exists_and_ensure_up("br0"))
|
||||
self.assertTrue(ip_lib_mock.link.set_up.called)
|
||||
# device doesn't exists
|
||||
ip_lib_mock.link.set_up.side_effect = RuntimeError
|
||||
self.assertFalse(self.lbm._bridge_exists_and_ensure_up("br0"))
|
||||
|
||||
def test_ensure_bridge(self):
|
||||
bridge_device = mock.Mock()
|
||||
bridge_device_old = mock.Mock()
|
||||
with mock.patch.object(self.lbm,
|
||||
'_bridge_exists_and_ensure_up') as de_fn,\
|
||||
with mock.patch.object(ip_lib,
|
||||
'ensure_device_is_ready') as de_fn,\
|
||||
mock.patch.object(bridge_lib, "BridgeDevice",
|
||||
return_value=bridge_device) as br_fn,\
|
||||
mock.patch.object(self.lbm,
|
||||
|
Loading…
x
Reference in New Issue
Block a user