From 851b1b4bbbaa965f190bfacab03fd6ece80ad0ec Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 24 Sep 2015 05:45:40 -0700 Subject: [PATCH] Fix quota usage tracker for security group rules This simple patch ensures usage for security group rules is marked as dirty when a security group rule is deleted. To this aim, the security group rule is deleted using ORM in order to ensure the sqlalchemy even if fired. Closes-Bug: #1499339 Change-Id: I1e81fe03fed14ec438cea5d7675f66caeb91afd8 --- neutron/db/securitygroups_db.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 7c5890469..ded5a323d 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -614,8 +614,13 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): raise ext_sg.SecurityGroupRuleInUse(id=id, reason=reason) with context.session.begin(subtransactions=True): - query = self._model_query(context, SecurityGroupRule) - if query.filter(SecurityGroupRule.id == id).delete() == 0: + query = self._model_query(context, SecurityGroupRule).filter( + SecurityGroupRule.id == id) + try: + # As there is a filter on a primary key it is not possible for + # MultipleResultsFound to be raised + context.session.delete(query.one()) + except exc.NoResultFound: raise ext_sg.SecurityGroupRuleNotFound(id=id) registry.notify( -- 2.45.2