Merge "Make sure vCPU and RAM quotas are initialised when no instances are running"

This commit is contained in:
Jenkins 2012-12-04 20:08:10 +00:00 committed by Gerrit Code Review
commit 6f5fdef017
2 changed files with 36 additions and 0 deletions

View File

@ -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)

View File

@ -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