Fix error not considering inheritance in valid_target_types checking in functions

Change-Id: Ifcf0ce478450340597fc112a87c367f5b832faca
Related-Bug: #1672989
This commit is contained in:
Miguel Caballer 2017-03-15 09:50:34 +01:00
parent 0f2e5a5543
commit c71c7d37b2
5 changed files with 82 additions and 3 deletions

View File

@ -81,3 +81,16 @@ class CapabilityTypeDef(StatefulEntityType):
if pnode:
return CapabilityTypeDef(self.name, pnode,
self.nodetype, self.custom_def)
def inherits_from(self, type_names):
'''Check this capability is in type_names
Check if this capability or some of its parent types
are in the list of types: type_names
'''
if self.type in type_names:
return True
elif self.parent_type:
return self.parent_type.inherits_from(type_names)
else:
return False

View File

@ -236,8 +236,8 @@ class GetAttribute(Function):
target_node = self._find_node_template(target_name)
target_type = target_node.type_definition
for capability in target_type.get_capabilities_objects():
if capability.type in \
hosted_on_rel['valid_target_types']:
if capability.inherits_from(
hosted_on_rel['valid_target_types']):
if self._attribute_exists_in_type(target_type):
return target_node
return self._find_host_containing_attribute(
@ -555,7 +555,8 @@ class GetProperty(Function):
target_node = self._find_node_template(target_name)
target_type = target_node.type_definition
for capability in target_type.get_capabilities_objects():
if capability.type in hosted_on_rel['valid_target_types']:
if capability.inherits_from(
hosted_on_rel['valid_target_types']):
if self._property_exists_in_type(target_type):
return target_node
return self._find_host_containing_property(

View File

@ -0,0 +1,33 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Define a capability class that inherits from tosca.capabilities.Container
capability_types:
tosca.capabilities.ContainerChild:
derived_from: tosca.capabilities.Container
node_types:
tosca.nodes.SomeNode:
derived_from: tosca.nodes.Root
properties:
some_prop:
type: string
requirements:
- host_child:
capability: tosca.capabilities.ContainerChild
node: tosca.nodes.SomeNode2
relationship: tosca.relationships.HostedOn
tosca.nodes.SomeNode2:
derived_from: tosca.nodes.Root
capabilities:
host_child:
type: tosca.capabilities.ContainerChild
requirements:
- host:
capability: tosca.capabilities.Container
node: tosca.nodes.Compute
relationship: tosca.relationships.HostedOn

View File

@ -0,0 +1,28 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile to test the get attribute function with HOST parameter
using a node that has as capability a child class of Container
imports:
- ../custom_types/container_cap_child.yaml
topology_template:
node_templates:
test_node:
type: tosca.nodes.SomeNode
properties:
some_prop: { get_attribute: [ HOST, public_address ] }
requirements:
- host_child: test_node2
test_node2:
type: tosca.nodes.SomeNode2
requirements:
- host: server
server:
type: tosca.nodes.Compute

View File

@ -318,6 +318,10 @@ class GetAttributeTest(TestCase):
self.assertIsNotNone(self._load_template(
'functions/test_get_implicit_attribute.yaml'))
def test_get_attribute_capability_inheritance(self):
self.assertIsNotNone(self._load_template(
'functions/test_container_cap_child.yaml'))
class ConcatTest(TestCase):