[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
This commit is contained in:
Janet Yu 2015-12-18 19:08:10 -08:00
parent 5488dd47f8
commit 32d1b92f18
3 changed files with 16 additions and 12 deletions

View File

@ -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:<tenant-id>, os-api-version:<neutron-api-version>,
<resoutce>:<resource-id>, os-project-name:<project-name>
Add <resource_type>:<resource-id>, os-project-id:<tenant-id>,
os-project-name:<project_name> os-api-version:<neutron-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',

View File

@ -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"))

View File

@ -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)