Pecan: add calls to resync/dirty quota usages

Add calls to dirty and resync the quota engine during
DELETEs and GETs respectively. This matches the old API controller
behavior and will be covered when the unit tests are switched to
use pecan in [1].

1. I76dc23fb7b96d82b0da50285bd0aac76142e81e5

Closes-Bug: #1714389
Change-Id: I1fb6b471e0e7cbf9b10dd14233931be94af38a41
This commit is contained in:
Kevin Benton 2017-08-30 20:16:59 -07:00
parent 6b650944e2
commit e76a575b05
1 changed files with 12 additions and 4 deletions

View File

@ -62,11 +62,19 @@ class QuotaEnforcementHook(hooks.PecanHook):
state.request.context['reservations'] = reservations
def after(self, state):
# Commit reservation(s)
reservations = state.request.context.get('reservations')
if not reservations:
return
neutron_context = state.request.context.get('neutron_context')
if not neutron_context:
return
collection = state.request.context.get('collection')
resource = state.request.context.get('resource')
if state.request.method == 'GET' and collection:
# resync on list operations to preserve behavior of old API
resource_registry.resync_resource(
neutron_context, resource, neutron_context.tenant_id)
# Commit reservation(s)
reservations = state.request.context.get('reservations') or []
if not reservations and state.request.method != 'DELETE':
return
with db_api.context_manager.writer.using(neutron_context):
# Commit the reservation(s)
for reservation in reservations: