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:
@@ -299,12 +299,14 @@ tosca.nodes.network.Port:
|
|||||||
attached to specific Compute node instance
|
attached to specific Compute node instance
|
||||||
capability: tosca.capabilities.network.Bindable
|
capability: tosca.capabilities.network.Bindable
|
||||||
relationship: tosca.relationships.network.BindsTo
|
relationship: tosca.relationships.network.BindsTo
|
||||||
|
node: tosca.nodes.Compute
|
||||||
- link:
|
- link:
|
||||||
description: >
|
description: >
|
||||||
Link requirement expresses the relationship between Port and Network
|
Link requirement expresses the relationship between Port and Network
|
||||||
nodes. It indicates which network this port will connect to.
|
nodes. It indicates which network this port will connect to.
|
||||||
capability: tosca.capabilities.network.Linkable
|
capability: tosca.capabilities.network.Linkable
|
||||||
relationship: tosca.relationships.network.LinksTo
|
relationship: tosca.relationships.network.LinksTo
|
||||||
|
node: tosca.nodes.network.Network
|
||||||
|
|
||||||
tosca.nodes.ObjectStorage:
|
tosca.nodes.ObjectStorage:
|
||||||
derived_from: tosca.nodes.Root
|
derived_from: tosca.nodes.Root
|
||||||
|
|||||||
@@ -86,16 +86,27 @@ class EntityType(object):
|
|||||||
defs = self.defs
|
defs = self.defs
|
||||||
if ndtype in defs:
|
if ndtype in defs:
|
||||||
value = defs[ndtype]
|
value = defs[ndtype]
|
||||||
if parent and not value:
|
if parent:
|
||||||
p = self.parent_type
|
p = self.parent_type
|
||||||
while value is None:
|
if p:
|
||||||
# check parent node
|
while p.type != 'tosca.nodes.Root':
|
||||||
if not p:
|
if p and p.type == 'tosca.nodes.Root':
|
||||||
break
|
break
|
||||||
if p and p.type == 'tosca.nodes.Root':
|
if ndtype in p.defs:
|
||||||
break
|
# get the parent value
|
||||||
value = p.get_value(ndtype)
|
parent_value = p.defs[ndtype]
|
||||||
p = p.parent_type
|
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
|
return value
|
||||||
|
|
||||||
def get_definition(self, ndtype):
|
def get_definition(self, ndtype):
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class NodeType(StatefulEntityType):
|
|||||||
def get_capabilities_objects(self):
|
def get_capabilities_objects(self):
|
||||||
'''Return a list of capability objects.'''
|
'''Return a list of capability objects.'''
|
||||||
typecapabilities = []
|
typecapabilities = []
|
||||||
caps = self.get_value(self.CAPABILITIES)
|
caps = self.get_value(self.CAPABILITIES, None, True)
|
||||||
if caps is None:
|
if caps is None:
|
||||||
caps = self.get_value(self.CAPABILITIES, None, True)
|
caps = self.get_value(self.CAPABILITIES, None, True)
|
||||||
if caps:
|
if caps:
|
||||||
@@ -146,7 +146,7 @@ class NodeType(StatefulEntityType):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
return self.get_value(self.REQUIREMENTS)
|
return self.get_value(self.REQUIREMENTS, None, True)
|
||||||
|
|
||||||
def get_all_requirements(self):
|
def get_all_requirements(self):
|
||||||
requires = self.requirements
|
requires = self.requirements
|
||||||
|
|||||||
@@ -192,7 +192,6 @@ class PropertyTest(TestCase):
|
|||||||
self.assertEqual(True, propertyInstance.required)
|
self.assertEqual(True, propertyInstance.required)
|
||||||
|
|
||||||
def test_proprety_inheritance(self):
|
def test_proprety_inheritance(self):
|
||||||
from toscaparser.nodetemplate import NodeTemplate
|
|
||||||
|
|
||||||
tosca_custom_def = '''
|
tosca_custom_def = '''
|
||||||
tosca.nodes.SoftwareComponent.MySoftware:
|
tosca.nodes.SoftwareComponent.MySoftware:
|
||||||
@@ -215,11 +214,7 @@ class PropertyTest(TestCase):
|
|||||||
expected_properties = ['component_version',
|
expected_properties = ['component_version',
|
||||||
'install_path']
|
'install_path']
|
||||||
|
|
||||||
nodetemplates = yamlparser.\
|
tpl = self._get_nodetemplate(tosca_node_template, tosca_custom_def)
|
||||||
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)
|
|
||||||
self.assertIsNone(tpl.validate())
|
self.assertIsNone(tpl.validate())
|
||||||
self.assertEqual(expected_properties,
|
self.assertEqual(expected_properties,
|
||||||
sorted(tpl.get_properties().keys()))
|
sorted(tpl.get_properties().keys()))
|
||||||
@@ -254,7 +249,7 @@ class PropertyTest(TestCase):
|
|||||||
self.assertEqual(expected_message, str(error))
|
self.assertEqual(expected_message, str(error))
|
||||||
|
|
||||||
def test_capability_proprety_inheritance(self):
|
def test_capability_proprety_inheritance(self):
|
||||||
tosca_custom_def = '''
|
tosca_custom_def_example1 = '''
|
||||||
tosca.capabilities.ScalableNew:
|
tosca.capabilities.ScalableNew:
|
||||||
derived_from: tosca.capabilities.Scalable
|
derived_from: tosca.capabilities.Scalable
|
||||||
properties:
|
properties:
|
||||||
@@ -270,7 +265,7 @@ class PropertyTest(TestCase):
|
|||||||
type: tosca.capabilities.ScalableNew
|
type: tosca.capabilities.ScalableNew
|
||||||
'''
|
'''
|
||||||
|
|
||||||
tosca_node_template = '''
|
tosca_node_template_example1 = '''
|
||||||
node_templates:
|
node_templates:
|
||||||
compute_instance:
|
compute_instance:
|
||||||
type: tosca.nodes.ComputeNew
|
type: tosca.nodes.ComputeNew
|
||||||
@@ -280,9 +275,37 @@ class PropertyTest(TestCase):
|
|||||||
min_instances: 1
|
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.\
|
nodetemplates = yamlparser.\
|
||||||
simple_parse(tosca_node_template)['node_templates']
|
simple_parse(tpl_snippet)['node_templates']
|
||||||
custom_def = yamlparser.simple_parse(tosca_custom_def)
|
custom_def = yamlparser.simple_parse(custom_def_snippet)
|
||||||
name = list(nodetemplates.keys())[0]
|
name = list(nodetemplates.keys())[0]
|
||||||
tpl = NodeTemplate(name, nodetemplates, custom_def)
|
tpl = NodeTemplate(name, nodetemplates, custom_def)
|
||||||
self.assertIsNone(tpl.validate())
|
return tpl
|
||||||
|
|||||||
Reference in New Issue
Block a user