Merge "Make sure vCPU and RAM quotas are initialised when no instances are running"
This commit is contained in:
commit
6f5fdef017
@ -103,3 +103,34 @@ class QuotaTests(test.APITestCase):
|
|||||||
|
|
||||||
# Compare internal structure of usages to expected.
|
# Compare internal structure of usages to expected.
|
||||||
self.assertEquals(quota_usages.usages, expected_output)
|
self.assertEquals(quota_usages.usages, expected_output)
|
||||||
|
|
||||||
|
@test.create_stubs({api.nova: ('server_list',
|
||||||
|
'flavor_list',
|
||||||
|
'tenant_floating_ip_list',
|
||||||
|
'tenant_quota_get',),
|
||||||
|
quotas: ('is_service_enabled',)})
|
||||||
|
def test_tenant_quota_usages_no_instances_running(self):
|
||||||
|
quotas.is_service_enabled(IsA(http.HttpRequest),
|
||||||
|
'volume').AndReturn(False)
|
||||||
|
api.nova.flavor_list(IsA(http.HttpRequest)) \
|
||||||
|
.AndReturn(self.flavors.list())
|
||||||
|
api.nova.tenant_quota_get(IsA(http.HttpRequest), '1') \
|
||||||
|
.AndReturn(self.quotas.first())
|
||||||
|
api.nova.tenant_floating_ip_list(IsA(http.HttpRequest)).AndReturn([])
|
||||||
|
api.nova.server_list(IsA(http.HttpRequest)).AndReturn([])
|
||||||
|
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
quota_usages = quotas.tenant_quota_usages(self.request)
|
||||||
|
expected_output = {
|
||||||
|
'injected_file_content_bytes': {'quota': 1},
|
||||||
|
'metadata_items': {'quota': 1},
|
||||||
|
'injected_files': {'quota': 1},
|
||||||
|
'ram': {'available': 10000, 'used': 0, 'quota': 10000},
|
||||||
|
'floating_ips': {'available': 1, 'used': 0, 'quota': 1},
|
||||||
|
'instances': {'available': 10, 'used': 0, 'quota': 10},
|
||||||
|
'cores': {'available': 10, 'used': 0, 'quota': 10}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Compare internal structure of usages to expected.
|
||||||
|
self.assertEquals(quota_usages.usages, expected_output)
|
||||||
|
@ -112,4 +112,9 @@ def tenant_quota_usages(request):
|
|||||||
usages.tally('cores', getattr(flavor, 'vcpus', None))
|
usages.tally('cores', getattr(flavor, 'vcpus', None))
|
||||||
usages.tally('ram', getattr(flavor, 'ram', None))
|
usages.tally('ram', getattr(flavor, 'ram', None))
|
||||||
|
|
||||||
|
# Initialise the tally if no instances have been launched yet
|
||||||
|
if len(instances) == 0:
|
||||||
|
usages.tally('cores', 0)
|
||||||
|
usages.tally('ram', 0)
|
||||||
|
|
||||||
return usages
|
return usages
|
||||||
|
Loading…
Reference in New Issue
Block a user