]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Prevent updating mac address of bound port
authorChuckC <ccarlino@hp.com>
Mon, 9 Mar 2015 00:51:09 +0000 (17:51 -0700)
committerChuckC <ccarlino@hp.com>
Sat, 14 Mar 2015 14:17:00 +0000 (07:17 -0700)
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

neutron/plugins/ml2/plugin.py
neutron/tests/unit/ml2/test_ml2_plugin.py

index aa5620e0421b9f3768c84c174e475041edea204a..11183555cb813ac37f5f9fe7eb7fe9a05e5191c6 100644 (file)
@@ -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,
index bb12b3893dd3f7cbbf773b54b92ee7e25ffa67a3..c9ccf773b07c29444aaa0f6360bb0548784e488b 100644 (file)
@@ -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()