Allow special keywords in TOSCA template
Allow certain keywords, which are not part of specification but most likely be added in future, which are in use by TOSCA users to pass validation in template. Change-Id: I9064ba239ae12121dc2cc17a3a5b8d35586caac0
This commit is contained in:
parent
52560534ef
commit
b2f6e8137e
|
@ -32,6 +32,8 @@ class EntityTemplate(object):
|
|||
REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES) = \
|
||||
('node', 'capability', 'relationship',
|
||||
'occurrences')
|
||||
# Special key names
|
||||
SPECIAL_SECTIONS = (METADATA) = ('metadata')
|
||||
|
||||
def __init__(self, name, template, entity_name, custom_def=None):
|
||||
self.name = name
|
||||
|
|
|
@ -234,6 +234,6 @@ class NodeTemplate(EntityTemplate):
|
|||
|
||||
def _validate_fields(self, nodetemplate):
|
||||
for name in nodetemplate.keys():
|
||||
if name not in self.SECTIONS:
|
||||
if name not in self.SECTIONS and name not in self.SPECIAL_SECTIONS:
|
||||
raise UnknownFieldError(what='Node template %s'
|
||||
% self.name, field=name)
|
||||
|
|
|
@ -3,6 +3,8 @@ tosca_definitions_version: tosca_simple_yaml_1_0
|
|||
description: >
|
||||
Tosca template for testing a template with no inputs.
|
||||
|
||||
metadata: test
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
server:
|
||||
|
|
|
@ -1093,3 +1093,27 @@ custom_types/wordpress.yaml
|
|||
ValueError,
|
||||
lambda: self._single_node_template_content_test(tpl_snippet))
|
||||
self.assertEqual(expectedmessage, err.__str__())
|
||||
|
||||
def test_special_keywords(self):
|
||||
"""Test special keywords
|
||||
|
||||
Test that special keywords, e.g. metadata, which are not part
|
||||
of specification do not throw any validation error.
|
||||
"""
|
||||
tpl_snippet_metadata_map = '''
|
||||
node_templates:
|
||||
server:
|
||||
type: tosca.nodes.Compute
|
||||
metadata:
|
||||
name: server A
|
||||
role: master
|
||||
'''
|
||||
self._single_node_template_content_test(tpl_snippet_metadata_map)
|
||||
|
||||
tpl_snippet_metadata_inline = '''
|
||||
node_templates:
|
||||
server:
|
||||
type: tosca.nodes.Compute
|
||||
metadata: none
|
||||
'''
|
||||
self._single_node_template_content_test(tpl_snippet_metadata_inline)
|
||||
|
|
|
@ -35,6 +35,8 @@ SECTIONS = (DEFINITION_VERSION, DEFAULT_NAMESPACE, TEMPLATE_NAME,
|
|||
'template_version', 'description', 'imports', 'dsl_definitions',
|
||||
'node_types', 'relationship_types', 'relationship_templates',
|
||||
'capability_types', 'artifact_types', 'datatype_definitions')
|
||||
# Special key names
|
||||
SPECIAL_SECTIONS = (METADATA) = ('metadata')
|
||||
|
||||
log = logging.getLogger("tosca.model")
|
||||
|
||||
|
@ -141,7 +143,7 @@ class ToscaTemplate(object):
|
|||
raise MissingRequiredFieldError(what='Template',
|
||||
required=DEFINITION_VERSION)
|
||||
for name in self.tpl:
|
||||
if name not in SECTIONS:
|
||||
if name not in SECTIONS and name not in SPECIAL_SECTIONS:
|
||||
raise UnknownFieldError(what='Template', field=name)
|
||||
|
||||
def _validate_version(self, version):
|
||||
|
|
Loading…
Reference in New Issue