Fix InvalidTypeError in get_attribute function
Fix InvalidTypeError is raised when a custom def datatype attribute is requested in a function. It only required to add custom defs in the DataType validation. Closes-Bug: 1964972 Change-Id: Ie3413c6d6ba86d0fd5eb819dfc9770b8211badc6
This commit is contained in:
parent
c63e17a7a3
commit
4533792d10
@ -179,7 +179,8 @@ class GetAttribute(Function):
|
||||
).format(GET_ATTRIBUTE, elem)))
|
||||
return
|
||||
else: # It is a complex type
|
||||
data_type = DataType(value_type)
|
||||
data_type = DataType(value_type,
|
||||
self.tosca_tpl.custom_defs)
|
||||
props = data_type.get_all_properties()
|
||||
found = [props[elem]] if elem in props else []
|
||||
if found:
|
||||
|
21
toscaparser/tests/data/custom_types/custom_data_type.yaml
Normal file
21
toscaparser/tests/data/custom_types/custom_data_type.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
data_types:
|
||||
|
||||
tosca.datatypes.SomeType:
|
||||
derived_from: tosca.datatypes.Root
|
||||
properties:
|
||||
tasks:
|
||||
type: map
|
||||
entry_schema:
|
||||
type: string
|
||||
|
||||
node_types:
|
||||
|
||||
tosca.nodes.SomeApp:
|
||||
derived_from: tosca.nodes.SoftwareComponent
|
||||
attributes:
|
||||
some_new_att:
|
||||
type: map
|
||||
entry_schema:
|
||||
type: tosca.datatypes.SomeType
|
@ -0,0 +1,36 @@
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: Template for testing get_attribute with a custom data type
|
||||
|
||||
imports:
|
||||
- ../custom_types/custom_data_type.yaml
|
||||
|
||||
topology_template:
|
||||
|
||||
node_templates:
|
||||
|
||||
some_app:
|
||||
type: tosca.nodes.SomeApp
|
||||
requirements:
|
||||
- host: server
|
||||
|
||||
server:
|
||||
type: tosca.nodes.Compute
|
||||
capabilities:
|
||||
# Host container properties
|
||||
host:
|
||||
properties:
|
||||
num_cpus: 2
|
||||
disk_size: 10 GB
|
||||
mem_size: 512 MB
|
||||
# Guest Operating System properties
|
||||
os:
|
||||
properties:
|
||||
# host Operating System image properties
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
distribution: RHEL
|
||||
version: 6.5
|
||||
outputs:
|
||||
url:
|
||||
value: { get_attribute: [ some_app, some_new_att, map_value, tasks, other_map ]}
|
@ -342,6 +342,10 @@ class GetAttributeTest(TestCase):
|
||||
self.assertIsNotNone(self._load_template(
|
||||
'functions/test_container_cap_child.yaml'))
|
||||
|
||||
def test_get_attribute_custom_data_type(self):
|
||||
self.assertIsNotNone(self._load_template(
|
||||
'functions/test_get_attribute_custom_data_type.yaml'))
|
||||
|
||||
|
||||
class ConcatTest(TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user