Solves an error in the _create_interfaces function in case of custom relationships defined in TOSCA document.
Change-Id: Id780d8a3ddea6f85bc555644b933c1782d7d98e2 Related-Bug: 1551608
This commit is contained in:
@@ -283,16 +283,19 @@ class EntityTemplate(object):
|
||||
type_interfaces = None
|
||||
if isinstance(self.type_definition, RelationshipType):
|
||||
if isinstance(self.entity_tpl, dict):
|
||||
for rel_def, value in self.entity_tpl.items():
|
||||
if rel_def != 'type':
|
||||
rel_def = self.entity_tpl.get(rel_def)
|
||||
rel = None
|
||||
if isinstance(rel_def, dict):
|
||||
rel = rel_def.get('relationship')
|
||||
if rel:
|
||||
if self.INTERFACES in rel:
|
||||
type_interfaces = rel[self.INTERFACES]
|
||||
break
|
||||
if self.INTERFACES in self.entity_tpl:
|
||||
type_interfaces = self.entity_tpl[self.INTERFACES]
|
||||
else:
|
||||
for rel_def, value in self.entity_tpl.items():
|
||||
if rel_def != 'type':
|
||||
rel_def = self.entity_tpl.get(rel_def)
|
||||
rel = None
|
||||
if isinstance(rel_def, dict):
|
||||
rel = rel_def.get('relationship')
|
||||
if rel:
|
||||
if self.INTERFACES in rel:
|
||||
type_interfaces = rel[self.INTERFACES]
|
||||
break
|
||||
else:
|
||||
type_interfaces = self.type_definition.get_value(self.INTERFACES,
|
||||
self.entity_tpl)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: Test template of a custom relationship with a configure script
|
||||
|
||||
topology_template:
|
||||
|
||||
node_templates:
|
||||
apache:
|
||||
type: tosca.nodes.WebServer
|
||||
requirements:
|
||||
- host:
|
||||
node: web_server
|
||||
relationship: my_custom_rel
|
||||
|
||||
web_server:
|
||||
type: tosca.nodes.Compute
|
||||
|
||||
relationship_templates:
|
||||
my_custom_rel:
|
||||
type: HostedOn
|
||||
interfaces:
|
||||
Configure:
|
||||
pre_configure_source: scripts/wp_db_configure.sh
|
||||
@@ -716,3 +716,12 @@ class ToscaTemplateTest(TestCase):
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_custom_caps_def.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_custom_rel_with_script(self):
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_tosca_custom_rel_with_script.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
rel = tosca.relationship_templates[0]
|
||||
self.assertEqual(len(rel.interfaces), 1)
|
||||
self.assertEqual(rel.interfaces[0].type, "Configure")
|
||||
|
||||
Reference in New Issue
Block a user