Create translation test code for vRNC
[parser.git] / tosca2heat / tosca-parser / toscaparser / tosca_template.py
index 28fa57b..2e815fd 100644 (file)
@@ -14,6 +14,7 @@
 import logging
 import os
 
+from copy import deepcopy
 from toscaparser.common.exception import ExceptionCollector
 from toscaparser.common.exception import InvalidTemplateVersion
 from toscaparser.common.exception import MissingRequiredFieldError
@@ -226,17 +227,19 @@ class ToscaTemplate(object):
         for fname, tosca_tpl in self.nested_tosca_tpls_with_topology.items():
             for nodetemplate in self.nodetemplates:
                 if self._is_sub_mapped_node(nodetemplate, tosca_tpl):
+                    parsed_params = self._get_params_for_nested_template(
+                        nodetemplate)
                     nested_template = ToscaTemplate(
-                        path=fname, parsed_params=self.parsed_params,
+                        path=fname, parsed_params=parsed_params,
                         yaml_dict_tpl=tosca_tpl,
                         sub_mapped_node_template=nodetemplate)
                     if nested_template.has_substitution_mappings():
-                        fnames = \
-                            [tpl.path for tpl in
-                             self.nested_tosca_templates_with_topology]
-                        if fname not in fnames:
-                            self.nested_tosca_templates_with_topology.\
-                                append(nested_template)
+                        # Record the nested templates in top level template
+                        self.nested_tosca_templates_with_topology.\
+                            append(nested_template)
+                        # Set the substitution toscatemplate for mapped node
+                        nodetemplate.sub_mapping_tosca_template = \
+                            nested_template
 
     def _validate_field(self):
         version = self._tpl_version()
@@ -310,6 +313,16 @@ class ToscaTemplate(object):
         else:
             return False
 
+    def _get_params_for_nested_template(self, nodetemplate):
+        """Return total params for nested_template."""
+        parsed_params = deepcopy(self.parsed_params) \
+            if self.parsed_params else {}
+        if nodetemplate:
+            for pname in nodetemplate.get_properties():
+                parsed_params.update({pname:
+                                      nodetemplate.get_property_value(pname)})
+        return parsed_params
+
     def get_sub_mapping_node_type(self, tosca_tpl):
         """Return substitution mappings node type."""
         if tosca_tpl: