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
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.
+ Returns True if there is an update. This can be used to decide
+ if 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
+ if new_pairs is None:
+ return False
+ old_pairs = port.get(addr_pair.ADDRESS_PAIRS)
+
# Missing or unchanged address pairs in attributes mean no update
+ return new_pairs != old_pairs
+
+ def update_address_pairs_on_port(self, context, port_id, port,
+ original_port, updated_port):
+ """Update allowed address pairs on port.
+
+ Returns True if an update notification is required. Notification
+ is not done here because other changes on the port may need
+ notification. This method is expected to be called within
+ a transaction.
+ """
+ new_pairs = port['port'].get(addr_pair.ADDRESS_PAIRS)
+
+ if self.is_address_pairs_attribute_updated(original_port,
+ port['port']):
+ updated_port[addr_pair.ADDRESS_PAIRS] = new_pairs
+ self._delete_allowed_address_pairs(context, port_id)
+ self._process_create_allowed_address_pairs(
+ context, updated_port, new_pairs)
+ return True
+
return False
context, id)
updated_port = super(OVSNeutronPluginV2, self).update_port(
context, id, 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,
- port['port'][addr_pair.ADDRESS_PAIRS])
- need_port_update_notify = True
+ if addr_pair.ADDRESS_PAIRS in port['port']:
+ need_port_update_notify |= (
+ self.update_address_pairs_on_port(context, id, port,
+ original_port,
+ updated_port))
elif changed_fixed_ips:
self._check_fixed_ips_and_address_pairs_no_overlap(
context, updated_port)
from neutron.extensions import portbindings
from neutron.tests.unit import _test_extension_portbindings as test_bindings
from neutron.tests.unit import test_db_plugin as test_plugin
+from neutron.tests.unit import test_extension_allowedaddresspairs as test_pair
from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc
OpenvswitchPluginV2TestCase,
test_bindings.PortBindingsHostTestCaseMixin):
pass
+
+
+class TestOpenvswitchAllowedAddressPairs(OpenvswitchPluginV2TestCase,
+ test_pair.TestAllowedAddressPairs):
+ pass