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
)
This commit is contained in:
parent
27c53ebc97
commit
53de19cc3c
|
@ -45,7 +45,12 @@ class SecurityGroupServerNotifierRpcMixin(sg_db.SecurityGroupDbMixin):
|
||||||
def notify_sg_on_port_change(self, resource, event, trigger, context,
|
def notify_sg_on_port_change(self, resource, event, trigger, context,
|
||||||
port, *args, **kwargs):
|
port, *args, **kwargs):
|
||||||
"""Trigger notification to other SG members on port changes."""
|
"""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):
|
def create_security_group_rule(self, context, security_group_rule):
|
||||||
rule = super(SecurityGroupServerNotifierRpcMixin,
|
rule = super(SecurityGroupServerNotifierRpcMixin,
|
||||||
|
|
|
@ -1487,8 +1487,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||||
LOG.error("mechanism_manager.update_port_postcommit "
|
LOG.error("mechanism_manager.update_port_postcommit "
|
||||||
"failed for port %s", id)
|
"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(
|
need_port_update_notify |= self.is_security_group_member_updated(
|
||||||
context, original_port, updated_port)
|
context, original_port, updated_port)
|
||||||
|
|
||||||
|
|
|
@ -1027,6 +1027,18 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
|
||||||
plugin.update_port(ctx, port['port']['id'], port)
|
plugin.update_port(ctx, port['port']['id'], port)
|
||||||
self.assertTrue(sg_member_update.called)
|
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):
|
def test_update_port_status_with_network(self):
|
||||||
registry.clear() # don't care about callback behavior
|
registry.clear() # don't care about callback behavior
|
||||||
ctx = context.get_admin_context()
|
ctx = context.get_admin_context()
|
||||||
|
|
Loading…
Reference in New Issue