Prevents 400 NVP errors caused by a None display_name

The API forbids a resource name to be None, but the
Model does not. Such errors may  be induced by
programming directly against the plugin interface. With
this fix we avoid raising 400 faults which may be introduced
by involuntary programming errors.

Fixes bug 1221896

Change-Id: Ic1201c5af5691f2bed38753453f73c229858b10f
This commit is contained in:
armando-migliaccio
2013-09-06 12:57:48 -07:00
parent 76678dedf5
commit 63fcb79622
2 changed files with 19 additions and 1 deletions

View File

@@ -139,7 +139,7 @@ def _check_and_truncate_name(display_name):
LOG.debug(_("Specified name:'%s' exceeds maximum length. "
"It will be truncated on NVP"), display_name)
return display_name[:MAX_DISPLAY_NAME_LEN]
return display_name
return display_name or ''
def get_cluster_version(cluster):

View File

@@ -1442,5 +1442,23 @@ class TestNvplibVersioning(base.BaseTestCase):
'create_lrouter', None)
class NvplibMiscTestCase(base.BaseTestCase):
def test_check_and_truncate_name_with_none(self):
name = None
result = nvplib._check_and_truncate_name(name)
self.assertEqual('', result)
def test_check_and_truncate_name_with_short_name(self):
name = 'foo_port_name'
result = nvplib._check_and_truncate_name(name)
self.assertEqual(name, result)
def test_check_and_truncate_name_long_name(self):
name = 'this_is_a_port_whose_name_is_longer_than_40_chars'
result = nvplib._check_and_truncate_name(name)
self.assertEqual(len(result), nvplib.MAX_DISPLAY_NAME_LEN)
def _nicira_method(method_name, module_name='nvplib'):
return '%s.%s.%s' % ('neutron.plugins.nicira', module_name, method_name)