Support quota rollback when creating/importing keypair failed

Change-Id: I83a7410f7509913aa574fe7fe9fc08e4688b32f6
Closes-Bug: #1717912
This commit is contained in:
liusheng 2017-09-18 20:00:47 +08:00
parent 6dae54303f
commit 8b8fc495b0
1 changed files with 10 additions and 2 deletions

View File

@ -553,7 +553,11 @@ class API(object):
keypair.fingerprint = fingerprint
keypair.public_key = public_key
keypair.project_id = context.tenant
keypair.create()
try:
keypair.create()
except Exception:
with excutils.save_and_reraise_exception():
self.quota.rollback(context, reservations)
# Commit keypairs reservations
if reservations:
self.quota.commit(context, reservations)
@ -577,7 +581,11 @@ class API(object):
keypair.fingerprint = fingerprint
keypair.public_key = public_key
keypair.project_id = context.tenant
keypair.create()
try:
keypair.create()
except Exception:
with excutils.save_and_reraise_exception():
self.quota.rollback(context, reservations)
# Commit keypairs reservations
if reservations:
self.quota.commit(context, reservations)