]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Send 'security_groups_member_updated' when port changes
authorshihanzhang <shihanzhang@huawei.com>
Fri, 24 Apr 2015 10:28:17 +0000 (18:28 +0800)
committershihanzhang <shihanzhang@huawei.com>
Mon, 8 Jun 2015 01:58:36 +0000 (01:58 +0000)
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

neutron/db/securitygroups_rpc_base.py
neutron/plugins/ml2/plugin.py
neutron/tests/unit/plugins/ml2/test_plugin.py

index af0b8a8e10949d24c03489261842d5bce124f262..c399598051225c2d15900605e3ada999a7525cac 100644 (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.
index 0947986859502e9e0db0a3590a395c422ae0f0e2..df831fdc81f52ba33db29186eab00cacfc2a72c9 100644 (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)
 
index 73c4a1134dadde79ab45d495fa087e2728648e43..50dfd31964161ce4fcc4ec86ed1dac65f42bdc33 100644 (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},