]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Stop removing ip allocations on port delete
authorMaru Newby <marun@redhat.com>
Fri, 14 Mar 2014 22:14:09 +0000 (22:14 +0000)
committerMaru Newby <marun@redhat.com>
Tue, 18 Mar 2014 07:52:06 +0000 (00:52 -0700)
The _delete_port() method was manually removing related
IPAllocation instances despite the existence of a perfectly
good cascade deletion relationship in the model.  This patch
puts an end to that nonsense and the potential for deadlock that
it represented.

Closes-bug: #1288379
Related-Bug: #1283522

Change-Id: Ib31550fa9000fc75768a327cb6cc1c419e06568f

neutron/db/db_base_plugin_v2.py
neutron/db/l3_db.py

index 4db152eb2808b18c856a8b2e7e0400325863a6cc..dafead7b613a54c5703e4a06c8272d5eb0151d31 100644 (file)
@@ -1428,35 +1428,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
                  enable_eagerloads(False).filter_by(id=id))
         if not context.is_admin:
             query = query.filter_by(tenant_id=context.tenant_id)
-        port = query.with_lockmode('update').one()
-
-        allocated_qry = context.session.query(
-            models_v2.IPAllocation).with_lockmode('update')
-        # recycle all of the IP's
-        allocated = allocated_qry.filter_by(port_id=id)
-        for a in allocated:
-            subnet = self._get_subnet(context, a['subnet_id'])
-            # Check if IP was allocated from allocation pool
-            if NeutronDbPluginV2._check_ip_in_allocation_pool(
-                context, a['subnet_id'], subnet['gateway_ip'],
-                a['ip_address']):
-                NeutronDbPluginV2._delete_ip_allocation(context,
-                                                        a['network_id'],
-                                                        a['subnet_id'],
-                                                        a['ip_address'])
-            else:
-                # IPs out of allocation pool will not be recycled, but
-                # we do need to delete the allocation from the DB
-                NeutronDbPluginV2._delete_ip_allocation(
-                    context, a['network_id'],
-                    a['subnet_id'], a['ip_address'])
-                msg_dict = {'address': a['ip_address'],
-                            'subnet_id': a['subnet_id']}
-                msg = _("%(address)s (%(subnet_id)s) is not "
-                        "recycled") % msg_dict
-                LOG.debug(msg)
-
-        context.session.delete(port)
+        query.delete()
 
     def get_port(self, context, id, fields=None):
         port = self._get_port(context, id)
index e2ada9c0e53d67f8684d6f193366f7f5155d7f3d..6096b19d3c3d685e4248d2756aade6f18405ee98 100644 (file)
@@ -236,7 +236,10 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
             if vpnservice:
                 vpnservice.check_router_in_use(context, id)
 
-            # delete any gw port
+            context.session.delete(router)
+
+            # Delete the gw port after the router has been removed to
+            # avoid a constraint violation.
             device_filter = {'device_id': [id],
                              'device_owner': [DEVICE_OWNER_ROUTER_GW]}
             ports = self._core_plugin.get_ports(context.elevated(),
@@ -245,7 +248,6 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
                 self._core_plugin._delete_port(context.elevated(),
                                                ports[0]['id'])
 
-            context.session.delete(router)
         self.l3_rpc_notifier.router_deleted(context, id)
 
     def get_router(self, context, id, fields=None):