diff --git a/toscaparser/relationship_template.py b/toscaparser/relationship_template.py index b9656d41..db334c48 100644 --- a/toscaparser/relationship_template.py +++ b/toscaparser/relationship_template.py @@ -46,6 +46,13 @@ class RelationshipTemplate(EntityTemplate): props = [] properties = {} relationship = self.entity_tpl.get('relationship') + + if not relationship: + for value in self.entity_tpl.values(): + if isinstance(value, dict): + relationship = value.get('relationship') + break + if relationship: properties = self.type_definition.get_value(self.PROPERTIES, relationship) or {} diff --git a/toscaparser/tests/test_properties.py b/toscaparser/tests/test_properties.py index 6a4e4d18..a629f7c9 100644 --- a/toscaparser/tests/test_properties.py +++ b/toscaparser/tests/test_properties.py @@ -322,7 +322,43 @@ class PropertyTest(TestCase): custom_def_snippet=None): nodetemplates = yamlparser.\ simple_parse(tpl_snippet)['node_templates'] - custom_def = yamlparser.simple_parse(custom_def_snippet) + custom_def = [] + if custom_def_snippet: + custom_def = yamlparser.simple_parse(custom_def_snippet) name = list(nodetemplates.keys())[0] tpl = NodeTemplate(name, nodetemplates, custom_def) return tpl + + def test_explicit_relationship_proprety(self): + + tosca_node_template = ''' + node_templates: + + client_node: + type: tosca.nodes.Compute + requirements: + - local_storage: + node: my_storage + relationship: + type: AttachesTo + properties: + location: /mnt/disk + + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: 1 GB + ''' + + expected_properties = ['location'] + + nodetemplates = yamlparser.\ + simple_parse(tosca_node_template)['node_templates'] + tpl = NodeTemplate('client_node', nodetemplates, []) + + self.assertIsNone(tpl.validate()) + rel_tpls = [] + for relationship, trgt in tpl.relationships.items(): + rel_tpls.extend(trgt.get_relationship_template()) + self.assertEqual(expected_properties, + sorted(rel_tpls[0].get_properties().keys()))