summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 21:42:57 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 21:42:57 +0000
commite54b2e4a3e8f4df8425232696177be564cde6054 (patch)
tree8c892c37032dcf2d9a33b6c62cdfd3bcf7ee392a
parentc9a9b5d41a7418e6a8b6df9061946245327d3bc3 (diff)
parent781b8f41498521041f7c9d4b4e0c0fa438736fc4 (diff)
Merge "Stop binding attempts when network has no segments"
-rw-r--r--neutron/plugins/ml2/plugin.py4
-rw-r--r--neutron/tests/unit/plugins/ml2/test_plugin.py15
2 files changed, 19 insertions, 0 deletions
diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py
index 8c45f4e..a112957 100644
--- a/neutron/plugins/ml2/plugin.py
+++ b/neutron/plugins/ml2/plugin.py
@@ -369,6 +369,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
369 @db_api.retry_db_errors 369 @db_api.retry_db_errors
370 def _bind_port_if_needed(self, context, allow_notify=False, 370 def _bind_port_if_needed(self, context, allow_notify=False,
371 need_notify=False): 371 need_notify=False):
372 if not context.network.network_segments:
373 LOG.debug("Network %s has no segments, skipping binding",
374 context.network.current['id'])
375 return context
372 for count in range(1, MAX_BIND_TRIES + 1): 376 for count in range(1, MAX_BIND_TRIES + 1):
373 if count > 1: 377 if count > 1:
374 # yield for binding retries so that we give other threads a 378 # yield for binding retries so that we give other threads a
diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py
index 796d3d7..3b4b7dd 100644
--- a/neutron/tests/unit/plugins/ml2/test_plugin.py
+++ b/neutron/tests/unit/plugins/ml2/test_plugin.py
@@ -1631,6 +1631,21 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
1631 self.assertEqual(expected_try_again, try_again) 1631 self.assertEqual(expected_try_again, try_again)
1632 self.assertEqual(expected_bd_mock_called, bd_mock.called) 1632 self.assertEqual(expected_bd_mock_called, bd_mock.called)
1633 1633
1634 def test__bind_port_if_needed_early_exit_on_no_segments(self):
1635 with self.network() as n:
1636 ctx = context.get_admin_context()
1637 seg_plugin = segments_plugin.Plugin.get_instance()
1638 seg = seg_plugin.get_segments(ctx)[0]
1639 seg_plugin.delete_segment(ctx, seg['id'])
1640 plugin = directory.get_plugin()
1641 mech_context = driver_context.PortContext(
1642 plugin, ctx, None,
1643 plugin.get_network(self.context, n['network']['id']),
1644 None, None)
1645 with mock.patch.object(plugin, '_attempt_binding') as ab:
1646 plugin._bind_port_if_needed(mech_context)
1647 self.assertFalse(ab.called)
1648
1634 def test__attempt_binding_retries(self): 1649 def test__attempt_binding_retries(self):
1635 # Simulate cases of both successful and failed binding states for 1650 # Simulate cases of both successful and failed binding states for
1636 # vif_type unbound 1651 # vif_type unbound