Permalink
Browse files

Merge "Make sure vCPU and RAM quotas are initialised when no instance…

…s are running"
  • Loading branch information...
2 parents aa3e274 + 300747c commit 6f5fdef01775cc89f7b9693ff1e22db3ae02e478 Jenkins committed with openstack-gerrit Dec 4, 2012
Showing with 36 additions and 0 deletions.
  1. +31 −0 openstack_dashboard/test/tests/quotas.py
  2. +5 −0 openstack_dashboard/usage/quotas.py
@@ -103,3 +103,34 @@ def test_tenant_quota_usages_without_volume(self):
# Compare internal structure of usages to expected.
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('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

0 comments on commit 6f5fdef

Please sign in to comment.