summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManor, Yanir (ym903w) <ym903w@att.com>2018-10-21 11:33:28 +0300
committerManor, Yanir (ym903w) <ym903w@intl.att.com>2018-10-23 12:00:25 +0300
commitc81f7b519874fba8751c5db6a4c0b88fb5426335 (patch)
tree40ee01aebdbe4ff25c3ebb0557188211f46f8ed7
parentfaa922c2074d86e4fe9c1082e4c5a2191ff3b688 (diff)
Update code to latest
Change-Id: I3ceb652d415ff50a8f385f64745e5367f3ef3488 Issue-ID: SDC-1800 Signed-off-by: Manor, Yanir (ym903w) <ym903w@intl.att.com>
-rw-r--r--app/tests/test_node_templates.py34
-rw-r--r--app/tests/test_value_templates.py23
-rw-r--r--app/toscalib/templates/node.py53
-rw-r--r--app/toscalib/templates/topology.py23
-rw-r--r--app/toscalib/templates/value.py14
-rw-r--r--app/toscalib/utils/tosca_operate.py2
6 files changed, 91 insertions, 58 deletions
diff --git a/app/tests/test_node_templates.py b/app/tests/test_node_templates.py
index 15d5480..2d79b95 100644
--- a/app/tests/test_node_templates.py
+++ b/app/tests/test_node_templates.py
@@ -20,25 +20,23 @@ class TestNodeTemplateMethods(unittest.TestCase):
node._parse_pre_defined_content(prop_sec)
self.assertEqual('template_value', node.properties.get('propertyName').value.value)
- # TODO uncomment after merging ecomp latest code
- # def test_update_get_node_name_property_value(self):
- # template = init_template()
- # node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
- # prop_sec = {'properties': {'propertyName': '__GET_NODE_NAME__'}}
- # node._parse_pre_defined_content(prop_sec)
- # self.assertEqual('__GET_NODE_NAME__', node.properties.get('propertyName').value.value)
- # node._update_get_node_name()
- # self.assertEqual('myNode', node.properties.get('propertyName').value.value)
+ def test_update_get_node_name_property_value(self):
+ template = init_template()
+ node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
+ prop_sec = {'properties': {'propertyName': '__GET_NODE_NAME__'}}
+ node._parse_pre_defined_content(prop_sec)
+ self.assertEqual('__GET_NODE_NAME__', node.properties.get('propertyName').value.value)
+ node._update_get_node_name()
+ self.assertEqual('myNode', node.properties.get('propertyName').value.value)
- # TODO uncomment after merging ecomp latest code
- # def test_update_get_node_name_capability_property_value(self):
- # template = init_template()
- # node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
- # prop_sec = {'capabilities': {'capabilityName': {'properties': {'capabilityProperty': '__GET_NODE_NAME__'}}}}
- # node._parse_pre_defined_content(prop_sec)
- # self.assertEqual('__GET_NODE_NAME__', node._get_capability_property('capabilityName', 'capabilityProperty').value.value)
- # node._update_get_node_name()
- # self.assertEqual('myNode', node._get_capability_property('capabilityName', 'capabilityProperty').value.value)
+ def test_update_get_node_name_capability_property_value(self):
+ template = init_template()
+ node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
+ prop_sec = {'capabilities': {'capabilityName': {'properties': {'capabilityProperty': '__GET_NODE_NAME__'}}}}
+ node._parse_pre_defined_content(prop_sec)
+ self.assertEqual('__GET_NODE_NAME__', node._get_capability_property('capabilityName', 'capabilityProperty').value.value)
+ node._update_get_node_name()
+ self.assertEqual('myNode', node._get_capability_property('capabilityName', 'capabilityProperty').value.value)
def test_update_prefix(self):
template = init_template()
diff --git a/app/tests/test_value_templates.py b/app/tests/test_value_templates.py
index bc98fa8..7ebe95d 100644
--- a/app/tests/test_value_templates.py
+++ b/app/tests/test_value_templates.py
@@ -79,18 +79,17 @@ class TestValueMethods(unittest.TestCase):
res._update_function_reference(template)
self.assertEqual(res.value_from_item, template.inputs.get('inputName'))
- # TODO uncomment after merging latest ecomp code
- # def test_update_get_input_function_reference_auto_generate_input(self):
- # template = init_template()
- # node = template.node_dict.get('nodeName')
- # value = {'get_input': 'propertyName'}
- # res = _is_function(value)
- # self.assertIsNone(res.value_from_item)
- # self.assertIsNone(template.inputs.get('nodeName_propertyName'))
- # self.assertEqual(res.target_property, 'propertyName')
- # res._update_function_reference(template, node, node.properties.get('propertyName'))
- # self.assertIsNotNone(res.value_from_item)
- # self.assertEqual(res.value_from_item, template.inputs.get('nodeName_propertyName'))
+ def test_update_get_input_function_reference_auto_generate_input(self):
+ template = init_template()
+ node = template.node_dict.get('nodeName')
+ value = {'get_input': 'propertyName'}
+ res = _is_function(value)
+ self.assertIsNone(res.value_from_item)
+ self.assertIsNone(template.inputs.get('nodeName_propertyName'))
+ self.assertEqual(res.target_property, 'propertyName')
+ res._update_function_reference(template, node, node.properties.get('propertyName'))
+ self.assertIsNotNone(res.value_from_item)
+ self.assertEqual(res.value_from_item, template.inputs.get('nodeName_propertyName'))
def test_update_get_property_function_reference_node_not_found(self):
value = {'get_property': ['node_name', 'property_name']}
diff --git a/app/toscalib/templates/node.py b/app/toscalib/templates/node.py
index 8a07a49..9aec2ae 100644
--- a/app/toscalib/templates/node.py
+++ b/app/toscalib/templates/node.py
@@ -7,8 +7,7 @@ from toscalib.utils import tosca_import, tosca_heat
import copy, re, logging
from toscalib.templates.interface_item import InterfaceItem
-#Author: Shu Shi
-#emaiL: shushi@research.att.com
+
@@ -61,13 +60,13 @@ class Node(object):
for intf in node_type.interfaces.keys():
self.interfaces[intf] = InterfaceItem(node_type.interfaces[intf])
- if node_type.mapping_template is not None:
- from toscalib.templates.topology import ToscaTopology
- self.mapping_template = copy.deepcopy(node_type.mapping_template)
- self.mapping_template._update_prefix(self.name + '_')
- self.mapping_template._verify_substitution(self)
-# for sub_rule in node_type.mapping_template.sub_rules:
-# sub_rule._update_pointer(self, self.mapping_template)
+# if node_type.mapping_template is not None:
+# from toscalib.templates.topology import ToscaTopology
+# self.mapping_template = copy.deepcopy(node_type.mapping_template)
+# self.mapping_template._update_prefix(self.name + '_')
+# self.mapping_template._verify_substitution(self)
+# # for sub_rule in node_type.mapping_template.sub_rules:
+# # sub_rule._update_pointer(self, self.mapping_template)
self._update_parent_node()
@@ -83,8 +82,8 @@ class Node(object):
prop_item = self._get_property_item(prop_name)
if prop_item is not None:
prop_item._assign(prop_sec[prop_name])
- if prop_sec[prop_name] == '__GET_NODE_NAME__':
- prop_item._assign(self.name)
+# if prop_sec[prop_name] == '__GET_NODE_NAME__':
+# prop_item._assign(self.name)
# if content.has_key(NOD_REQUIREMENTS):
if NOD_REQUIREMENTS in content:
@@ -172,24 +171,28 @@ class Node(object):
for req in self.requirements:
req._verify_requirement(node_dict)
- def _verify_functions(self):
+ def _verify_functions(self, parent_temp = None):
+ if parent_temp is not None:
+ temp = parent_temp
+ else:
+ temp = self.template
if self.id.value is not None:
- self.id.value._update_function_reference(self.template, self, self.id)
+ self.id.value._update_function_reference(temp, self, self.id)
for prop_item in iter(self.properties.values()):
if prop_item.value is not None:
- prop_item.value._update_function_reference(self.template, self, prop_item)
+ prop_item.value._update_function_reference(temp, self, prop_item)
for cap_item in iter(self.capabilities.values()):
for cap_item_prop in iter(cap_item.properties.values()):
if cap_item_prop.value is not None:
- cap_item_prop.value._update_function_reference(self.template, self, cap_item_prop)
+ cap_item_prop.value._update_function_reference(temp, self, cap_item_prop)
for interface_item in iter(self.interfaces.values()):
for interface_item_input in iter(interface_item.inputs.values()):
if interface_item_input.value is not None:
- interface_item_input.value._update_function_reference(self.template, self, interface_item_input)
+ interface_item_input.value._update_function_reference(temp, self, interface_item_input)
for operation_item in iter(interface_item.operations.values()):
for input_item in iter(operation_item.inputs.values()):
if input_item.value is not None:
- input_item.value._update_function_reference(self.template, self, input_item)
+ input_item.value._update_function_reference(temp, self, input_item)
def _update_parent_node(self):
for prop in iter(self.properties.values()):
@@ -200,7 +203,21 @@ class Node(object):
req._update_parent_node(self)
for interface in iter(self.interfaces.values()):
interface._update_parent_node(self)
-
+
+ def _update_get_node_name(self):
+ for prop_item in iter(self.properties.values()):
+ if prop_item.value is not None:
+ if prop_item.value.value == '__GET_NODE_NAME__':
+ prop_item._assign(self.name)
+
+ for cap_item in iter(self.capabilities.values()):
+ for cap_item_prop in iter(cap_item.properties.values()):
+ if cap_item_prop.value is not None:
+ if cap_item_prop.value.value == '__GET_NODE_NAME__':
+ cap_item_prop._assign(self.name)
+
+ def _update_template(self, template):
+ self.template = template
def _update_prefix(self, prefix):
if self.name == 'NO_PREFIX':
diff --git a/app/toscalib/templates/topology.py b/app/toscalib/templates/topology.py
index f8c00ed..9426ef0 100644
--- a/app/toscalib/templates/topology.py
+++ b/app/toscalib/templates/topology.py
@@ -1,5 +1,4 @@
-#Author: Shu Shi
-#emaiL: shushi@research.att.com
+
from toscalib.templates.constant import *
@@ -177,18 +176,30 @@ class ToscaTopology(object):
edges.append(new_edge)
return edges
- def _update_function_pointer(self):
+ def _update_function_pointer(self, parent_temp=None):
for node in iter(self.node_dict.values()):
#node._verify_requirements(self.node_dict)
- node._verify_functions()
+ node._verify_functions(parent_temp)
for output in iter(self.outputs.values()):
if output.value is not None:
- output.value._update_function_reference(self)
+ if parent_temp is None:
+ output.value._update_function_reference(self)
+ else:
+ output.value._update_function_reference(parent_temp)
+
def _update_translation_function_pointer(self):
for node in iter(self.node_dict.values()):
if node.tran_template is not None:
- node.tran_template._update_function_pointer()
+ node.tran_template._update_function_pointer(node.template)
+
+ def _update_get_node_name(self):
+ for node in iter(self.node_dict.values()):
+ node._update_get_node_name()
+
+ def _update_template(self, template):
+ for node in iter(self.node_dict.values()):
+ node._update_template(template)
def _update_prefix(self, prefix):
exist_key_list = list(self.node_dict.keys())
diff --git a/app/toscalib/templates/value.py b/app/toscalib/templates/value.py
index fee0ceb..3e1ad42 100644
--- a/app/toscalib/templates/value.py
+++ b/app/toscalib/templates/value.py
@@ -73,12 +73,18 @@ class FunctionValue(object):
elif self.target_property in temp.aux_inputs:
self.value_from_item = temp.aux_inputs[self.target_property]
return
- else:
- logging.debug( 'get_input function points to a non-existent input, autofill'+ self.target_property)
+ elif self.value_from_item is None: #This might not be the best solution, needs to pay attention to
+# logging.debug( 'get_input function points to a non-existent input, set it to NONE')
+# self_item.value = None
+ #this code is causing problems when properties in different nodes are calling the same get_input but actually mean different input values
+
+ logging.warning( 'get_input function points to a non-existent input, autofill '+ self.target_property)
def_item = copy.deepcopy(self_item.definition)
- def_item.name = self.target_property
+ def_item.name = self_node.name + '_' + self.target_property
+ self.target_property = self_node.name + '_' + self.target_property
temp.inputs[self.target_property] = PropertyItem(def_item)
self.value_from_item = temp.inputs[self.target_property]
+
return
elif self.type == GET_PROPERTY:
if self.extra_data is None or len(self.extra_data) < 2:
@@ -250,7 +256,7 @@ class Value(object):
self.type_obj._update_function_reference(temp, self.value, self_node, self_item)
if self.function is not None:
self.function._update_function_reference(temp, self_node, self_item)
-
+
def _update_prefix(self, prefix):
if self.value is not None:
self.type_obj._update_prefix(prefix, self.value)
diff --git a/app/toscalib/utils/tosca_operate.py b/app/toscalib/utils/tosca_operate.py
index bc67310..3f47d93 100644
--- a/app/toscalib/utils/tosca_operate.py
+++ b/app/toscalib/utils/tosca_operate.py
@@ -42,6 +42,8 @@ def _create_new_template(template, type_name, prefix_name = None):
new_temp = copy.deepcopy(db.TEMPLATES[type_name])
new_temp._update_prefix(prefix)
+ new_temp._update_get_node_name()
+ new_temp._update_template(template)
template.inputs.update(new_temp.inputs)
template.outputs.update(new_temp.outputs)
template.node_dict.update(new_temp.node_dict)