Fix error using get_attribute with HOST in case of setting host relationship in "long" format.

Change-Id: I7fefe31373bdc407599f1ebbf844c0a79aa0e241
Closes-Bug: 1779643
This commit is contained in:
Miguel Caballer 2018-07-02 13:16:04 +02:00
parent 3eb67e755d
commit c08022d0b7
3 changed files with 52 additions and 0 deletions

View File

@ -246,6 +246,15 @@ class GetAttribute(Function):
target_name) target_name)
def _find_node_template(self, node_template_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: if node_template_name == HOST:
# Currently this is the only way to tell whether the function # Currently this is the only way to tell whether the function
# is used within the outputs section of the TOSCA template. # is used within the outputs section of the TOSCA template.
@ -479,6 +488,15 @@ class GetProperty(Function):
return found[0] return found[0]
def _find_node_template(self, node_template_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 == SELF: if node_template_name == SELF:
return self.context return self.context
# enable the HOST value in the function # enable the HOST value in the function

View File

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

View File

@ -1864,3 +1864,9 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)),
"data/test_normative_type_properties_override.yaml") "data/test_normative_type_properties_override.yaml")
self.assertIsNotNone(ToscaTemplate(tpl_path)) 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))