Merge "Bugfix to enable CapabilityTypeDef to consider custom definitions"
This commit is contained in:
commit
b22b7c7bd7
@ -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
|
||||
|
||||
|
22
toscaparser/tests/data/custom_types/custom_caps_def.yaml
Normal file
22
toscaparser/tests/data/custom_types/custom_caps_def.yaml
Normal 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
|
||||
|
13
toscaparser/tests/data/test_custom_caps_def.yaml
Normal file
13
toscaparser/tests/data/test_custom_caps_def.yaml
Normal 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
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user