From: Aaron Rosen Date: Tue, 7 Jul 2015 18:58:06 +0000 (-0700) Subject: Move update_security_group_on_port to SecurityGroupDbMixin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a6be4aa71d8f81d622cdd94d2512f59791d89254;p=openstack-build%2Fneutron-build.git Move update_security_group_on_port to SecurityGroupDbMixin Previously this function lived in SecurityGroupServerRpcMixin. This patch moves this function to SecurityGroupDbMixin so plugins who don't use SecurityGroupServerRpcMixin can leverage this function. This patch has no affect to anyone using SecurityGroupServerRpcMixin as that inherits from SecurityGroupDbMixin. Change-Id: I6ce60dad222e1e244f0d4fac9680e73de2a9b2e9 --- diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index ff28337a5..49b4f0913 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -27,6 +27,7 @@ from neutron.callbacks import exceptions from neutron.callbacks import registry from neutron.callbacks import resources from neutron.common import constants +from neutron.common import utils from neutron.db import api as db_api from neutron.db import db_base_plugin_v2 from neutron.db import model_base @@ -735,3 +736,31 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): port['port'][ext_sg.SECURITYGROUPS] != [])): return True return False + + def update_security_group_on_port(self, context, id, port, + original_port, updated_port): + """Update security groups on port. + + This method returns a flag which indicates request notification + is required and does not perform notification itself. + It is because another changes for the port may require notification. + """ + need_notify = False + port_updates = port['port'] + if (ext_sg.SECURITYGROUPS in port_updates and + not utils.compare_elements( + original_port.get(ext_sg.SECURITYGROUPS), + port_updates[ext_sg.SECURITYGROUPS])): + # delete the port binding and read it with the new rules + port_updates[ext_sg.SECURITYGROUPS] = ( + self._get_security_groups_on_port(context, port)) + self._delete_port_security_group_bindings(context, id) + self._process_port_create_security_group( + context, + updated_port, + port_updates[ext_sg.SECURITYGROUPS]) + need_notify = True + else: + updated_port[ext_sg.SECURITYGROUPS] = ( + original_port[ext_sg.SECURITYGROUPS]) + return need_notify diff --git a/neutron/db/securitygroups_rpc_base.py b/neutron/db/securitygroups_rpc_base.py index 3be75c378..63212fad9 100644 --- a/neutron/db/securitygroups_rpc_base.py +++ b/neutron/db/securitygroups_rpc_base.py @@ -91,34 +91,6 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): self.notifier.security_groups_rule_updated(context, [rule['security_group_id']]) - def update_security_group_on_port(self, context, id, port, - original_port, updated_port): - """Update security groups on port. - - This method returns a flag which indicates request notification - is required and does not perform notification itself. - It is because another changes for the port may require notification. - """ - need_notify = False - port_updates = port['port'] - if (ext_sg.SECURITYGROUPS in port_updates and - not utils.compare_elements( - original_port.get(ext_sg.SECURITYGROUPS), - port_updates[ext_sg.SECURITYGROUPS])): - # delete the port binding and read it with the new rules - port_updates[ext_sg.SECURITYGROUPS] = ( - self._get_security_groups_on_port(context, port)) - self._delete_port_security_group_bindings(context, id) - self._process_port_create_security_group( - context, - updated_port, - port_updates[ext_sg.SECURITYGROUPS]) - need_notify = True - else: - updated_port[ext_sg.SECURITYGROUPS] = ( - 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(