From eea48274762897579ab04610c994a495a35fe3b2 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Mon, 15 Feb 2016 13:57:26 +0100 Subject: [PATCH] Bugfix to enable CapabilityTypeDef to consider custom definitions Change-Id: Ib5d4ad68d1d6a35fe40d441f6d5d4460a8a3fbbe Related-Bug: 1545703 --- toscaparser/elements/capabilitytype.py | 9 +++++--- .../data/custom_types/custom_caps_def.yaml | 22 +++++++++++++++++++ .../tests/data/test_custom_caps_def.yaml | 13 +++++++++++ toscaparser/tests/test_toscatpl.py | 6 +++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 toscaparser/tests/data/custom_types/custom_caps_def.yaml create mode 100644 toscaparser/tests/data/test_custom_caps_def.yaml diff --git a/toscaparser/elements/capabilitytype.py b/toscaparser/elements/capabilitytype.py index 2ac0c0e..0413443 100644 --- a/toscaparser/elements/capabilitytype.py +++ b/toscaparser/elements/capabilitytype.py @@ -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 diff --git a/toscaparser/tests/data/custom_types/custom_caps_def.yaml b/toscaparser/tests/data/custom_types/custom_caps_def.yaml new file mode 100644 index 0000000..337c38f --- /dev/null +++ b/toscaparser/tests/data/custom_types/custom_caps_def.yaml @@ -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 + diff --git a/toscaparser/tests/data/test_custom_caps_def.yaml b/toscaparser/tests/data/test_custom_caps_def.yaml new file mode 100644 index 0000000..0b0984a --- /dev/null +++ b/toscaparser/tests/data/test_custom_caps_def.yaml @@ -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 diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index 6dbf891..57fec45 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -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)