Browse Source

Fix unnecessary security_groups_member_updated notification

notify_sg_on_port_change will cause unnecessary notification to
neutron-l2-agents when port update, for example like port's name
updating will also notify.

notify_sg_on_port_change will only be needed when port's
Security Group update or port IP change.

Change-Id: I5439adf2c4b7dcf832241201fd949f6930e65fdf
Closes-Bug: #1720322
(cherry picked from commit 530d97141a)
changes/47/749447/1
jufeng 3 years ago
committed by LIU Yulong
parent
commit
53de19cc3c
3 changed files with 18 additions and 3 deletions
  1. +6
    -1
      neutron/db/securitygroups_rpc_base.py
  2. +0
    -2
      neutron/plugins/ml2/plugin.py
  3. +12
    -0
      neutron/tests/unit/plugins/ml2/test_plugin.py

+ 6
- 1
neutron/db/securitygroups_rpc_base.py View File

@@ -45,7 +45,12 @@ class SecurityGroupServerNotifierRpcMixin(sg_db.SecurityGroupDbMixin):
def notify_sg_on_port_change(self, resource, event, trigger, context,
port, *args, **kwargs):
"""Trigger notification to other SG members on port changes."""
self.notify_security_groups_member_updated(context, port)
if event == events.AFTER_UPDATE:
original_port = kwargs.get('original_port')
self.check_and_notify_security_group_member_changed(
context, original_port, port)
else:
self.notify_security_groups_member_updated(context, port)

def create_security_group_rule(self, context, security_group_rule):
rule = super(SecurityGroupServerNotifierRpcMixin,


+ 0
- 2
neutron/plugins/ml2/plugin.py View File

@@ -1487,8 +1487,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
LOG.error("mechanism_manager.update_port_postcommit "
"failed for port %s", id)

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)



+ 12
- 0
neutron/tests/unit/plugins/ml2/test_plugin.py View File

@@ -1027,6 +1027,18 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
plugin.update_port(ctx, port['port']['id'], port)
self.assertTrue(sg_member_update.called)

def test_update_port_name_do_not_notify_sg(self):
ctx = context.get_admin_context()
plugin = directory.get_plugin()
port_name = "port_name"
with self.port(name=port_name) as port,\
mock.patch.object(
plugin.notifier,
'security_groups_member_updated') as sg_member_update:
port['port']['name'] = 'new_port_name'
plugin.update_port(ctx, port['port']['id'], port)
self.assertFalse(sg_member_update.called)

def test_update_port_status_with_network(self):
registry.clear() # don't care about callback behavior
ctx = context.get_admin_context()


Loading…
Cancel
Save