diff --git a/toscaparser/elements/TOSCA_definition_1_0.yaml b/toscaparser/elements/TOSCA_definition_1_0.yaml index 14158cd..3cb74b9 100644 --- a/toscaparser/elements/TOSCA_definition_1_0.yaml +++ b/toscaparser/elements/TOSCA_definition_1_0.yaml @@ -299,12 +299,14 @@ tosca.nodes.network.Port: attached to specific Compute node instance capability: tosca.capabilities.network.Bindable relationship: tosca.relationships.network.BindsTo + node: tosca.nodes.Compute - link: description: > Link requirement expresses the relationship between Port and Network nodes. It indicates which network this port will connect to. capability: tosca.capabilities.network.Linkable relationship: tosca.relationships.network.LinksTo + node: tosca.nodes.network.Network tosca.nodes.ObjectStorage: derived_from: tosca.nodes.Root diff --git a/toscaparser/elements/entity_type.py b/toscaparser/elements/entity_type.py index bd185c3..8e3a4d0 100644 --- a/toscaparser/elements/entity_type.py +++ b/toscaparser/elements/entity_type.py @@ -86,16 +86,27 @@ class EntityType(object): defs = self.defs if ndtype in defs: value = defs[ndtype] - if parent and not value: + if parent: p = self.parent_type - while value is None: - # check parent node - if not p: - break - if p and p.type == 'tosca.nodes.Root': - break - value = p.get_value(ndtype) - p = p.parent_type + if p: + while p.type != 'tosca.nodes.Root': + if p and p.type == 'tosca.nodes.Root': + break + if ndtype in p.defs: + # get the parent value + parent_value = p.defs[ndtype] + if value: + if isinstance(value, dict): + for k, v in parent_value.items(): + if k not in value.keys(): + value[k] = v + if isinstance(value, list): + for p_value in parent_value: + if p_value not in value: + value.append(p_value) + else: + value = parent_value + p = p.parent_type return value def get_definition(self, ndtype): diff --git a/toscaparser/elements/nodetype.py b/toscaparser/elements/nodetype.py index 8ddc5a2..2d545c7 100644 --- a/toscaparser/elements/nodetype.py +++ b/toscaparser/elements/nodetype.py @@ -128,7 +128,7 @@ class NodeType(StatefulEntityType): def get_capabilities_objects(self): '''Return a list of capability objects.''' typecapabilities = [] - caps = self.get_value(self.CAPABILITIES) + caps = self.get_value(self.CAPABILITIES, None, True) if caps is None: caps = self.get_value(self.CAPABILITIES, None, True) if caps: @@ -146,7 +146,7 @@ class NodeType(StatefulEntityType): @property def requirements(self): - return self.get_value(self.REQUIREMENTS) + return self.get_value(self.REQUIREMENTS, None, True) def get_all_requirements(self): requires = self.requirements diff --git a/toscaparser/tests/test_properties.py b/toscaparser/tests/test_properties.py index 79af9e2..beea3f3 100644 --- a/toscaparser/tests/test_properties.py +++ b/toscaparser/tests/test_properties.py @@ -192,7 +192,6 @@ class PropertyTest(TestCase): self.assertEqual(True, propertyInstance.required) def test_proprety_inheritance(self): - from toscaparser.nodetemplate import NodeTemplate tosca_custom_def = ''' tosca.nodes.SoftwareComponent.MySoftware: @@ -215,11 +214,7 @@ class PropertyTest(TestCase): expected_properties = ['component_version', 'install_path'] - nodetemplates = yamlparser.\ - simple_parse(tosca_node_template)['node_templates'] - custom_def = yamlparser.simple_parse(tosca_custom_def) - name = list(nodetemplates.keys())[0] - tpl = NodeTemplate(name, nodetemplates, custom_def) + tpl = self._get_nodetemplate(tosca_node_template, tosca_custom_def) self.assertIsNone(tpl.validate()) self.assertEqual(expected_properties, sorted(tpl.get_properties().keys())) @@ -254,7 +249,7 @@ class PropertyTest(TestCase): self.assertEqual(expected_message, str(error)) def test_capability_proprety_inheritance(self): - tosca_custom_def = ''' + tosca_custom_def_example1 = ''' tosca.capabilities.ScalableNew: derived_from: tosca.capabilities.Scalable properties: @@ -270,7 +265,7 @@ class PropertyTest(TestCase): type: tosca.capabilities.ScalableNew ''' - tosca_node_template = ''' + tosca_node_template_example1 = ''' node_templates: compute_instance: type: tosca.nodes.ComputeNew @@ -280,9 +275,37 @@ class PropertyTest(TestCase): min_instances: 1 ''' + tosca_custom_def_example2 = ''' + tosca.nodes.ComputeNew: + derived_from: tosca.nodes.Compute + capabilities: + new_cap: + type: tosca.capabilities.Scalable + ''' + + tosca_node_template_example2 = ''' + node_templates: + db_server: + type: tosca.nodes.ComputeNew + capabilities: + host: + properties: + num_cpus: 1 + ''' + + tpl1 = self._get_nodetemplate(tosca_node_template_example1, + tosca_custom_def_example1) + self.assertIsNone(tpl1.validate()) + + tpl2 = self._get_nodetemplate(tosca_node_template_example2, + tosca_custom_def_example2) + self.assertIsNone(tpl2.validate()) + + def _get_nodetemplate(self, tpl_snippet, + custom_def_snippet=None): nodetemplates = yamlparser.\ - simple_parse(tosca_node_template)['node_templates'] - custom_def = yamlparser.simple_parse(tosca_custom_def) + simple_parse(tpl_snippet)['node_templates'] + custom_def = yamlparser.simple_parse(custom_def_snippet) name = list(nodetemplates.keys())[0] tpl = NodeTemplate(name, nodetemplates, custom_def) - self.assertIsNone(tpl.validate()) + return tpl