Ensure Quotas can be updated concurrently

Closes-Bug: 1433560
Change-Id: I1927bf3942e3a33aa69e3db307e7b0f57b53b4e6
This commit is contained in:
Kiall Mac Innes 2015-03-18 12:23:05 +00:00
parent 3b93343f5c
commit 46ebbd3774

View File

@ -19,6 +19,7 @@ from oslo_log import log as logging
from designate import exceptions from designate import exceptions
from designate import storage from designate import storage
from designate import objects from designate import objects
from designate.central import service as central_service
from designate.quota.base import Quota from designate.quota.base import Quota
@ -53,6 +54,7 @@ class StorageQuota(Quota):
return {resource: quota['hard_limit']} return {resource: quota['hard_limit']}
@central_service.transaction
def set_quota(self, context, tenant_id, resource, hard_limit): def set_quota(self, context, tenant_id, resource, hard_limit):
context = context.deepcopy() context = context.deepcopy()
context.all_tenants = True context.all_tenants = True
@ -73,17 +75,17 @@ class StorageQuota(Quota):
"resource", resource) "resource", resource)
try: try:
create_quota()
except exceptions.Duplicate:
quota = self.storage.find_quota(context, { quota = self.storage.find_quota(context, {
'tenant_id': tenant_id, 'tenant_id': tenant_id,
'resource': resource, 'resource': resource,
}) })
except exceptions.NotFound:
create_quota()
else:
update_quota(quota) update_quota(quota)
return {resource: hard_limit} return {resource: hard_limit}
@central_service.transaction
def reset_quotas(self, context, tenant_id): def reset_quotas(self, context, tenant_id):
context = context.deepcopy() context = context.deepcopy()
context.all_tenants = True context.all_tenants = True