From d49ad74e280f9b7d9397e951f12dc428f26821df Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Thu, 18 Sep 2014 15:52:35 +0900 Subject: [PATCH] Workaround for negative vals in total*Used in nova absolute_limits Due to bug 1370867 there is a case where negative values are returned in total*Used in absolute_limits. If it occurs, Horizon Overview page cannot be displayed due to an error "cannot convert float infinity to integer". This commit replaces negative values in total*Used with 0 for a workarond. Change-Id: I606803bdff1d335cc9f92d67619ff82f356a5143 Closes-Bug: #1370869 --- openstack_dashboard/api/nova.py | 12 ++++++-- .../test/api_tests/nova_tests.py | 30 ++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py index a58fd1820d..f3ec4ee91b 100644 --- a/openstack_dashboard/api/nova.py +++ b/openstack_dashboard/api/nova.py @@ -755,9 +755,15 @@ def tenant_absolute_limits(request, reserved=False): limits = novaclient(request).limits.get(reserved=reserved).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: + # Workaround for nova bug 1370867 that absolute_limits + # returns negative value for total.*Used instead of 0. + # For such case, 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/nova_tests.py b/openstack_dashboard/test/api_tests/nova_tests.py index 472b210283..f1fea51daf 100644 --- a/openstack_dashboard/test/api_tests/nova_tests.py +++ b/openstack_dashboard/test/api_tests/nova_tests.py @@ -211,8 +211,7 @@ class ComputeApiTests(test.APITestCase): ret_val = api.nova.server_get(self.request, server.id) self.assertIsInstance(ret_val, api.nova.Server) - def test_absolute_limits_handle_unlimited(self): - values = {"maxTotalCores": -1, "maxTotalInstances": 10} + def _test_absolute_limits(self, values, expected_results): limits = self.mox.CreateMockAnything() limits.absolute = [] for key, val in six.iteritems(values): @@ -227,7 +226,30 @@ class ComputeApiTests(test.APITestCase): self.mox.ReplayAll() ret_val = api.nova.tenant_absolute_limits(self.request, reserved=True) - expected_results = {"maxTotalCores": float("inf"), - "maxTotalInstances": 10} for key in expected_results.keys(): self.assertEqual(expected_results[key], ret_val[key]) + + def test_absolute_limits_handle_unlimited(self): + values = {"maxTotalCores": -1, "maxTotalInstances": 10} + expected_results = {"maxTotalCores": float("inf"), + "maxTotalInstances": 10} + self._test_absolute_limits(values, expected_results) + + def test_absolute_limits_negative_used_workaround(self): + values = {"maxTotalCores": -1, + "maxTotalInstances": 10, + "totalInstancesUsed": -1, + "totalCoresUsed": -1, + "totalRAMUsed": -2048, + "totalSecurityGroupsUsed": 1, + "totalFloatingIpsUsed": 0, + } + expected_results = {"maxTotalCores": float("inf"), + "maxTotalInstances": 10, + "totalInstancesUsed": 0, + "totalCoresUsed": 0, + "totalRAMUsed": 0, + "totalSecurityGroupsUsed": 1, + "totalFloatingIpsUsed": 0, + } + self._test_absolute_limits(values, expected_results)