Merge "Allow special keywords in TOSCA template"

This commit is contained in:
Jenkins
2015-09-28 21:52:33 +00:00
committed by Gerrit Code Review
5 changed files with 32 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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