From: ChuckC Date: Mon, 9 Mar 2015 00:51:09 +0000 (-0700) Subject: Prevent updating mac address of bound port X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=89b9e8597816a5ac2f5a48133777c88abb91914e;p=openstack-build%2Fneutron-build.git Prevent updating mac address of bound port Currently, a port's mac address can be updated even if it is bound. This fixes the _check_mac_update_allowed() call to pass just port update attributes rather than the entire payload and fills in missing testing. Change-Id: Iee8492e9b4fcdb07eb438eb6f5958d7addeb3d8f Closes-bug: #1429672 --- diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index aa5620e04..11183555c 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1002,7 +1002,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, if not port_db: raise exc.PortNotFound(port_id=id) mac_address_updated = self._check_mac_update_allowed( - port_db, port, binding) + port_db, attrs, binding) need_port_update_notify |= mac_address_updated original_port = self._make_port_dict(port_db) updated_port = super(Ml2Plugin, self).update_port(context, id, diff --git a/neutron/tests/unit/ml2/test_ml2_plugin.py b/neutron/tests/unit/ml2/test_ml2_plugin.py index bb12b3893..c9ccf773b 100644 --- a/neutron/tests/unit/ml2/test_ml2_plugin.py +++ b/neutron/tests/unit/ml2/test_ml2_plugin.py @@ -460,6 +460,31 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): self.assertIsNone(l3plugin.disassociate_floatingips(ctx, port_id)) +class TestMl2PluginOnly(Ml2PluginV2TestCase): + """For testing methods that don't call drivers""" + + def _test_check_mac_update_allowed(self, vif_type, expect_change=True): + plugin = manager.NeutronManager.get_plugin() + port = {'mac_address': "fake_mac", 'id': "fake_id"} + if expect_change: + new_attrs = {"mac_address": "dummy_mac"} + else: + new_attrs = {"mac_address": port['mac_address']} + binding = mock.Mock() + binding.vif_type = vif_type + mac_changed = plugin._check_mac_update_allowed(port, new_attrs, + binding) + self.assertEqual(expect_change, mac_changed) + + def test_check_mac_update_allowed_if_no_mac_change(self): + self._test_check_mac_update_allowed(portbindings.VIF_TYPE_UNBOUND, + expect_change=False) + + def test_check_mac_update_allowed_unless_bound(self): + with testtools.ExpectedException(exc.PortBound): + self._test_check_mac_update_allowed(portbindings.VIF_TYPE_OVS) + + class TestMl2DvrPortsV2(TestMl2PortsV2): def setUp(self): super(TestMl2DvrPortsV2, self).setUp()