diff options
author | Julie Pichon <jpichon@redhat.com> | 2014-10-28 13:02:15 +0000 |
---|---|---|
committer | Julie Pichon <jpichon@redhat.com> | 2014-10-29 12:00:33 +0000 |
commit | 146a72215c40e8697699ca2eaa165de5db135d14 (patch) | |
tree | cb4b77a6db4d6f2c10d22c2d130455108e15c68d | |
parent | 9e777f2530f3cecda97f4a0c2b261afe89dc295d (diff) | |
download | horizon-146a72215c40e8697699ca2eaa165de5db135d14.tar.gz |
Handle negative values in total*Used for Cinder absolute limits
In some cases negative values can be returned for resources currently
in use. When this occurs, the project overview page fails with an
error 500 due to an OverflowError, "cannot convert float infinity to
integer". Handle this case more gracefully.
Change-Id: Id1ad16eafdde906dc74bfafc7f72ea8d3bdcdc8f
Closes-Bug: #1386687
(cherry picked from commit 53c7dc022ed4e0d5d60fb344b3e8c94e3dfb7d43)
-rw-r--r-- | openstack_dashboard/api/cinder.py | 13 | ||||
-rw-r--r-- | openstack_dashboard/test/api_tests/cinder_tests.py | 23 |
2 files changed, 33 insertions, 3 deletions
diff --git a/openstack_dashboard/api/cinder.py b/openstack_dashboard/api/cinder.py index 734bacaa9..6f6dc3c78 100644 --- a/openstack_dashboard/api/cinder.py +++ b/openstack_dashboard/api/cinder.py @@ -484,9 +484,16 @@ def tenant_absolute_limits(request): limits = cinderclient(request).limits.get().absolute limits_dict = {} for limit in limits: - # -1 is used to represent unlimited quotas - if limit.value == -1: - limits_dict[limit.name] = float("inf") + if limit.value < 0: + # In some cases, the absolute limits data in Cinder can get + # out of sync causing the total.*Used limits to return + # negative values instead of 0. For such cases, replace + # negative values with 0. + if limit.name.startswith('total') and limit.name.endswith('Used'): + limits_dict[limit.name] = 0 + else: + # -1 is used to represent unlimited quotas + limits_dict[limit.name] = float("inf") else: limits_dict[limit.name] = limit.value return limits_dict diff --git a/openstack_dashboard/test/api_tests/cinder_tests.py b/openstack_dashboard/test/api_tests/cinder_tests.py index 3a9de3b12..47f85bc15 100644 --- a/openstack_dashboard/test/api_tests/cinder_tests.py +++ b/openstack_dashboard/test/api_tests/cinder_tests.py @@ -13,6 +13,7 @@ # under the License. from django.test.utils import override_settings +import six import cinderclient as cinder_client @@ -86,6 +87,28 @@ class CinderApiTests(test.APITestCase): associate_spec = assoc_vol_types[0].associated_qos_spec self.assertTrue(associate_spec, qos_specs_only_one[0].name) + def test_absolute_limits_with_negative_values(self): + values = {"maxTotalVolumes": -1, "totalVolumesUsed": -1} + expected_results = {"maxTotalVolumes": float("inf"), + "totalVolumesUsed": 0} + + limits = self.mox.CreateMockAnything() + limits.absolute = [] + for key, val in six.iteritems(values): + limit = self.mox.CreateMockAnything() + limit.name = key + limit.value = val + limits.absolute.append(limit) + + cinderclient = self.stub_cinderclient() + cinderclient.limits = self.mox.CreateMockAnything() + cinderclient.limits.get().AndReturn(limits) + self.mox.ReplayAll() + + ret_val = api.cinder.tenant_absolute_limits(self.request) + for key in expected_results.keys(): + self.assertEqual(expected_results[key], ret_val[key]) + class CinderApiVersionTests(test.TestCase): |