]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fix missing deallocation of gateway ip
authorDan Wendlandt <dan@nicira.com>
Wed, 8 Aug 2012 22:30:48 +0000 (15:30 -0700)
committerDan Wendlandt <dan@nicira.com>
Wed, 8 Aug 2012 22:30:48 +0000 (15:30 -0700)
bug 1032506

when deleting a port that uses the gateway IP, we were not removing
the IPAllocation entry, which resulted in a depedency issue when we
deleted the port that the IPAllocation entry referenced.

Change-Id: I272a6572c389ef8c12585f4b62204f5877cda078

quantum/db/db_base_plugin_v2.py

index d07e5d0d0a690b2ce00a8940327f3d913a2a035c..ed3922ac9ebf8e00381a513197a7e0de893d4835 100644 (file)
@@ -240,6 +240,12 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                 last_ip=ip_address)
             context.session.add(ip_range)
             LOG.debug("Recycle: created new %s-%s", ip_address, ip_address)
+        QuantumDbPluginV2._delete_ip_allocation(context, network_id, subnet_id,
+                                                port_id, ip_address)
+
+    @staticmethod
+    def _delete_ip_allocation(context, network_id, subnet_id, port_id,
+                              ip_address):
 
         # Delete the IP address from the IPAllocate table
         LOG.debug("Delete allocated IP %s (%s/%s/%s)", ip_address,
@@ -834,9 +840,14 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
             allocated = allocated_qry.filter_by(port_id=id).all()
             if allocated:
                 for a in allocated:
-                    # Gateway address will not be recycled
                     subnet = self._get_subnet(context, a['subnet_id'])
                     if a['ip_address'] == subnet['gateway_ip']:
+                        # Gateway address will not be recycled, but we do
+                        # need to delete the allocation from the DB
+                        QuantumDbPluginV2._delete_ip_allocation(
+                            context,
+                            a['network_id'], a['subnet_id'],
+                            id, a['ip_address'])
                         LOG.debug("Gateway address (%s/%s) is not recycled",
                                   a['ip_address'], a['subnet_id'])
                         continue