From ce351637edc05704ff0df86fee4a12026cc9b282 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 30 Dec 2015 00:46:56 -0800 Subject: [PATCH] NSX|V3: ensure that tag length does not exceed 40 characters This is alimitation on the backend platforms. Change-Id: Ic26525a4eca8114d31abe484a1c2c4075889e675 Closes-bug: #1530058 --- vmware_nsx/common/utils.py | 9 +++++---- vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 5c9db4febe..6c9c031c6f 100644 --- a/vmware_nsx/common/utils.py +++ b/vmware_nsx/common/utils.py @@ -29,6 +29,7 @@ LOG = log.getLogger(__name__) MAX_DISPLAY_NAME_LEN = 40 MAX_RESOURCE_TYPE_LEN = 20 +MAX_TAG_LEN = 40 NEUTRON_VERSION = version.version_info.release_string() NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin' OS_NEUTRON_ID_SCOPE = 'os-neutron-id' @@ -132,13 +133,13 @@ def build_v3_tags_payload(resource, resource_type, project_name): if not project_name: project_name = 'NSX Neutron plugin' return [{'scope': resource_type, - 'tag': resource.get('id', '')}, + 'tag': resource.get('id', '')[:MAX_TAG_LEN]}, {'scope': 'os-project-id', - 'tag': resource.get('tenant_id', '')}, + 'tag': resource.get('tenant_id', '')[:MAX_TAG_LEN]}, {'scope': 'os-project-name', - 'tag': project_name}, + 'tag': project_name[:MAX_TAG_LEN]}, {'scope': 'os-api-version', - 'tag': version.version_info.release_string()}] + 'tag': version.version_info.release_string()[:MAX_TAG_LEN]}] def retry_upon_exception_nsxv3(exc, delay=500, max_delay=2000, diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index fe9783dee3..983e594e53 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -451,3 +451,16 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin): expected = '%s%s' % ('X' * (80 - len(suffix)), suffix) short_name = utils.get_name_and_uuid(name, uuid) self.assertEqual(expected, short_name) + + def test_build_v3_tags_max_length_payload(self): + result = utils.build_v3_tags_payload( + {'id': 'X' * 255, + 'tenant_id': 'X' * 255}, + resource_type='os-neutron-net-id', + project_name='X' * 255) + expected = [{'scope': 'os-neutron-net-id', 'tag': 'X' * 40}, + {'scope': 'os-project-id', 'tag': 'X' * 40}, + {'scope': 'os-project-name', 'tag': 'X' * 40}, + {'scope': 'os-api-version', + 'tag': version.version_info.release_string()}] + self.assertEqual(expected, result)