Don't update cinder quotas if disabled

The quotas for cinder were being updated even if they were disabled,
resulting in None being sent as the value, and an error being thrown
by the API.

This patch cleans up that code to use the same logic in all three cases
for nova, cinder and neutron.

Change-Id: I73209122df20689eee33da9dccffa994a04a3ec0
Closes-bug: #1671911
This commit is contained in:
Radomir Dopieralski 2017-03-30 09:17:35 +02:00
parent 39eea5ce22
commit 3055a98763
1 changed files with 18 additions and 16 deletions

View File

@ -411,25 +411,27 @@ class CommonQuotaWorkflow(workflows.Workflow):
# Update the project quotas. # Update the project quotas.
if api.base.is_service_enabled(request, 'compute'): if api.base.is_service_enabled(request, 'compute'):
nova_data = {key: data[key] for key in nova_data = {key: data[key] for key in
set(quotas.NOVA_QUOTA_FIELDS) - disabled_quotas} quotas.NOVA_QUOTA_FIELDS
nova.tenant_quota_update(request, project_id, **nova_data) if key not in disabled_quotas}
if nova_data:
nova.tenant_quota_update(request, project_id, **nova_data)
if cinder.is_volume_service_enabled(request): if cinder.is_volume_service_enabled(request):
cinder_data = dict([(key, data[key]) for key in cinder_data = {key: data[key] for key in
quotas.CINDER_QUOTA_FIELDS]) quotas.CINDER_QUOTA_FIELDS
cinder.tenant_quota_update(request, if key not in disabled_quotas and
project_id, data[key] is not None}
**cinder_data) if cinder_data:
cinder.tenant_quota_update(request, project_id, **cinder_data)
if api.base.is_service_enabled(request, 'network') and \ if (api.base.is_service_enabled(request, 'network') and
api.neutron.is_quotas_extension_supported(request): api.neutron.is_quotas_extension_supported(request)):
neutron_data = {} neutron_data = {key: data[key] for key in
for key in quotas.NEUTRON_QUOTA_FIELDS: quotas.NEUTRON_QUOTA_FIELDS
if key not in disabled_quotas: if key not in disabled_quotas}
neutron_data[key] = data[key] if neutron_data:
api.neutron.tenant_quota_update(request, api.neutron.tenant_quota_update(request, project_id,
project_id, **neutron_data)
**neutron_data)
class CreateProject(CommonQuotaWorkflow): class CreateProject(CommonQuotaWorkflow):