Merge "Openvswitch update_port should return updated port info"
This commit is contained in:
commit
2da9302ac1
@ -17,7 +17,6 @@ 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
|
||||||
@ -126,13 +125,36 @@ class AllowedAddressPairsMixin(object):
|
|||||||
def is_address_pairs_attribute_updated(self, port, update_attrs):
|
def is_address_pairs_attribute_updated(self, port, update_attrs):
|
||||||
"""Check if the address pairs attribute is being updated.
|
"""Check if the address pairs attribute is being updated.
|
||||||
|
|
||||||
This method returns a flag which indicates whether there is an update
|
Returns True if there is an update. This can be used to decide
|
||||||
and therefore a port update notification should be sent to agents or
|
if a port update notification should be sent to agents or third
|
||||||
third party controllers.
|
party controllers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
new_pairs = update_attrs.get(addr_pair.ADDRESS_PAIRS)
|
new_pairs = update_attrs.get(addr_pair.ADDRESS_PAIRS)
|
||||||
if new_pairs and not utils.compare_elements(
|
if new_pairs is None:
|
||||||
port.get(addr_pair.ADDRESS_PAIRS), new_pairs):
|
return False
|
||||||
return True
|
old_pairs = port.get(addr_pair.ADDRESS_PAIRS)
|
||||||
|
|
||||||
# Missing or unchanged address pairs in attributes mean no update
|
# 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
|
return False
|
||||||
|
@ -587,12 +587,11 @@ 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 self.is_address_pairs_attribute_updated(original_port, port):
|
if addr_pair.ADDRESS_PAIRS in port['port']:
|
||||||
self._delete_allowed_address_pairs(context, id)
|
need_port_update_notify |= (
|
||||||
self._process_create_allowed_address_pairs(
|
self.update_address_pairs_on_port(context, id, port,
|
||||||
context, updated_port,
|
original_port,
|
||||||
port['port'][addr_pair.ADDRESS_PAIRS])
|
updated_port))
|
||||||
need_port_update_notify = True
|
|
||||||
elif changed_fixed_ips:
|
elif changed_fixed_ips:
|
||||||
self._check_fixed_ips_and_address_pairs_no_overlap(
|
self._check_fixed_ips_and_address_pairs_no_overlap(
|
||||||
context, updated_port)
|
context, updated_port)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
from neutron.extensions import portbindings
|
from neutron.extensions import portbindings
|
||||||
from neutron.tests.unit import _test_extension_portbindings as test_bindings
|
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_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
|
from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc
|
||||||
|
|
||||||
|
|
||||||
@ -73,3 +74,8 @@ class TestOpenvswitchPortBindingHost(
|
|||||||
OpenvswitchPluginV2TestCase,
|
OpenvswitchPluginV2TestCase,
|
||||||
test_bindings.PortBindingsHostTestCaseMixin):
|
test_bindings.PortBindingsHostTestCaseMixin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestOpenvswitchAllowedAddressPairs(OpenvswitchPluginV2TestCase,
|
||||||
|
test_pair.TestAllowedAddressPairs):
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user