]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix quota usage tracker for security group rules
authorSalvatore Orlando <salv.orlando@gmail.com>
Thu, 24 Sep 2015 12:45:40 +0000 (05:45 -0700)
committerCarl Baldwin <carl@ecbaldwin.net>
Thu, 24 Sep 2015 16:11:20 +0000 (16:11 +0000)
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
(cherry picked from commit 851b1b4bbbaa965f190bfacab03fd6ece80ad0ec)

neutron/db/securitygroups_db.py

index 7c589046990a6434fe90e93f0b5373e24f2453b6..ded5a323d296440dcf74e59946d92a22321e4912 100644 (file)
@@ -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(