From 32d1b92f1840c81455aa3e46254c257265aafc2b Mon Sep 17 00:00:00 2001 From: Janet Yu Date: Fri, 18 Dec 2015 19:08:10 -0800 Subject: [PATCH] [NSXv3] Add tags to qos switching profile Add resource type and project name tags to qos switching profile. Make maximum length of resource type name a constant. Fix some typos. Change-Id: Ibd793894ca65320fa5fcf49e5dfa1872f534b7fe --- vmware_nsx/common/utils.py | 16 ++++++++++------ vmware_nsx/services/qos/plugin.py | 6 +++--- vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 86ba0d02f2..93fb2afb24 100644 --- a/vmware_nsx/common/utils.py +++ b/vmware_nsx/common/utils.py @@ -27,6 +27,7 @@ from vmware_nsx._i18n import _, _LE LOG = log.getLogger(__name__) MAX_DISPLAY_NAME_LEN = 40 +MAX_RESOURCE_TYPE_LEN = 20 NEUTRON_VERSION = version.version_info.release_string() @@ -95,7 +96,7 @@ def build_v3_api_version_tag(): Neutron resource. """ return [{'scope': 'os-neutron-id', - 'tag': 'NSX neutron plug-in'}, + 'tag': 'NSX Neutron plugin'}, {'scope': "os-api-version", 'tag': version.version_info.release_string()}] @@ -103,16 +104,19 @@ def build_v3_api_version_tag(): def build_v3_tags_payload(resource, resource_type, project_name): """ Construct the tags payload that will be pushed to NSX-v3 - Add os-project-id:, os-api-version:, - :, os-project-name: + Add :, os-project-id:, + os-project-name: os-api-version: """ # Add in a validation to ensure that we catch this at build time - if len(resource_type) > 20: + if len(resource_type) > MAX_RESOURCE_TYPE_LEN: raise exceptions.InvalidInput( - error_message=_('scope cannot exceed 20 characters')) + error_message=(_('Tag scope name cannot exceed %(max_len)s ' + 'characters: %(scope)s') % + {'max_len': MAX_RESOURCE_TYPE_LEN, + 'scope': resource_type})) # There may be cases when the plugin creates the port, for example DHCP if not project_name: - project_name = 'NSX neutron plug-in' + project_name = 'NSX Neutron plugin' return [{'scope': resource_type, 'tag': resource.get('id', '')}, {'scope': 'os-project-id', diff --git a/vmware_nsx/services/qos/plugin.py b/vmware_nsx/services/qos/plugin.py index 3c41095636..7b81bb85ed 100644 --- a/vmware_nsx/services/qos/plugin.py +++ b/vmware_nsx/services/qos/plugin.py @@ -40,9 +40,9 @@ class NsxQosPlugin(qos_plugin.QoSPlugin): @db_base_plugin_common.convert_result_to_dict def create_policy(self, context, policy): - if 'tenant_name' not in policy['policy']: - policy['policy']['tenant_name'] = context.tenant_name - tags = utils.build_v3_tags_payload(policy['policy']) + tags = utils.build_v3_tags_payload( + policy['policy'], resource_type='os-neutron-qos-id', + project_name=context.tenant_name) result = nsxlib.create_qos_switching_profile( tags=tags, name=policy['policy'].get("name"), description=policy['policy'].get("description")) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index 9c6470da94..e0c77bc9d3 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -405,12 +405,12 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin): project_name=None) expected = [{'scope': 'os-neutron-net-id', 'tag': 'fake_id'}, {'scope': 'os-project-id', 'tag': 'fake_tenant_id'}, - {'scope': 'os-project-name', 'tag': 'NSX neutron plug-in'}, + {'scope': 'os-project-name', 'tag': 'NSX Neutron plugin'}, {'scope': 'os-api-version', 'tag': version.version_info.release_string()}] self.assertEqual(expected, result) - def test_build_v3_tags_payloadi_invalid_length(self): + def test_build_v3_tags_payload_invalid_length(self): self.assertRaises(n_exc.InvalidInput, utils.build_v3_tags_payload, {'id': 'fake_id', @@ -421,7 +421,7 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin): def test_build_v3_api_version_tag(self): result = utils.build_v3_api_version_tag() expected = [{'scope': 'os-neutron-id', - 'tag': 'NSX neutron plug-in'}, + 'tag': 'NSX Neutron plugin'}, {'scope': 'os-api-version', 'tag': version.version_info.release_string()}] self.assertEqual(expected, result)