Address problems with foreign keys with subnet and network deletion
This also fixes bug 1020879 and bug 1020847 Change-Id: Ib68f9357ed65f35e56d17577b83fabe8f96388cf
This commit is contained in:
parent
17bed81d11
commit
80a44c82d0
@ -704,9 +704,6 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
allocated = allocated_qry.filter_by(subnet_id=id).all()
|
allocated = allocated_qry.filter_by(subnet_id=id).all()
|
||||||
if allocated:
|
if allocated:
|
||||||
raise q_exc.SubnetInUse(subnet_id=id)
|
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)
|
context.session.delete(subnet)
|
||||||
|
|
||||||
def get_subnet(self, context, id, fields=None, verbose=None):
|
def get_subnet(self, context, id, fields=None, verbose=None):
|
||||||
|
@ -44,7 +44,8 @@ class IPAvailabilityRange(model_base.BASEV2):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
allocation_pool_id = sa.Column(sa.String(36),
|
allocation_pool_id = sa.Column(sa.String(36),
|
||||||
sa.ForeignKey('ipallocationpools.id'),
|
sa.ForeignKey('ipallocationpools.id',
|
||||||
|
ondelete="CASCADE"),
|
||||||
nullable=True,
|
nullable=True,
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
first_ip = sa.Column(sa.String(64), nullable=False, primary_key=True)
|
first_ip = sa.Column(sa.String(64), nullable=False, primary_key=True)
|
||||||
@ -57,7 +58,8 @@ class IPAvailabilityRange(model_base.BASEV2):
|
|||||||
class IPAllocationPool(model_base.BASEV2, HasId):
|
class IPAllocationPool(model_base.BASEV2, HasId):
|
||||||
"""Representation of an allocation pool in a Quantum subnet."""
|
"""Representation of an allocation pool in a Quantum subnet."""
|
||||||
|
|
||||||
subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id'),
|
subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id',
|
||||||
|
ondelete="CASCADE"),
|
||||||
nullable=True)
|
nullable=True)
|
||||||
first_ip = sa.Column(sa.String(64), nullable=False)
|
first_ip = sa.Column(sa.String(64), nullable=False)
|
||||||
last_ip = sa.Column(sa.String(64), nullable=False)
|
last_ip = sa.Column(sa.String(64), nullable=False)
|
||||||
@ -72,12 +74,15 @@ class IPAllocationPool(model_base.BASEV2, HasId):
|
|||||||
class IPAllocation(model_base.BASEV2):
|
class IPAllocation(model_base.BASEV2):
|
||||||
"""Internal representation of allocated IP addresses in a Quantum subnet.
|
"""Internal representation of allocated IP addresses in a Quantum subnet.
|
||||||
"""
|
"""
|
||||||
port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id'),
|
port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id',
|
||||||
|
ondelete="CASCADE"),
|
||||||
nullable=False, primary_key=True)
|
nullable=False, primary_key=True)
|
||||||
ip_address = sa.Column(sa.String(64), nullable=False, primary_key=True)
|
ip_address = sa.Column(sa.String(64), nullable=False, primary_key=True)
|
||||||
subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id'),
|
subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id',
|
||||||
|
ondelete="CASCADE"),
|
||||||
nullable=False, primary_key=True)
|
nullable=False, primary_key=True)
|
||||||
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id"),
|
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id",
|
||||||
|
ondelete="CASCADE"),
|
||||||
nullable=False, primary_key=True)
|
nullable=False, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +49,6 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2):
|
|||||||
|
|
||||||
def delete_network(self, context, id):
|
def delete_network(self, context, id):
|
||||||
vlan_binding = cdb.get_vlan_binding(id)
|
vlan_binding = cdb.get_vlan_binding(id)
|
||||||
cdb.release_vlanid(vlan_binding[const.VLANID])
|
cdb.release_vlanid(vlan_binding['vlan_id'])
|
||||||
cdb.remove_vlan_binding(id)
|
cdb.remove_vlan_binding(id)
|
||||||
return super(LinuxBridgePluginV2, self).delete_network(context, id)
|
return super(LinuxBridgePluginV2, self).delete_network(context, id)
|
||||||
|
@ -718,6 +718,34 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
self._test_create_subnet(gateway_ip=gateway_ip,
|
self._test_create_subnet(gateway_ip=gateway_ip,
|
||||||
cidr=cidr)
|
cidr=cidr)
|
||||||
|
|
||||||
|
def test_delete_subnet(self):
|
||||||
|
gateway_ip = '10.0.0.1'
|
||||||
|
cidr = '10.0.0.0/24'
|
||||||
|
fmt = 'json'
|
||||||
|
# Create new network
|
||||||
|
res = self._create_network(fmt=fmt, name='net',
|
||||||
|
admin_status_up=True)
|
||||||
|
network = self.deserialize(fmt, res)
|
||||||
|
subnet = self._make_subnet(fmt, network, gateway_ip,
|
||||||
|
cidr, ip_version=4)
|
||||||
|
req = self.new_delete_request('subnets', subnet['subnet']['id'])
|
||||||
|
res = req.get_response(self.api)
|
||||||
|
self.assertEquals(res.status_int, 204)
|
||||||
|
|
||||||
|
def test_delete_network(self):
|
||||||
|
gateway_ip = '10.0.0.1'
|
||||||
|
cidr = '10.0.0.0/24'
|
||||||
|
fmt = 'json'
|
||||||
|
# Create new network
|
||||||
|
res = self._create_network(fmt=fmt, name='net',
|
||||||
|
admin_status_up=True)
|
||||||
|
network = self.deserialize(fmt, res)
|
||||||
|
subnet = self._make_subnet(fmt, network, gateway_ip,
|
||||||
|
cidr, ip_version=4)
|
||||||
|
req = self.new_delete_request('networks', network['network']['id'])
|
||||||
|
res = req.get_response(self.api)
|
||||||
|
self.assertEquals(res.status_int, 204)
|
||||||
|
|
||||||
def test_create_subnet_defaults(self):
|
def test_create_subnet_defaults(self):
|
||||||
gateway = '10.0.0.1'
|
gateway = '10.0.0.1'
|
||||||
cidr = '10.0.0.0/24'
|
cidr = '10.0.0.0/24'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user