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
(cherry picked from commit 851b1b4bbb)
This commit is contained in:
Salvatore Orlando 2015-09-24 05:45:40 -07:00 committed by Carl Baldwin
parent 3b0934e9f1
commit 0782a0b381
1 changed files with 7 additions and 2 deletions

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