Rebind allowed address pairs only if they changed

This patch ensures allowed address pairs bindings are refreshed
only when they actually change.
This will also avoid sending a notification to the agent if no
change actually occured.

Closes-Bug: #1255145
Partial blueprint neutron-tempest-parallel

Change-Id: Iac2502586a0d215a29194590c16c2e1a064f943b
This commit is contained in:
Salvatore Orlando 2013-11-26 08:18:17 -08:00
parent 1811ea2759
commit 02b7d39896
4 changed files with 18 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
from neutron.common import utils
from neutron.db import db_base_plugin_v2 from neutron.db import db_base_plugin_v2
from neutron.db import model_base from neutron.db import model_base
from neutron.db import models_v2 from neutron.db import models_v2
@ -124,3 +125,17 @@ class AllowedAddressPairsMixin(object):
""" """
return (addr_pair.ADDRESS_PAIRS in port['port'] and return (addr_pair.ADDRESS_PAIRS in port['port'] and
not self._has_address_pairs(port)) not self._has_address_pairs(port))
def is_address_pairs_attribute_updated(self, port, update_attrs):
"""Check if the address pairs attribute is being updated.
This method returns a flag which indicates whether there is an update
and therefore a port update notification should be sent to agents or
third party controllers.
"""
new_pairs = update_attrs.get(addr_pair.ADDRESS_PAIRS)
if new_pairs and not utils.compare_elements(
port.get(addr_pair.ADDRESS_PAIRS), new_pairs):
return True
# Missing or unchanged address pairs in attributes mean no update
return False

View File

@ -597,7 +597,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
original_port = super(Ml2Plugin, self).get_port(context, id) original_port = super(Ml2Plugin, self).get_port(context, id)
updated_port = super(Ml2Plugin, self).update_port(context, id, updated_port = super(Ml2Plugin, self).update_port(context, id,
port) port)
if addr_pair.ADDRESS_PAIRS in port['port']: if self.is_address_pairs_attribute_updated(original_port, port):
self._delete_allowed_address_pairs(context, id) self._delete_allowed_address_pairs(context, id)
self._process_create_allowed_address_pairs( self._process_create_allowed_address_pairs(
context, updated_port, context, updated_port,

View File

@ -579,7 +579,7 @@ class NECPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
new_port = super(NECPluginV2, self).update_port(context, id, port) new_port = super(NECPluginV2, self).update_port(context, id, port)
portinfo_changed = self._process_portbindings_update( portinfo_changed = self._process_portbindings_update(
context, port['port'], new_port) context, port['port'], new_port)
if addr_pair.ADDRESS_PAIRS in port['port']: if self.is_address_pairs_attribute_updated(old_port, port):
self._delete_allowed_address_pairs(context, id) self._delete_allowed_address_pairs(context, id)
self._process_create_allowed_address_pairs( self._process_create_allowed_address_pairs(
context, new_port, context, new_port,

View File

@ -588,7 +588,7 @@ class OVSNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
context, id) context, id)
updated_port = super(OVSNeutronPluginV2, self).update_port( updated_port = super(OVSNeutronPluginV2, self).update_port(
context, id, port) context, id, port)
if addr_pair.ADDRESS_PAIRS in port['port']: if self.is_address_pairs_attribute_updated(original_port, port):
self._delete_allowed_address_pairs(context, id) self._delete_allowed_address_pairs(context, id)
self._process_create_allowed_address_pairs( self._process_create_allowed_address_pairs(
context, updated_port, context, updated_port,