]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix ML2 Plugin binding:profile update
authorIrena Berezovsky <irenab@mellanox.com>
Tue, 22 Jul 2014 15:13:00 +0000 (18:13 +0300)
committerIrena Berezovsky <irenab@mellanox.com>
Sat, 26 Jul 2014 10:39:41 +0000 (13:39 +0300)
The current fix changes the logic for binding:profile
update. The binding:profile should be considered as changed
once it is present in the port attributes and differs from
existing binding:profile. The specified binding:profile with
None value should be treated as request to clear binding:profile.

Change-Id: Ibda9a1beec697fbee5be0ee379349035c3626509
Closes-Bug: 1338202

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

index bae54b9fc47b1e3093e5a4f2be7c539f4e89cff3..5f97f35c6ac9823e729e21b3319cff7524ea171a 100644 (file)
@@ -229,10 +229,13 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
             binding.vnic_type = vnic_type
             changes = True
 
-        # CLI can't send {}, so treat None as {}.
-        profile = attrs and attrs.get(portbindings.PROFILE) or {}
-        if (profile is not attributes.ATTR_NOT_SPECIFIED and
-            self._get_profile(binding) != profile):
+        # treat None as clear of profile.
+        profile = None
+        if attrs and portbindings.PROFILE in attrs:
+            profile = attrs.get(portbindings.PROFILE) or {}
+
+        if profile not in (None, attributes.ATTR_NOT_SPECIFIED,
+                           self._get_profile(binding)):
             binding.profile = jsonutils.dumps(profile)
             if len(binding.profile) > models.BINDING_PROFILE_LEN:
                 msg = _("binding:profile value too large")
index 0ab7349e8c2509fa2615524b9493cb143b837b7f..45cab5426d5c0b3a3dd610305a82d2cdf9f4e676 100644 (file)
@@ -250,6 +250,20 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
             # should have returned before calling _make_port_dict
             self.assertFalse(mpd_mock.mock_calls)
 
+    def test_port_binding_profile_not_changed(self):
+        profile = {'e': 5}
+        profile_arg = {portbindings.PROFILE: profile}
+        with self.port(arg_list=(portbindings.PROFILE,),
+                       **profile_arg) as port:
+            self._check_port_binding_profile(port['port'], profile)
+            port_id = port['port']['id']
+            state_arg = {'admin_state_up': True}
+            port = self._update('ports', port_id,
+                                {'port': state_arg})['port']
+            self._check_port_binding_profile(port, profile)
+            port = self._show('ports', port_id)['port']
+            self._check_port_binding_profile(port, profile)
+
 
 class TestMl2PortBindingNoSG(TestMl2PortBinding):
     HAS_PORT_FILTER = False