diff --git a/toscaparser/elements/capabilitytype.py b/toscaparser/elements/capabilitytype.py index 5fa96615..dc36dd86 100644 --- a/toscaparser/elements/capabilitytype.py +++ b/toscaparser/elements/capabilitytype.py @@ -35,7 +35,8 @@ class CapabilityTypeDef(StatefulEntityType): parent_properties = {} if self.parent_capabilities: for type, value in self.parent_capabilities.items(): - parent_properties[type] = value.get('properties') + if self.PROPERTIES in value: + parent_properties[type] = value.get(self.PROPERTIES) if self.properties: for prop, schema in self.properties.items(): properties.append(PropertyDef(prop, None, schema)) diff --git a/toscaparser/tests/data/test_capability_without_properties.yaml b/toscaparser/tests/data/test_capability_without_properties.yaml new file mode 100644 index 00000000..88330c18 --- /dev/null +++ b/toscaparser/tests/data/test_capability_without_properties.yaml @@ -0,0 +1,36 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Test resources for which properties are not defined in + the parent of capabilitytype. + TestApp has capabilities->test_cap, + and the type of test_cap is TestCapabilityAA. + The parents of TestCapabilityAA is TestCapabilityA, + and TestCapabilityA has no properties. + +node_types: + tosca.nodes.WebApplication.TestApp: + derived_from: tosca.nodes.WebApplication + capabilities: + test_cap: + type: tosca.capabilities.TestCapabilityAA + + # Node whose parent is Root and does not have properties + tosca.capabilities.TestCapabilityA: + derived_from: tosca.capabilities.Root + + tosca.capabilities.TestCapabilityAA: + derived_from: tosca.capabilities.TestCapabilityA + properties: + test: + type: integer + required: false + +topology_template: + node_templates: + test_app: + type: tosca.nodes.WebApplication.TestApp + capabilities: + test_cap: + properties: + test: 1 diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index 512f3355..c472804d 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -439,6 +439,40 @@ class ToscaTemplateTest(TestCase): self.assertEqual('Type "tosca.capabilities.TestCapability" is not ' 'a valid type.', six.text_type(err)) + def test_capability_without_properties(self): + expected_version = "tosca_simple_yaml_1_0" + expected_description = \ + "Test resources for which properties are not defined in "\ + "the parent of capabilitytype. "\ + "TestApp has capabilities->test_cap, "\ + "and the type of test_cap is TestCapabilityAA. "\ + "The parents of TestCapabilityAA is TestCapabilityA, "\ + "and TestCapabilityA has no properties." + expected_nodetemplates = { + "test_app": { + "type": "tosca.nodes.WebApplication.TestApp", + "capabilities": { + "test_cap": { + "properties": { + "test": 1 + } + } + } + } + } + + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_capability_without_properties.yaml") + tosca = ToscaTemplate(tosca_tpl) + + self.assertEqual(expected_version, tosca.version) + self.assertEqual(expected_description, tosca.description) + self.assertEqual( + expected_nodetemplates, + tosca.nodetemplates[0].templates, + ) + def test_local_template_with_local_relpath_import(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)),