From 0cf620bdf945527077f9875a1849e71ec0d1c6b2 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Fri, 18 Sep 2015 14:57:21 -0700 Subject: [PATCH] delete_port: ensure quota usage is marked as dirty To this aim the ORM session mapper must be used. This patch simply uses context.session.delete rather than query.delete, and handles UnmappedInstanceError to safely complete the operation when the record is deleted by another transaction. Change-Id: I55c701fc1e2fda4461501aae532bbe11cce45b75 Closes-Bug: #1497459 --- neutron/db/ipam_backend_mixin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index 3806cb040b7..13650b1d2d3 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -20,6 +20,7 @@ import netaddr from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging +from sqlalchemy.orm import exc as orm_exc from neutron.api.v2 import attributes from neutron.common import constants @@ -414,7 +415,14 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): enable_eagerloads(False).filter_by(id=port_id)) if not context.is_admin: query = query.filter_by(tenant_id=context.tenant_id) - query.delete(synchronize_session=False) + # Use of the ORM mapper is needed for ensuring appropriate resource + # tracking; otherwise SQL Alchemy events won't be triggered. + # For more info check 'caveats' in doc/source/devref/quota.rst + try: + context.session.delete(query.first()) + except orm_exc.UnmappedInstanceError: + LOG.debug("Port %s was not found and therefore no delete " + "operation was performed", port_id) def _save_subnet(self, context, network,