Bugfix to enable CapabilityTypeDef to consider custom definitions

Change-Id: Ib5d4ad68d1d6a35fe40d441f6d5d4460a8a3fbbe
Related-Bug: 1545703
This commit is contained in:
Miguel Caballer 2016-02-15 13:57:26 +01:00
parent ae185f4ae8
commit eea4827476
4 changed files with 47 additions and 3 deletions

View File

@ -25,7 +25,7 @@ class CapabilityTypeDef(StatefulEntityType):
self.properties = None
if self.PROPERTIES in self.defs:
self.properties = self.defs[self.PROPERTIES]
self.parent_capabilities = self._get_parent_capabilities()
self.parent_capabilities = self._get_parent_capabilities(custom_def)
def get_properties_def_objects(self):
'''Return a list of property definition objects.'''
@ -57,12 +57,15 @@ class CapabilityTypeDef(StatefulEntityType):
if props_def and name in props_def:
return props_def[name].value
def _get_parent_capabilities(self):
def _get_parent_capabilities(self, custom_def=None):
capabilities = {}
parent_cap = self.parent_type
if parent_cap:
while parent_cap != 'tosca.capabilities.Root':
capabilities[parent_cap] = self.TOSCA_DEF[parent_cap]
if parent_cap in self.TOSCA_DEF.keys():
capabilities[parent_cap] = self.TOSCA_DEF[parent_cap]
elif custom_def and parent_cap in custom_def.keys():
capabilities[parent_cap] = custom_def[parent_cap]
parent_cap = capabilities[parent_cap]['derived_from']
return capabilities

View File

@ -0,0 +1,22 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Definition of a node with a capiblity and a parent capability
defined in an imported file
capability_types:
tosca.capabilities.SomeCap:
derived_from: tosca.capabilities.Root
tosca.capabilities.SomeChildCap:
derived_from: tosca.capabilities.SomeCap
node_types:
tosca.nodes.SomeNode:
derived_from: tosca.nodes.Root
capabilities:
lrms:
type: tosca.capabilities.SomeChildCap

View File

@ -0,0 +1,13 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA simple profile to test a custom defined capability
imports:
- custom_types/custom_caps_def.yaml
topology_template:
node_templates:
server:
type: tosca.nodes.SomeNode

View File

@ -710,3 +710,9 @@ class ToscaTemplateTest(TestCase):
os.path.dirname(os.path.abspath(__file__)),
"data/test_repositories_definition.yaml")
ToscaTemplate(tosca_tpl)
def test_custom_caps_def(self):
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/test_custom_caps_def.yaml")
ToscaTemplate(tosca_tpl)