diff --git a/toscaparser/nodetemplate.py b/toscaparser/nodetemplate.py index b3fbf5c4..3991f059 100644 --- a/toscaparser/nodetemplate.py +++ b/toscaparser/nodetemplate.py @@ -102,13 +102,14 @@ class NodeTemplate(EntityTemplate): if relationship: found_relationship_tpl = False # apply available relationship templates if found - for tpl in self.available_rel_tpls: - if tpl.name == relationship: - rtype = RelationshipType(tpl.type, None, - self.custom_def) - explicit_relation[rtype] = related_tpl - self.relationship_tpl.append(tpl) - found_relationship_tpl = True + if self.available_rel_tpls: + for tpl in self.available_rel_tpls: + if tpl.name == relationship: + rtype = RelationshipType(tpl.type, None, + self.custom_def) + explicit_relation[rtype] = related_tpl + self.relationship_tpl.append(tpl) + found_relationship_tpl = True # create relationship template object. rel_prfx = self.type_definition.RELATIONSHIP_PREFIX if not found_relationship_tpl: diff --git a/toscaparser/tests/data/test_available_rel_tpls.yaml b/toscaparser/tests/data/test_available_rel_tpls.yaml new file mode 100644 index 00000000..e8d90450 --- /dev/null +++ b/toscaparser/tests/data/test_available_rel_tpls.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA test for bug 1527214 + +topology_template: + + node_templates: + + test_db: + type: tosca.nodes.Database + requirements: + - host: + node: mysql + + mysql: + type: tosca.nodes.DBMS + requirements: + - host: + node: db_server + + db_server: + type: tosca.nodes.Compute + diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index 4a32dad0..064cb16c 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -544,3 +544,15 @@ class ToscaTemplateTest(TestCase): "data/CSAR/csar_elk.csar") tosca = ToscaTemplate(tosca_tpl) self.assertTrue(tosca.topology_template.custom_defs) + + def test_available_rel_tpls(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_available_rel_tpls.yaml") + tosca = ToscaTemplate(tosca_tpl) + for node in tosca.nodetemplates: + for relationship, target in node.relationships.items(): + try: + target.relationships + except TypeError as error: + self.fail(error)