Handle float('inf') in tenant_quota_usages properly
tenant_absolute_limits API wrapper converts -1 (unlimited) to float('inf'), but tenant_quota_usages() cannot handle this properly. This is a regression during the quota refactoring work. This commit changes QuotaUsage.add_quota() to accept float('inf') as one of unlimited quota value. Closes-Bug: #1741493 Part of blueprint make-quotas-great-again Change-Id: Ic6ed00761381d52ee04a15a43ee4fe2a30b9a106
This commit is contained in:
parent
0d1d22c85e
commit
6baf8c9fa0
@ -68,7 +68,8 @@ class QuotaTests(test.APITestCase):
|
||||
return usages
|
||||
|
||||
def get_usages_from_limits(self, with_volume=True, with_compute=True,
|
||||
nova_quotas_enabled=True):
|
||||
nova_quotas_enabled=True,
|
||||
unlimited_items=None):
|
||||
usages = {}
|
||||
if with_compute and nova_quotas_enabled:
|
||||
usages.update({
|
||||
@ -83,6 +84,10 @@ class QuotaTests(test.APITestCase):
|
||||
'gigabytes': {'available': 600, 'used': 400, 'quota': 1000},
|
||||
'snapshots': {'available': 7, 'used': 3, 'quota': 10},
|
||||
})
|
||||
if unlimited_items:
|
||||
for item in unlimited_items:
|
||||
usages[item]['available'] = float('inf')
|
||||
usages[item]['quota'] = float('inf')
|
||||
return usages
|
||||
|
||||
def assertAvailableQuotasEqual(self, expected_usages, actual_usages):
|
||||
@ -130,7 +135,8 @@ class QuotaTests(test.APITestCase):
|
||||
cinder: ('tenant_absolute_limits',
|
||||
'is_volume_service_enabled')})
|
||||
def _test_tenant_quota_usages(self, nova_quotas_enabled=True,
|
||||
with_compute=True, with_volume=True):
|
||||
with_compute=True, with_volume=True,
|
||||
unlimited_items=None):
|
||||
tenant_id = '1'
|
||||
cinder.is_volume_service_enabled(IsA(http.HttpRequest)).AndReturn(
|
||||
with_volume)
|
||||
@ -157,7 +163,8 @@ class QuotaTests(test.APITestCase):
|
||||
expected_output = self.get_usages_from_limits(
|
||||
nova_quotas_enabled=nova_quotas_enabled,
|
||||
with_volume=with_volume,
|
||||
with_compute=with_compute)
|
||||
with_compute=with_compute,
|
||||
unlimited_items=unlimited_items)
|
||||
|
||||
# Compare internal structure of usages to expected.
|
||||
self.assertItemsEqual(expected_output, quota_usages.usages)
|
||||
@ -173,6 +180,10 @@ class QuotaTests(test.APITestCase):
|
||||
with_compute=True,
|
||||
with_volume=False)
|
||||
|
||||
def test_tenant_quota_usages_with_unlimited(self):
|
||||
self.limits['absolute']['maxTotalInstances'] = float('inf')
|
||||
self._test_tenant_quota_usages(unlimited_items=['instances'])
|
||||
|
||||
@override_settings(OPENSTACK_HYPERVISOR_FEATURES={'enable_quotas': False})
|
||||
@test.create_stubs({api.base: ('is_service_enabled',),
|
||||
cinder: ('is_volume_service_enabled',)})
|
||||
|
@ -137,7 +137,7 @@ class QuotaUsage(dict):
|
||||
|
||||
def add_quota(self, quota):
|
||||
"""Adds an internal tracking reference for the given quota."""
|
||||
if quota.limit is None or quota.limit == -1:
|
||||
if quota.limit in (None, -1, float('inf')):
|
||||
# Handle "unlimited" quotas.
|
||||
self.usages[quota.name]['quota'] = float("inf")
|
||||
self.usages[quota.name]['available'] = float("inf")
|
||||
|
Loading…
Reference in New Issue
Block a user