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
This commit is contained in:
jufeng 2017-09-29 16:38:24 +08:00
parent e6b4fe995d
commit 530d97141a
3 changed files with 18 additions and 3 deletions

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,

View File

@ -1406,8 +1406,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)

View File

@ -904,6 +904,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()