Add validation for implicit attribute reference
TOSCA attributes can be explicit as part of the type definition or can be used as implicit via property name. Handle missing implicit attribute validation with get_attribute function. Change-Id: I639d819dd55ee828600e6d78a59ab92c3c6e14c3 Closes-Bug: #1622573
This commit is contained in:
parent
780026da63
commit
5f762c51ae
toscaparser
@ -207,10 +207,13 @@ class GetAttribute(Function):
|
||||
"""
|
||||
return self._find_node_template_containing_attribute()
|
||||
|
||||
# Attributes can be explicitly created as part of the type definition
|
||||
# or a property name can be implicitly used as an attribute name
|
||||
def _find_node_template_containing_attribute(self):
|
||||
node_tpl = self._find_node_template(self.args[0])
|
||||
if node_tpl and \
|
||||
not self._attribute_exists_in_type(node_tpl.type_definition):
|
||||
not self._attribute_exists_in_type(node_tpl.type_definition) \
|
||||
and self.attribute_name not in node_tpl.get_properties():
|
||||
ExceptionCollector.appendException(
|
||||
KeyError(_('Attribute "%(att)s" was not found in node '
|
||||
'template "%(ntpl)s".') %
|
||||
|
@ -0,0 +1,25 @@
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: >
|
||||
Attribute can be defined explicitly as part of type definition
|
||||
or implicitly via property. This TOSCA template tests validation
|
||||
of attribute name implicitly created as a property and referenced
|
||||
via get_attribute function.
|
||||
|
||||
node_types:
|
||||
ServerNode:
|
||||
derived_from: SoftwareComponent
|
||||
properties:
|
||||
notification_port:
|
||||
type: integer
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
my_server:
|
||||
type: ServerNode
|
||||
properties:
|
||||
notification_port: 8000
|
||||
|
||||
outputs:
|
||||
ip_address:
|
||||
value: { get_attribute: [ my_server, notification_port ] }
|
@ -314,6 +314,10 @@ class GetAttributeTest(TestCase):
|
||||
self._load_template(
|
||||
'functions/test_get_attribute_with_nested_params.yaml')
|
||||
|
||||
def test_implicit_attribute(self):
|
||||
self.assertIsNotNone(self._load_template(
|
||||
'functions/test_get_implicit_attribute.yaml'))
|
||||
|
||||
|
||||
class ConcatTest(TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user