diff --git a/toscaparser/elements/nodetype.py b/toscaparser/elements/nodetype.py index 4889ed89..79b5cc1e 100644 --- a/toscaparser/elements/nodetype.py +++ b/toscaparser/elements/nodetype.py @@ -85,9 +85,10 @@ class NodeType(StatefulEntityType): _get_node_type_by_cap(captype)) keyword = key node_type = value - rtype = RelationshipType(relation, keyword, self.custom_def) - relatednode = NodeType(node_type, self.custom_def) - relationship[rtype] = relatednode + rtype = RelationshipType(relation, keyword, + self.custom_def) + relatednode = NodeType(node_type, self.custom_def) + relationship[rtype] = relatednode return relationship def _get_node_type_by_cap(self, cap): diff --git a/toscaparser/tests/data/test_nodetype_without_relationship.yaml b/toscaparser/tests/data/test_nodetype_without_relationship.yaml new file mode 100644 index 00000000..4487432d --- /dev/null +++ b/toscaparser/tests/data/test_nodetype_without_relationship.yaml @@ -0,0 +1,27 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Test NodeType which requirements has no relationship. + +node_types: + sample.SC: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - custom_host: + capability: tosca.capabilities.Attachment + node: tosca.nodes.Compute + +topology_template: + node_templates: + SampleSC1: + type: sample.SC + requirements: + - custom_host: Compute1 + Compute1: + type: tosca.nodes.Compute + SC2: + type: tosca.nodes.SoftwareComponent + requirements: + - host: Compute2 + Compute2: + type: tosca.nodes.Compute diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index 0349140f..d43f3a4d 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -148,6 +148,37 @@ class ToscaTemplateTest(TestCase): self.assertFalse( wordpress_node.is_derived_from("tosca.policies.Root")) + def test_nodetype_without_relationship(self): + # Nodes that contain "relationship" in "requirements" + depend_node_types = ( + "tosca.nodes.SoftwareComponent", + ) + + # Nodes that do not contain "relationship" in "requirements" + non_depend_node_types = ( + "tosca.nodes.Compute", + "sample.SC", + ) + + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_nodetype_without_relationship.yaml") + tosca = ToscaTemplate(tosca_tpl) + + nodetemplates = tosca.nodetemplates + for node in nodetemplates: + node_depend = node.related_nodes + if node_depend: + self.assertIn( + node.type, + depend_node_types + ) + else: + self.assertIn( + node.type, + non_depend_node_types + ) + def test_outputs(self): self.assertEqual( ['website_url'],