From: Salvatore Orlando Date: Tue, 26 Nov 2013 16:18:17 +0000 (-0800) Subject: Rebind allowed address pairs only if they changed X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=eb23b345876796f4002cab3632bad1c840289d04;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/db/allowedaddresspairs_db.py b/neutron/db/allowedaddresspairs_db.py index d1c35b221..e28576ef3 100644 --- a/neutron/db/allowedaddresspairs_db.py +++ b/neutron/db/allowedaddresspairs_db.py @@ -20,6 +20,7 @@ import sqlalchemy as sa from sqlalchemy import orm 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 model_base from neutron.db import models_v2 @@ -124,3 +125,17 @@ class AllowedAddressPairsMixin(object): """ return (addr_pair.ADDRESS_PAIRS in port['port'] and 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 diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 16307ef9b..646ebf444 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -597,7 +597,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, original_port = super(Ml2Plugin, self).get_port(context, id) updated_port = super(Ml2Plugin, self).update_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._process_create_allowed_address_pairs( context, updated_port, diff --git a/neutron/plugins/nec/nec_plugin.py b/neutron/plugins/nec/nec_plugin.py index 5d38a485f..e8e201508 100644 --- a/neutron/plugins/nec/nec_plugin.py +++ b/neutron/plugins/nec/nec_plugin.py @@ -579,7 +579,7 @@ class NECPluginV2(db_base_plugin_v2.NeutronDbPluginV2, new_port = super(NECPluginV2, self).update_port(context, id, port) portinfo_changed = self._process_portbindings_update( 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._process_create_allowed_address_pairs( context, new_port, diff --git a/neutron/plugins/openvswitch/ovs_neutron_plugin.py b/neutron/plugins/openvswitch/ovs_neutron_plugin.py index 6377c073b..f037707f7 100644 --- a/neutron/plugins/openvswitch/ovs_neutron_plugin.py +++ b/neutron/plugins/openvswitch/ovs_neutron_plugin.py @@ -588,7 +588,7 @@ class OVSNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, context, id) updated_port = super(OVSNeutronPluginV2, self).update_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._process_create_allowed_address_pairs( context, updated_port,