]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Delete IP allocation range for subnet when deleting subnet
authorGary Kotton <gkotton@redhat.com>
Tue, 3 Jul 2012 17:11:31 +0000 (13:11 -0400)
committerGary Kotton <gkotton@redhat.com>
Tue, 3 Jul 2012 17:11:31 +0000 (13:11 -0400)
Fixes bug 1020563

Change-Id: I034e490825603ab71662a0bbad9b325f419a9e43

quantum/db/db_base_plugin_v2.py

index ab4da90905385513fbc95abba022321cff7abd5d..b91334fb09ffc7f7fd1419533d08e4646b4a6fb1 100644 (file)
@@ -591,9 +591,12 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
             subnet = self._get_subnet(context, id)
             # Check if ports are using this subnet
             allocated_qry = context.session.query(models_v2.IPAllocation)
-            allocated = allocated_qry.filter_by(port_id=id).all()
+            allocated = allocated_qry.filter_by(subnet_id=id).all()
             if allocated:
                 raise q_exc.SubnetInUse(subnet_id=id)
+            # Delete IP Allocations on subnet
+            range_qry = context.session.query(models_v2.IPAllocationRange)
+            range_qry.filter_by(subnet_id=id).delete()
             context.session.delete(subnet)
 
     def get_subnet(self, context, id, fields=None, verbose=None):