Fix error raising exception when importing a file with an invalid template version

Change-Id: I31a0c1b477d8f8f234457021235f35c4bb9fee4d
This commit is contained in:
Miguel Caballer 2018-01-31 09:45:58 +01:00
parent 784227cce4
commit 23cd991e88
4 changed files with 34 additions and 2 deletions

View File

@ -48,12 +48,12 @@ class TypeValidation(object):
for name in custom_type:
if name not in self.ALLOWED_TYPE_SECTIONS:
ExceptionCollector.appendException(
UnknownFieldError(what='Template ' + (self.import_def),
UnknownFieldError(what='Template ' + str(self.import_def),
field=name))
def _validate_type_version(self, version):
if version not in self.VALID_TEMPLATE_VERSIONS:
ExceptionCollector.appendException(
InvalidTemplateVersion(
what=version + ' in ' + self.import_def,
what=version + ' in ' + str(self.import_def),
valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS)))

View File

@ -0,0 +1,7 @@
tosca_definitions_version: tosca_simple_yaml_XXX
node_types:
tosca.nodes.SomeNode:
derived_from: tosca.nodes.SoftwareComponent

View File

@ -0,0 +1,13 @@
tosca_definitions_version: tosca_simple_yaml_1_0
imports:
- invalid: custom_types/invalid_template_version.yaml
description: >
Test to import a template with an invalid template version.
topology_template:
node_templates:
test:
type: tosca.nodes.SomeNode

View File

@ -1441,6 +1441,18 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
(_('The template version "tosca_xyz" is invalid. Valid versions '
'are "%s".') % valid_versions))
def test_import_invalid_template_version(self):
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/test_import_invalid_template_version.yaml")
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
exception.ExceptionCollector.assertExceptionMessage(
exception.InvalidTemplateVersion,
(_('The template version "tosca_simple_yaml_XXX in '
'{\'invalid\': \'custom_types/invalid_template_version.yaml\'}"'
' is invalid. Valid versions are "%s".') % valid_versions))
def test_node_template_capabilities_properties(self):
# validating capability property values
tpl_snippet = '''