summaryrefslogtreecommitdiffstats
path: root/tosca2heat
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/common/exception.py10
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py2
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py4
-rw-r--r--tosca2heat/tosca-parser/toscaparser/shell.py9
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/invalid_type.yaml8
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/test_import_invalid_type.yaml11
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_properties.py29
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py11
8 files changed, 74 insertions, 10 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/common/exception.py b/tosca2heat/tosca-parser/toscaparser/common/exception.py
index 67a9f7f..d36a714 100644
--- a/tosca2heat/tosca-parser/toscaparser/common/exception.py
+++ b/tosca2heat/tosca-parser/toscaparser/common/exception.py
@@ -207,10 +207,14 @@ class ExceptionCollector(object):
@staticmethod
def removeException(exception_type):
- if ExceptionCollector.collecting and ExceptionCollector.exceptions:
+ # if ExceptionCollector.collecting and ExceptionCollector.exceptions:
+ if ExceptionCollector.exceptions:
+ tmp_exceptions = []
for i, e in enumerate(ExceptionCollector.exceptions):
- if isinstance(e, exception_type):
- del ExceptionCollector.exceptions[i]
+ if not isinstance(e, exception_type):
+ tmp_exceptions.append(e)
+ # del ExceptionCollector.exceptions[i]
+ ExceptionCollector.exceptions = tmp_exceptions
@staticmethod
def exceptionsCaught():
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py b/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
index 23c5afc..c37aa9d 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
@@ -35,7 +35,7 @@ class CapabilityTypeDef(StatefulEntityType):
parent_properties = {}
if self.parent_capabilities:
for type, value in self.parent_capabilities.items():
- parent_properties[type] = value.get('properties')
+ parent_properties[type] = value.get('properties', {})
if self.properties:
for prop, schema in self.properties.items():
properties.append(PropertyDef(prop, None, schema))
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py b/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py
index 89a6a03..8b49f48 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py
@@ -49,12 +49,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)))
diff --git a/tosca2heat/tosca-parser/toscaparser/shell.py b/tosca2heat/tosca-parser/toscaparser/shell.py
index 88c7473..c024d1e 100644
--- a/tosca2heat/tosca-parser/toscaparser/shell.py
+++ b/tosca2heat/tosca-parser/toscaparser/shell.py
@@ -53,7 +53,7 @@ class ParserShell(object):
required=True,
help=_('YAML template or CSAR file to parse.'))
- parser.add_argument('-nrpv', dest='no_required_paras_check',
+ parser.add_argument('--nrpv', dest='no_required_paras_check',
action='store_true', default=False,
help=_('Ignore input parameter validation '
'when parse template.'))
@@ -97,9 +97,10 @@ class ParserShell(object):
else:
raise e
- version = tosca.version if tosca else "unknown"
- if tosca and tosca.version:
- print("\nversion: " + version)
+ if tosca and hasattr(tosca, 'version'):
+ print("\nversion: " + tosca.version)
+ else:
+ print("\nversion: " + "unknown")
if tosca and hasattr(tosca, 'description'):
description = tosca.description
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/invalid_type.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/invalid_type.yaml
new file mode 100644
index 0000000..4d3a0b0
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/invalid_type.yaml
@@ -0,0 +1,8 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+
+annotation_types:
+ org.openecomp.annotations.Source:
+ description: Indicates the origin source of an input
+ properties:
+ source_type:
+ type: string
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/test_import_invalid_type.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/test_import_invalid_type.yaml
new file mode 100644
index 0000000..f2c1876
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/test_import_invalid_type.yaml
@@ -0,0 +1,11 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+
+imports:
+ - invalid: custom_types/invalid_type.yaml
+
+description: Test to import a template with an invalid type.
+
+topology_template:
+ node_templates:
+ test:
+ type: tosca.nodes.Root
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_properties.py b/tosca2heat/tosca-parser/toscaparser/tests/test_properties.py
index 6b95537..faa8af4 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_properties.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_properties.py
@@ -314,6 +314,31 @@ class PropertyTest(TestCase):
num_cpus: 1
'''
+ tosca_custom_def_example3 = '''
+ tosca.capabilities.New:
+ derived_from: tosca.capabilities.Node
+ properties:
+ test_case:
+ type: integer
+ required: yes
+
+ tosca.nodes.ComputeNew:
+ derived_from: tosca.nodes.Compute
+ capabilities:
+ scalable:
+ type: tosca.capabilities.New
+ '''
+
+ tosca_node_template_example3 = '''
+ node_templates:
+ compute_instance:
+ type: tosca.nodes.ComputeNew
+ capabilities:
+ scalable:
+ properties:
+ test_case: 1
+ '''
+
tpl1 = self._get_nodetemplate(tosca_node_template_example1,
tosca_custom_def_example1)
self.assertIsNone(tpl1.validate())
@@ -322,6 +347,10 @@ class PropertyTest(TestCase):
tosca_custom_def_example2)
self.assertIsNone(tpl2.validate())
+ tpl3 = self._get_nodetemplate(tosca_node_template_example3,
+ tosca_custom_def_example3)
+ self.assertIsNone(tpl3.validate())
+
def _get_nodetemplate(self, tpl_snippet,
custom_def_snippet=None):
nodetemplates = yamlparser.\
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
index a8b1590..ea27bcb 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
@@ -1442,6 +1442,17 @@ 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_type(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/test_import_invalid_type.yaml")
+ self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
+ exception.ExceptionCollector.assertExceptionMessage(
+ exception.UnknownFieldError,
+ (_("Template {'invalid': 'custom_types/invalid_type.yaml'} "
+ 'contains unknown field "annotation_types". Refer to the '
+ 'definition to verify valid values.')))
+
def test_node_template_capabilities_properties(self):
# validating capability property values
tpl_snippet = '''