summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/release/userguide/feature.userguide.rst2
-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/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
7 files changed, 63 insertions, 4 deletions
diff --git a/docs/release/userguide/feature.userguide.rst b/docs/release/userguide/feature.userguide.rst
index 4d0d46e..4ad4f22 100644
--- a/docs/release/userguide/feature.userguide.rst
+++ b/docs/release/userguide/feature.userguide.rst
@@ -71,7 +71,7 @@ Using api, which is used to parse and get the result of service template. it can
ToscaTemplate(path=None, parsed_params=None, a_file=True, yaml_dict_tpl=None,
sub_mapped_node_template=None,
- no_required_paras_valid=False, debug=False )
+ no_required_paras_valid=False, debug=False)
REST API
*********
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/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 = '''