]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Rebind allowed address pairs only if they changed
authorSalvatore Orlando <salv.orlando@gmail.com>
Tue, 26 Nov 2013 16:18:17 +0000 (08:18 -0800)
committerSalvatore Orlando <salv.orlando@gmail.com>
Tue, 26 Nov 2013 16:25:49 +0000 (08:25 -0800)
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
neutron/plugins/ml2/plugin.py
neutron/plugins/nec/nec_plugin.py
neutron/plugins/openvswitch/ovs_neutron_plugin.py

index d1c35b221ab41f07baebeb935b31cf068125f796..e28576ef3e25b3dbe0702f47942efba0fe666a67 100644 (file)
@@ -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
index 16307ef9b9f6fd459f2a8f412565568ce18a1699..646ebf444c560c1ee079f28b19ec289c32df15f3 100644 (file)
@@ -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,
index 5d38a485f39db8ae66a629fc252d2c410405529a..e8e20150890e25d0234a9eac23bbece9beda8b1b 100644 (file)
@@ -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,
index 6377c073ba5fd8b180bc3020c38e078f6c3f9b75..f037707f7e8572889d4eb4cb02800ea6b9f4a64a 100644 (file)
@@ -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,