Return type value along with parent hierarchy

Instead of simply returning value of calling type or just parent type,
get and return all values together.

Change-Id: I1b424b444691d81ad58b065bcfd930790407d488
Closes-Bug: 1535267
This commit is contained in:
Sahdev Zala
2016-01-19 09:53:54 -08:00
parent 51ec7154e6
commit 839d099c5f
4 changed files with 58 additions and 22 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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

View File

@@ -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