Send 'security_groups_member_updated' when port changes

With ml2 plugin, when a port's IP or security group changes, it
should send 'security_groups_member_updated' message to other l2
agents which have same security group with this changed port.

Change-Id: I2e7622d2db4c173ac879a95a6e0adf92b858fe82
Closes-bug: #1448022
This commit is contained in:
shihanzhang 2015-04-24 18:28:17 +08:00
parent 66bc9deba8
commit b17ff81ef1
3 changed files with 23 additions and 0 deletions

View File

@ -120,6 +120,17 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin):
original_port[ext_sg.SECURITYGROUPS])
return need_notify
def check_and_notify_security_group_member_changed(
self, context, original_port, updated_port):
sg_change = not utils.compare_elements(
original_port.get(ext_sg.SECURITYGROUPS),
updated_port.get(ext_sg.SECURITYGROUPS))
if sg_change:
self.notify_security_groups_member_updated_bulk(
context, [original_port, updated_port])
elif original_port['fixed_ips'] != updated_port['fixed_ips']:
self.notify_security_groups_member_updated(context, updated_port)
def is_security_group_member_updated(self, context,
original_port, updated_port):
"""Check security group member updated or not.

View File

@ -1157,6 +1157,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
# either undo/retry the operation or delete the resource.
self.mechanism_manager.update_port_postcommit(mech_context)
self.check_and_notify_security_group_member_changed(
context, original_port, updated_port)
need_port_update_notify |= self.is_security_group_member_updated(
context, original_port, updated_port)

View File

@ -402,6 +402,16 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
plugin.update_port_status(ctx, short_id, 'UP')
mock_gbl.assert_called_once_with(mock.ANY, port_id, mock.ANY)
def test_update_port_fixed_ip_changed(self):
ctx = context.get_admin_context()
plugin = manager.NeutronManager.get_plugin()
with self.port() as port, mock.patch.object(
plugin.notifier,
'security_groups_member_updated') as sg_member_update:
port['port']['fixed_ips'][0]['ip_address'] = '10.0.0.3'
plugin.update_port(ctx, port['port']['id'], port)
self.assertTrue(sg_member_update.called)
def test_update_port_mac(self):
self.check_update_port_mac(
host_arg={portbindings.HOST_ID: HOST},