nova limits ERROR (Exception): Field names must be unique

Running `nova absolute-limits` or `nova limits` can fail
when unaccounted for limits are returned

This works OK for a standard Vanilla OpenStack deployment
today, but it is quite fragile if new limit types are
introduced, or if a deployer sends back
other custom limits.
For instance, my limits include `maxTotalPrivateNetworks`
and `totalPrivateNetworksUsed` limits, which do not map
accordingly, and thus result in an error.

This happens when 'Others' field(custom limit type) is
occuring more than once which is not handled in code
causing multiple columns having same name.
Which throws exception and does not pretty prints
absolute limit.

This fix should also fix any future custom limits.

Closes-bug: #1546767

Change-Id: I1d3cf707722fc71c20cf4ec517b3f4f4875480e0
This commit is contained in:
Rahul 2017-12-14 15:55:43 +05:30
parent beb90ec793
commit 43f093623a
2 changed files with 22 additions and 1 deletions

View File

@ -18,6 +18,7 @@
import argparse
import base64
import collections
import datetime
import os
@ -43,6 +44,11 @@ FAKE_UUID_1 = fakes.FAKE_IMAGE_UUID_1
FAKE_UUID_2 = fakes.FAKE_IMAGE_UUID_2
# Converting dictionary to object
TestAbsoluteLimits = collections.namedtuple("TestAbsoluteLimits",
["name", "value"])
class ShellFixture(fixtures.Fixture):
def setUp(self):
super(ShellFixture, self).setUp()
@ -2814,6 +2820,20 @@ class ShellTest(utils.TestCase):
self.assertIn('Verb', stdout)
self.assertIn('Name', stdout)
def test_print_absolute_limits(self):
# Note: This test is to validate that no exception is
# thrown if in case we pass multiple custom fields
limits = [TestAbsoluteLimits('maxTotalPrivateNetworks', 3),
TestAbsoluteLimits('totalPrivateNetworksUsed', 0),
# Above two fields are custom fields
TestAbsoluteLimits('maxImageMeta', 15),
TestAbsoluteLimits('totalCoresUsed', 10),
TestAbsoluteLimits('totalInstancesUsed', 5),
TestAbsoluteLimits('maxServerMeta', 10),
TestAbsoluteLimits('totalRAMUsed', 10240),
TestAbsoluteLimits('totalFloatingIpsUsed', 10)]
novaclient.v2.shell._print_absolute_limits(limits=limits)
def test_limits_2_57(self):
"""Tests the limits command at microversion 2.57 where personality
size limits should not be shown.

View File

@ -2853,7 +2853,8 @@ def _print_absolute_limits(limits):
used[name] = l.value
else:
other[name] = l.value
columns.append('Other')
if 'Other' not in columns:
columns.append('Other')
if name not in limit_names:
limit_names.append(name)