From 57660b3cb36eb5d6625cba4ed98d8a9bb6c9f68f Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Thu, 10 Mar 2016 10:01:22 +0100 Subject: [PATCH] Bugfix for RelationshipTemplate._create_relationship_properties method to get the properties of the "explicit relationships" Change-Id: I325cc610b9792d89c31857da2d2bcd3bf525361a Related-Bug: 1555472 --- toscaparser/relationship_template.py | 7 +++++ toscaparser/tests/test_properties.py | 38 +++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/toscaparser/relationship_template.py b/toscaparser/relationship_template.py index d405b9c7..70b8ec8d 100644 --- a/toscaparser/relationship_template.py +++ b/toscaparser/relationship_template.py @@ -43,6 +43,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()))