Merge "Stop removing ip allocations on port delete"

This commit is contained in:
Jenkins 2014-03-19 09:52:56 +00:00 committed by Gerrit Code Review
commit 3ccb3be933
2 changed files with 5 additions and 31 deletions

View 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)

View 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):