Merge "Stop binding attempts when network has no segments"

This commit is contained in:
Jenkins 2017-06-19 21:42:57 +00:00 committed by Gerrit Code Review
commit e54b2e4a3e
2 changed files with 19 additions and 0 deletions

View File

@ -369,6 +369,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
@db_api.retry_db_errors
def _bind_port_if_needed(self, context, allow_notify=False,
need_notify=False):
if not context.network.network_segments:
LOG.debug("Network %s has no segments, skipping binding",
context.network.current['id'])
return context
for count in range(1, MAX_BIND_TRIES + 1):
if count > 1:
# yield for binding retries so that we give other threads a

View File

@ -1631,6 +1631,21 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
self.assertEqual(expected_try_again, try_again)
self.assertEqual(expected_bd_mock_called, bd_mock.called)
def test__bind_port_if_needed_early_exit_on_no_segments(self):
with self.network() as n:
ctx = context.get_admin_context()
seg_plugin = segments_plugin.Plugin.get_instance()
seg = seg_plugin.get_segments(ctx)[0]
seg_plugin.delete_segment(ctx, seg['id'])
plugin = directory.get_plugin()
mech_context = driver_context.PortContext(
plugin, ctx, None,
plugin.get_network(self.context, n['network']['id']),
None, None)
with mock.patch.object(plugin, '_attempt_binding') as ab:
plugin._bind_port_if_needed(mech_context)
self.assertFalse(ab.called)
def test__attempt_binding_retries(self):
# Simulate cases of both successful and failed binding states for
# vif_type unbound