From 02b7d3989615c848153d0a363f52481a917128fb Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 26 Nov 2013 08:18:17 -0800 Subject: [PATCH] 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 --- neutron/db/allowedaddresspairs_db.py | 15 +++++++++++++++ neutron/plugins/ml2/plugin.py | 2 +- neutron/plugins/nec/nec_plugin.py | 2 +- neutron/plugins/openvswitch/ovs_neutron_plugin.py | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/neutron/db/allowedaddresspairs_db.py b/neutron/db/allowedaddresspairs_db.py index d1c35b221a..e28576ef3e 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 16307ef9b9..646ebf444c 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 5d38a485f3..e8e2015089 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 6377c073ba..f037707f7e 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,