]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Prevents 400 NVP errors caused by a None display_name
authorarmando-migliaccio <amigliaccio@nicira.com>
Fri, 6 Sep 2013 19:57:48 +0000 (12:57 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Fri, 6 Sep 2013 20:59:18 +0000 (13:59 -0700)
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

neutron/plugins/nicira/nvplib.py
neutron/tests/unit/nicira/test_nvplib.py

index dd63d5bc3f01e8f5d53c4a373513a9651b5a723f..a65dfc08aab2655e3564c3853601d31c98bb103d 100644 (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):
index d7b815ae21c202dde9747c54301d0c4133bb1649..85cb948fb3c58f6c7b0934641a6d55e2d8619089 100644 (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)