From 7bea3b7c8b9c5d659973790486d38e57d9ad6939 Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Mon, 22 Apr 2019 13:48:41 +0800 Subject: toscaparser: Support deriving from capability types of no property Change-Id: I259a43b72a4dd3c74ad54a250ada9f913b5ce67b Issue-ID: PARSER-188 Signed-off-by: Lianhao Lu --- .../toscaparser/elements/capabilitytype.py | 2 +- .../toscaparser/tests/test_properties.py | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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/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.\ -- cgit 1.2.3-korg