]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move update_security_group_on_port to SecurityGroupDbMixin
authorAaron Rosen <aaronorosen@gmail.com>
Tue, 7 Jul 2015 18:58:06 +0000 (11:58 -0700)
committerAaron Rosen <aaronorosen@gmail.com>
Thu, 9 Jul 2015 07:50:48 +0000 (07:50 +0000)
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

neutron/db/securitygroups_db.py
neutron/db/securitygroups_rpc_base.py

index ff28337a522bb54e3107ce20c0e70b4f5420cb21..49b4f0913c4f87d86bfff8f6007cd9f5130740fa 100644 (file)
@@ -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
index 3be75c3786540849228c2d14a0993f94155921fa..63212fad92cdd232be6376f04cdae9b93660edf5 100644 (file)
@@ -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(