Merge "Fail to parse if relationship is not defined in requirements."

This commit is contained in:
Zuul 2020-01-21 12:33:56 +00:00 committed by Gerrit Code Review
commit 3242ea550e
3 changed files with 62 additions and 3 deletions

View File

@ -85,7 +85,8 @@ class NodeType(StatefulEntityType):
_get_node_type_by_cap(captype))
keyword = key
node_type = value
rtype = RelationshipType(relation, keyword, self.custom_def)
rtype = RelationshipType(relation, keyword,
self.custom_def)
relatednode = NodeType(node_type, self.custom_def)
relationship[rtype] = relatednode
return relationship

View File

@ -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

View File

@ -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'],