Permalink
Browse files

Add a check for unlimited quotas

This extra check will prevent Horizon to misunderstand "-1" value when tallying quotas,
setting the "Available" field to inf instead of 0.

Fixes: bug #1084976
Change-Id: Ib316a15ac8ffa8ed4e4c51c02d5956db57fb6f6e
  • Loading branch information...
1 parent 6f5fdef commit aec73a78b2b3dc7cabe65b246cd5c3c4d872e0ec @vkmc vkmc committed Dec 3, 2012
Showing with 45 additions and 1 deletion.
  1. +44 −0 openstack_dashboard/test/tests/quotas.py
  2. +1 −1 openstack_dashboard/usage/quotas.py
@@ -134,3 +134,47 @@ def test_tenant_quota_usages_no_instances_running(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',),
+ cinder: ('volume_list', 'tenant_quota_get',)})
+ def test_tenant_quota_usages_unlimited_quota(self):
+ inf_quota = self.quotas.first()
+ inf_quota['ram'] = -1
+
+ quotas.is_service_enabled(IsA(http.HttpRequest),
+ 'volume').AndReturn(True)
+ api.nova.flavor_list(IsA(http.HttpRequest)) \
+ .AndReturn(self.flavors.list())
+ api.nova.tenant_quota_get(IsA(http.HttpRequest), '1') \
+ .AndReturn(inf_quota)
+ api.nova.tenant_floating_ip_list(IsA(http.HttpRequest)) \
+ .AndReturn(self.floating_ips.list())
+ api.nova.server_list(IsA(http.HttpRequest)) \
+ .AndReturn(self.servers.list())
+ cinder.volume_list(IsA(http.HttpRequest)) \
+ .AndReturn(self.volumes.list())
+ cinder.tenant_quota_get(IsA(http.HttpRequest), '1') \
+ .AndReturn(inf_quota)
+
+ 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},
+ 'gigabytes': {'available': 920, 'used': 80, 'quota': 1000},
+ 'ram': {'available': float("inf"), 'used': 1024,
+ 'quota': float("inf")},
+ 'floating_ips': {'available': 0, 'used': 2, 'quota': 1},
+ 'instances': {'available': 8, 'used': 2, 'quota': 10},
+ 'volumes': {'available': 0, 'used': 3, 'quota': 1},
+ 'cores': {'available': 8, 'used': 2, 'quota': 10}
+ }
+
+ # Compare internal structure of usages to expected.
+ self.assertEquals(quota_usages.usages, expected_output)
@@ -27,7 +27,7 @@ def __repr__(self):
def add_quota(self, quota):
""" Adds an internal tracking reference for the given quota. """
- if quota.limit is None:
+ if quota.limit is None or quota.limit == -1:
# Handle "unlimited" quotas.
self.usages[quota.name]['quota'] = float("inf")
self.usages[quota.name]['available'] = float("inf")

0 comments on commit aec73a7

Please sign in to comment.