Add the rebinding chance in _bind_port_if_needed
Make function _bind_port_if_needed to bind at least one time when the port's binding status passed in is already in binding_failed. Change-Id: I823ff5ca66833cdca459f13ab28f5075ae03ded3 Closes-Bug: #1399249
This commit is contained in:
parent
33b8355444
commit
67e45d324a
@ -260,7 +260,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||||||
# First, determine whether it is necessary and possible to
|
# First, determine whether it is necessary and possible to
|
||||||
# bind the port.
|
# bind the port.
|
||||||
binding = context._binding
|
binding = context._binding
|
||||||
if (binding.vif_type != portbindings.VIF_TYPE_UNBOUND
|
if (binding.vif_type not in [portbindings.VIF_TYPE_UNBOUND,
|
||||||
|
portbindings.VIF_TYPE_BINDING_FAILED]
|
||||||
or not binding.host):
|
or not binding.host):
|
||||||
# We either don't need to bind the port, or can't, so
|
# We either don't need to bind the port, or can't, so
|
||||||
# notify if needed and return.
|
# notify if needed and return.
|
||||||
@ -298,12 +299,15 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||||||
LOG.debug("Port %s has been deleted concurrently",
|
LOG.debug("Port %s has been deleted concurrently",
|
||||||
port_id)
|
port_id)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
context = new_context
|
||||||
|
|
||||||
|
if (context._binding.vif_type ==
|
||||||
|
portbindings.VIF_TYPE_BINDING_FAILED):
|
||||||
|
return context
|
||||||
# Need to notify if we succeed and our results were
|
# Need to notify if we succeed and our results were
|
||||||
# committed.
|
# committed.
|
||||||
if did_commit and (new_context._binding.vif_type !=
|
need_notify |= did_commit
|
||||||
portbindings.VIF_TYPE_BINDING_FAILED):
|
|
||||||
need_notify = True
|
|
||||||
context = new_context
|
|
||||||
|
|
||||||
def _bind_port(self, orig_context):
|
def _bind_port(self, orig_context):
|
||||||
# Construct a new PortContext from the one from the previous
|
# Construct a new PortContext from the one from the previous
|
||||||
|
@ -457,6 +457,54 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
|
|||||||
# should have returned before calling _make_port_dict
|
# should have returned before calling _make_port_dict
|
||||||
self.assertFalse(mpd_mock.mock_calls)
|
self.assertFalse(mpd_mock.mock_calls)
|
||||||
|
|
||||||
|
def test_bind_port_if_needed(self):
|
||||||
|
# create a port and set its vif_type to binding_failed
|
||||||
|
with self.port() as port:
|
||||||
|
plugin = manager.NeutronManager.get_plugin()
|
||||||
|
binding = ml2_db.get_locked_port_and_binding(self.context.session,
|
||||||
|
port['port']['id'])[1]
|
||||||
|
binding['host'] = 'test'
|
||||||
|
|
||||||
|
binding['vif_type'] = portbindings.VIF_TYPE_BINDING_FAILED
|
||||||
|
mech_context = driver_context.PortContext(
|
||||||
|
plugin, self.context, port['port'],
|
||||||
|
plugin.get_network(self.context, port['port']['network_id']),
|
||||||
|
binding)
|
||||||
|
|
||||||
|
# test when _commit_port_binding return binding_failed
|
||||||
|
self._test_bind_port_if_needed(plugin, mech_context, False)
|
||||||
|
# test when _commit_port_binding NOT return binding_failed
|
||||||
|
self._test_bind_port_if_needed(plugin, mech_context, True)
|
||||||
|
|
||||||
|
def _test_bind_port_if_needed(self, plugin, mech_context, commit_fail):
|
||||||
|
# mock _commit_port_binding
|
||||||
|
commit_context = mock.MagicMock()
|
||||||
|
if commit_fail:
|
||||||
|
commit_context._binding.vif_type = (
|
||||||
|
portbindings.VIF_TYPE_BINDING_FAILED)
|
||||||
|
else:
|
||||||
|
commit_context._binding.vif_type = portbindings.VIF_TYPE_OVS
|
||||||
|
|
||||||
|
with contextlib.nested(
|
||||||
|
mock.patch('neutron.plugins.ml2.plugin.'
|
||||||
|
'db.get_locked_port_and_binding',
|
||||||
|
return_value=(None, None)),
|
||||||
|
mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin._bind_port'),
|
||||||
|
mock.patch('neutron.plugins.ml2.plugin.'
|
||||||
|
'Ml2Plugin._commit_port_binding',
|
||||||
|
return_value=(commit_context, False))
|
||||||
|
) as (glpab_mock, bd_mock, commit_mock):
|
||||||
|
bound_context = plugin._bind_port_if_needed(mech_context)
|
||||||
|
# check _bind_port be called
|
||||||
|
self.assertTrue(bd_mock.called)
|
||||||
|
|
||||||
|
if commit_fail:
|
||||||
|
self.assertEqual(portbindings.VIF_TYPE_BINDING_FAILED,
|
||||||
|
bound_context._binding.vif_type)
|
||||||
|
else:
|
||||||
|
self.assertEqual(portbindings.VIF_TYPE_OVS,
|
||||||
|
bound_context._binding.vif_type)
|
||||||
|
|
||||||
def test_port_binding_profile_not_changed(self):
|
def test_port_binding_profile_not_changed(self):
|
||||||
profile = {'e': 5}
|
profile = {'e': 5}
|
||||||
profile_arg = {portbindings.PROFILE: profile}
|
profile_arg = {portbindings.PROFILE: profile}
|
||||||
|
Loading…
Reference in New Issue
Block a user