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
This commit is contained in:
Akihiro Motoki 2014-09-18 15:52:35 +09:00
parent 2c02f7c11e
commit d49ad74e28
2 changed files with 35 additions and 7 deletions

View File

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

View File

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