diff --git a/toscaparser/elements/statefulentitytype.py b/toscaparser/elements/statefulentitytype.py index 5317eed..47496f7 100644 --- a/toscaparser/elements/statefulentitytype.py +++ b/toscaparser/elements/statefulentitytype.py @@ -66,7 +66,7 @@ class StatefulEntityType(EntityType): def get_attributes_def_objects(self): '''Return a list of attribute definition objects.''' - attrs = self.get_value(self.ATTRIBUTES) + attrs = self.get_value(self.ATTRIBUTES, parent=True) if attrs: return [AttributeDef(attr, None, schema) for attr, schema in attrs.items()] diff --git a/toscaparser/tests/data/test_attributes_inheritance.yaml b/toscaparser/tests/data/test_attributes_inheritance.yaml new file mode 100644 index 0000000..0649c11 --- /dev/null +++ b/toscaparser/tests/data/test_attributes_inheritance.yaml @@ -0,0 +1,28 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile to test the attribute inheritance + +imports: + - custom_types/compute_with_prop.yaml + +topology_template: + + node_templates: + + server: + type: tosca.nodes.ComputeWithProp + properties: + test: yes + capabilities: + host: + properties: + num_cpus: 1 + mem_size: 1 GB + os: + properties: + type: linux + + outputs: + server_ip: + value: { get_attribute: [ server, public_address ] } + diff --git a/toscaparser/tests/test_toscadef.py b/toscaparser/tests/test_toscadef.py index 54451c5..6001935 100644 --- a/toscaparser/tests/test_toscadef.py +++ b/toscaparser/tests/test_toscadef.py @@ -64,15 +64,15 @@ class ToscaDefTest(TestCase): def test_capabilities(self): self.assertEqual( - sorted(['tosca.capabilities.Container', - 'tosca.capabilities.Node', - 'tosca.capabilities.OperatingSystem', - 'tosca.capabilities.network.Bindable', - 'tosca.capabilities.Scalable']), + ['tosca.capabilities.Container', + 'tosca.capabilities.Node', + 'tosca.capabilities.OperatingSystem', + 'tosca.capabilities.Scalable', + 'tosca.capabilities.network.Bindable'], sorted([c.type for c in compute_type.get_capabilities_objects()])) self.assertEqual( - sorted(['tosca.capabilities.Node', - 'tosca.capabilities.network.Linkable']), + ['tosca.capabilities.Node', + 'tosca.capabilities.network.Linkable'], sorted([c.type for c in network_type.get_capabilities_objects()])) endpoint_properties = ['initiator', 'network_name', 'port', 'port_name', 'ports', 'protocol', @@ -154,7 +154,8 @@ class ToscaDefTest(TestCase): def test_attributes_def(self): self.assertEqual( - ['networks', 'ports', 'private_address', 'public_address'], + ['networks', 'ports', 'private_address', 'public_address', + 'state', 'tosca_id', 'tosca_name'], sorted(compute_type.get_attributes_def().keys())) def test_requirements(self): @@ -171,8 +172,8 @@ class ToscaDefTest(TestCase): def test_relationship(self): self.assertEqual( - sorted([('tosca.relationships.HostedOn', 'tosca.nodes.Compute'), - ('tosca.relationships.DependsOn', 'tosca.nodes.Root')]), + [('tosca.relationships.DependsOn', 'tosca.nodes.Root'), + ('tosca.relationships.HostedOn', 'tosca.nodes.Compute')], sorted([(relation.type, node.type) for relation, node in component_type.relationship.items()])) self.assertIn( diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index e9c7a5e..53778cc 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -698,3 +698,9 @@ class ToscaTemplateTest(TestCase): os.path.dirname(os.path.abspath(__file__)), "data/test_node_filter.yaml") ToscaTemplate(tosca_tpl) + + def test_attributes_inheritance(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_attributes_inheritance.yaml") + ToscaTemplate(tosca_tpl)