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)