Merge "Delete subnet fails if assoc port has IPs from another subnet"
This commit is contained in:
commit
d1282b1eda
@ -1283,10 +1283,11 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
subnet = self._get_subnet(context, id)
|
subnet = self._get_subnet(context, id)
|
||||||
# Check if any tenant owned ports are using this subnet
|
# Check if any tenant owned ports are using this subnet
|
||||||
allocated_qry = context.session.query(models_v2.IPAllocation)
|
allocated = (context.session.query(models_v2.IPAllocation).
|
||||||
allocated_qry = allocated_qry.join(models_v2.Port)
|
filter_by(subnet_id=subnet['id']).
|
||||||
allocated = allocated_qry.filter_by(
|
join(models_v2.Port).
|
||||||
network_id=subnet.network_id).with_lockmode('update')
|
filter_by(network_id=subnet['network_id']).
|
||||||
|
with_lockmode('update'))
|
||||||
|
|
||||||
# remove network owned ports
|
# remove network owned ports
|
||||||
for a in allocated:
|
for a in allocated:
|
||||||
|
@ -2492,6 +2492,22 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
|||||||
msg = str(n_exc.SubnetInUse(subnet_id=id))
|
msg = str(n_exc.SubnetInUse(subnet_id=id))
|
||||||
self.assertEqual(data['NeutronError']['message'], msg)
|
self.assertEqual(data['NeutronError']['message'], msg)
|
||||||
|
|
||||||
|
def test_delete_subnet_with_other_subnet_on_network_still_in_use(self):
|
||||||
|
with self.network() as network:
|
||||||
|
with contextlib.nested(
|
||||||
|
self.subnet(network=network),
|
||||||
|
self.subnet(network=network, cidr='10.0.1.0/24',
|
||||||
|
do_delete=False)) as (subnet1, subnet2):
|
||||||
|
subnet1_id = subnet1['subnet']['id']
|
||||||
|
subnet2_id = subnet2['subnet']['id']
|
||||||
|
with self.port(
|
||||||
|
subnet=subnet1,
|
||||||
|
fixed_ips=[{'subnet_id': subnet1_id}]):
|
||||||
|
req = self.new_delete_request('subnets', subnet2_id)
|
||||||
|
res = req.get_response(self.api)
|
||||||
|
self.assertEqual(res.status_int,
|
||||||
|
webob.exc.HTTPNoContent.code)
|
||||||
|
|
||||||
def test_delete_network(self):
|
def test_delete_network(self):
|
||||||
gateway_ip = '10.0.0.1'
|
gateway_ip = '10.0.0.1'
|
||||||
cidr = '10.0.0.0/24'
|
cidr = '10.0.0.0/24'
|
||||||
|
Loading…
Reference in New Issue
Block a user