Support version of tosca_simple_yaml_1_1
[parser.git] / tosca2heat / tosca-parser / toscaparser / tosca_template.py
index f48078f..ac534dc 100644 (file)
@@ -18,6 +18,7 @@ from copy import deepcopy
 from toscaparser.common.exception import ExceptionCollector
 from toscaparser.common.exception import InvalidTemplateVersion
 from toscaparser.common.exception import MissingRequiredFieldError
+from toscaparser.common.exception import MissingRequiredParameterError
 from toscaparser.common.exception import UnknownFieldError
 from toscaparser.common.exception import ValidationError
 from toscaparser.elements.entity_type import update_definitions
@@ -55,17 +56,20 @@ YAML_LOADER = toscaparser.utils.yamlparser.load_yaml
 class ToscaTemplate(object):
     exttools = ExtTools()
 
-    VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0']
+    VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0',
+                               'tosca_simple_yaml_1_1']
 
     VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions())
 
-    ADDITIONAL_SECTIONS = {'tosca_simple_yaml_1_0': SPECIAL_SECTIONS}
+    ADDITIONAL_SECTIONS = {'tosca_simple_yaml_1_0': SPECIAL_SECTIONS,
+                           'tosca_simple_yaml_1_1': SPECIAL_SECTIONS}
 
     ADDITIONAL_SECTIONS.update(exttools.get_sections())
 
     '''Load the template data.'''
     def __init__(self, path=None, parsed_params=None, a_file=True,
-                 yaml_dict_tpl=None, sub_mapped_node_template=None):
+                 yaml_dict_tpl=None, sub_mapped_node_template=None,
+                 no_required_paras_valid=False):
         if sub_mapped_node_template is None:
             ExceptionCollector.start()
         self.a_file = a_file
@@ -75,6 +79,7 @@ class ToscaTemplate(object):
         self.sub_mapped_node_template = sub_mapped_node_template
         self.nested_tosca_tpls_with_topology = {}
         self.nested_tosca_templates_with_topology = []
+        self.no_required_paras_valid = no_required_paras_valid
         if path:
             self.input_path = path
             self.path = self._get_path(path)
@@ -236,7 +241,8 @@ class ToscaTemplate(object):
                     nested_template = ToscaTemplate(
                         path=fname, parsed_params=parsed_params,
                         yaml_dict_tpl=tosca_tpl,
-                        sub_mapped_node_template=nodetemplate)
+                        sub_mapped_node_template=nodetemplate,
+                        no_required_paras_valid=self.no_required_paras_valid)
                     if nested_template._has_substitution_mappings():
                         # Record the nested templates in top level template
                         self.nested_tosca_templates_with_topology.\
@@ -268,11 +274,12 @@ class ToscaTemplate(object):
                     what=version,
                     valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS)))
         else:
-            if version != 'tosca_simple_yaml_1_0':
+            if (version != 'tosca_simple_yaml_1_0' and
+                    version != 'tosca_simple_yaml_1_1'):
                 update_definitions(version)
 
     def _get_path(self, path):
-        if path.lower().endswith('.yaml'):
+        if path.lower().endswith('.yaml') or path.lower().endswith('.yml'):
             return path
         elif path.lower().endswith(('.zip', '.csar')):
             # a CSAR archive
@@ -288,6 +295,10 @@ class ToscaTemplate(object):
 
     def verify_template(self):
         if ExceptionCollector.exceptionsCaught():
+            if self.no_required_paras_valid:
+                ExceptionCollector.removeException(
+                    MissingRequiredParameterError)
+
             if self.input_path:
                 raise ValidationError(
                     message=(_('\nThe input "%(path)s" failed validation with '