Fix ML2 Plugin binding:profile update

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
This commit is contained in:
Irena Berezovsky 2014-07-22 18:13:00 +03:00
parent 505042d355
commit cbaa3fe07b
2 changed files with 21 additions and 4 deletions

View 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")

View 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