From: shihanzhang Date: Fri, 24 Apr 2015 10:28:17 +0000 (+0800) Subject: Send 'security_groups_member_updated' when port changes X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b17ff81ef1b18395c0b0671a487f68201d739f43;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/db/securitygroups_rpc_base.py b/neutron/db/securitygroups_rpc_base.py index af0b8a8e1..c39959805 100644 --- a/neutron/db/securitygroups_rpc_base.py +++ b/neutron/db/securitygroups_rpc_base.py @@ -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. diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 094798685..df831fdc8 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -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) diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 73c4a1134..50dfd3196 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -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},