diff --git a/toscaparser/functions.py b/toscaparser/functions.py index b64f1bc2..935e965d 100644 --- a/toscaparser/functions.py +++ b/toscaparser/functions.py @@ -246,6 +246,15 @@ class GetAttribute(Function): target_name) def _find_node_template(self, node_template_name): + # if the node_template_name has the long format + if isinstance(node_template_name, dict): + # get only the node name + if 'node' in node_template_name: + node_template_name = node_template_name['node'] + else: + ExceptionCollector.appendException( + ValueError(_(' No node name in the relationship.'))) + return if node_template_name == HOST: # Currently this is the only way to tell whether the function # is used within the outputs section of the TOSCA template. @@ -479,6 +488,15 @@ class GetProperty(Function): return found[0] def _find_node_template(self, node_template_name): + # if the node_template_name has the long format + if isinstance(node_template_name, dict): + # get only the node name + if 'node' in node_template_name: + node_template_name = node_template_name['node'] + else: + ExceptionCollector.appendException( + ValueError(_(' No node name in the relationship.'))) + return if node_template_name == SELF: return self.context # enable the HOST value in the function diff --git a/toscaparser/tests/data/test_long_rel.yaml b/toscaparser/tests/data/test_long_rel.yaml new file mode 100644 index 00000000..8a0b0c9d --- /dev/null +++ b/toscaparser/tests/data/test_long_rel.yaml @@ -0,0 +1,28 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile to test a relatinship in log format + +node_types: + + tosca.nodes.SomeSoftwareComponent: + derived_from: tosca.nodes.SoftwareComponent + properties: + test: + type: string + +topology_template: + + node_templates: + + some: + type: tosca.nodes.SomeSoftwareComponent + properties: + test: { get_attribute: [ HOST, private_address ] } + requirements: + - host: + node: server + capability: tosca.capabilities.Container + relationship: tosca.relationships.HostedOn + + server: + type: tosca.nodes.Compute diff --git a/toscaparser/tests/test_toscatplvalidation.py b/toscaparser/tests/test_toscatplvalidation.py index d4bf4f0f..d4abe3ef 100644 --- a/toscaparser/tests/test_toscatplvalidation.py +++ b/toscaparser/tests/test_toscatplvalidation.py @@ -1864,3 +1864,9 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml os.path.dirname(os.path.abspath(__file__)), "data/test_normative_type_properties_override.yaml") self.assertIsNotNone(ToscaTemplate(tpl_path)) + + def test_long_rel(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_long_rel.yaml") + self.assertIsNotNone(ToscaTemplate(tpl_path))