Distinguish the mapping and mapped by name. 55/17855/3
authorshangxdy <shang.xiaodong@zte.com.cn>
Sat, 30 Jul 2016 18:10:03 +0000 (02:10 +0800)
committershangxdy <shang.xiaodong@zte.com.cn>
Wed, 3 Aug 2016 08:33:11 +0000 (16:33 +0800)
1. Use complete name like nested_topology_tpls here and other places
like get_nested_topology_tpls for better readability;
2. Use "sub_mapped_node_tpl" instead of submaped_node_tpl;
3. Use sub_mapped_  instead of submaped.

Upper changed in substitution_mappings.py, tosca_template.py,
tosca_template.py and others

JIRA:PARSER-73
Change-Id: I21b2d3a35773078d7437bbae9ff5d1522608c4d2
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
tosca2heat/tosca-parser/toscaparser/imports.py
tosca2heat/tosca-parser/toscaparser/substitution_mappings.py
tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
tosca2heat/tosca-parser/toscaparser/topology_template.py
tosca2heat/tosca-parser/toscaparser/tosca_template.py

index 86c10f0..451c952 100644 (file)
@@ -37,7 +37,7 @@ class ImportsLoader(object):
                  tpl=None):
         self.importslist = importslist
         self.custom_defs = {}
-        self.nested_topo_tpls = []
+        self.nested_tosca_tpls = []
         if not path and not tpl:
             msg = _('Input tosca template is not provided.')
             log.warning(msg)
@@ -57,8 +57,8 @@ class ImportsLoader(object):
     def get_custom_defs(self):
         return self.custom_defs
 
-    def get_nested_topo_tpls(self):
-        return self.nested_topo_tpls
+    def get_nested_tosca_tpls(self):
+        return self.nested_tosca_tpls
 
     def _validate_and_load_imports(self):
         imports_names = set()
@@ -98,7 +98,7 @@ class ImportsLoader(object):
                         custom_type, import_def)
                     self._update_custom_def(custom_type, None)
 
-            self._update_nested_topo_tpls(full_file_name, custom_type)
+            self._update_nested_tosca_tpls(full_file_name, custom_type)
 
     def _update_custom_def(self, custom_type, namespace_prefix):
         outer_custom_types = {}
@@ -119,10 +119,10 @@ class ImportsLoader(object):
                     else:
                         self.custom_defs.update(outer_custom_types)
 
-    def _update_nested_topo_tpls(self, full_file_name, custom_tpl):
+    def _update_nested_tosca_tpls(self, full_file_name, custom_tpl):
         if full_file_name and custom_tpl:
             topo_tpl = {full_file_name: custom_tpl}
-            self.nested_topo_tpls.append(topo_tpl)
+            self.nested_tosca_tpls.append(topo_tpl)
 
     def _validate_import_keys(self, import_name, import_uri_def):
         if self.FILE not in import_uri_def.keys():
index 40ff3ca..dc953b0 100644 (file)
@@ -31,45 +31,46 @@ log = logging.getLogger('tosca')
 
 
 class Substitution_mappings(object):
-    '''Substitution_mappings class for declaration that
+    '''Substitution_mappings class declaration
 
-    exports the topology template as an implementation of a Node type.
+    Substitution_mappings exports the topology template as an
+    implementation of a Node type.
     '''
 
     SECTIONS = (NODE_TYPE, CAPABILITIES, REQUIREMENTS) = \
                ('node_type', 'requirements', 'capabilities')
 
-    def __init__(self, submap_def, nodetemplates, inputs, outputs,
-                 submaped_node_template, custom_defs):
+    def __init__(self, sub_mapping_def, nodetemplates, inputs, outputs,
+                 sub_mapped_node_template, custom_defs):
         self.nodetemplates = nodetemplates
-        self.submap_def = submap_def
+        self.sub_mapping_def = sub_mapping_def
         self.inputs = inputs or []
         self.outputs = outputs or []
-        self.submaped_node_template = submaped_node_template
+        self.sub_mapped_node_template = sub_mapped_node_template
         self.custom_defs = custom_defs or {}
         self._validate()
 
         self._capabilities = None
         self._requirements = None
 
-        self.submaped_node_template.substitution_mapped = True
+        self.sub_mapped_node_template.substitution_mapped = True
 
     @classmethod
-    def get_node_type(cls, submap_tpl):
-        if isinstance(submap_tpl, dict):
-            return submap_tpl.get(cls.NODE_TYPE)
+    def get_node_type(cls, sub_mapping_def):
+        if isinstance(sub_mapping_def, dict):
+            return sub_mapping_def.get(cls.NODE_TYPE)
 
     @property
     def node_type(self):
-        return self.submap_def.get(self.NODE_TYPE)
+        return self.sub_mapping_def.get(self.NODE_TYPE)
 
     @property
     def capabilities(self):
-        return self.submap_def.get(self.CAPABILITIES)
+        return self.sub_mapping_def.get(self.CAPABILITIES)
 
     @property
     def requirements(self):
-        return self.submap_def.get(self.REQUIREMENTS)
+        return self.sub_mapping_def.get(self.REQUIREMENTS)
 
     def _validate(self):
         self._validate_keys()
@@ -81,7 +82,7 @@ class Substitution_mappings(object):
 
     def _validate_keys(self):
         """validate the keys of substitution mappings."""
-        for key in self.submap_def.keys():
+        for key in self.sub_mapping_def.keys():
             if key not in self.SECTIONS:
                 ExceptionCollector.appendException(
                     UnknownFieldError(what='Substitution_mappings',
@@ -89,7 +90,7 @@ class Substitution_mappings(object):
 
     def _validate_type(self):
         """validate the node_type of substitution mappings."""
-        node_type = self.submap_def.get(self.NODE_TYPE)
+        node_type = self.sub_mapping_def.get(self.NODE_TYPE)
         if not node_type:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
@@ -106,7 +107,7 @@ class Substitution_mappings(object):
 
         # The inputs in service template which defines substutition mappings
         # must be in properties of node template wchich be mapped.
-        inputs_names = list(self.submaped_node_template
+        inputs_names = list(self.sub_mapped_node_template
                                 .get_properties().keys())
         for name in inputs_names:
             if name not in [input.name for input in self.inputs]:
@@ -118,8 +119,8 @@ class Substitution_mappings(object):
         """validate the capabilities of substitution mappings."""
 
         # The capabilites must be in node template wchich be mapped.
-        tpls_capabilities = self.submap_def.get(self.CAPABILITIES)
-        node_capabiliteys = self.submaped_node_template.get_capabilities()
+        tpls_capabilities = self.sub_mapping_def.get(self.CAPABILITIES)
+        node_capabiliteys = self.sub_mapped_node_template.get_capabilities()
         for cap in node_capabiliteys.keys() if node_capabiliteys else []:
             if (tpls_capabilities and
                     cap not in list(tpls_capabilities.keys())):
@@ -132,8 +133,8 @@ class Substitution_mappings(object):
         """validate the requirements of substitution mappings."""
 
         # The requirements must be in node template wchich be mapped.
-        tpls_requirements = self.submap_def.get(self.REQUIREMENTS)
-        node_requirements = self.submaped_node_template.requirements
+        tpls_requirements = self.sub_mapping_def.get(self.REQUIREMENTS)
+        node_requirements = self.sub_mapped_node_template.requirements
         for req in node_requirements if node_requirements else []:
             if (tpls_requirements and
                     req not in list(tpls_requirements.keys())):
@@ -147,7 +148,7 @@ class Substitution_mappings(object):
         pass
         # The outputs in service template which defines substutition mappings
         # must be in atrributes of node template wchich be mapped.
-        # outputs_names = self.submaped_node_template.get_properties().keys()
+        # outputs_names = self.sub_mapped_node_template.get_properties().keys()
         # for name in outputs_names:
         #    if name not in [output.name for input in self.outputs]:
         #        ExceptionCollector.appendException(
index 877c72f..3d1b55d 100644 (file)
@@ -159,4 +159,6 @@ class TopologyTemplateTest(TestCase):
             "data/topology_template/system.yaml")
         system_tosca_template = ToscaTemplate(tpl_path)
         self.assertIsNotNone(system_tosca_template)
-        self.assertEqual(len(system_tosca_template.nested_tosca_templates), 3)
+        self.assertEqual(
+            len(system_tosca_template.
+                nested_tosca_templates_with_topology), 3)
index 70bc7d6..4039257 100644 (file)
@@ -43,9 +43,9 @@ class TopologyTemplate(object):
     '''Load the template data.'''
     def __init__(self, template, custom_defs,
                  rel_types=None, parsed_params=None,
-                 submaped_node_template=None):
+                 sub_mapped_node_template=None):
         self.tpl = template
-        self.submaped_node_template = submaped_node_template
+        self.sub_mapped_node_template = sub_mapped_node_template
         if self.tpl:
             self.custom_defs = custom_defs
             self.rel_types = rel_types
@@ -110,12 +110,12 @@ class TopologyTemplate(object):
 
     def _substitution_mappings(self):
         tpl_substitution_mapping = self._tpl_substitution_mappings()
-        if tpl_substitution_mapping and self.submaped_node_template:
+        if tpl_substitution_mapping and self.sub_mapped_node_template:
             return Substitution_mappings(tpl_substitution_mapping,
                                          self.nodetemplates,
                                          self.inputs,
                                          self.outputs,
-                                         self.submaped_node_template,
+                                         self.sub_mapped_node_template,
                                          self.custom_defs)
 
     def _policies(self):
@@ -294,7 +294,7 @@ class TopologyTemplate(object):
                 output.attrs[output.VALUE] = func
 
     @classmethod
-    def get_submaped_node_type(cls, topo_tpl):
-        if topo_tpl and isinstance(topo_tpl, dict):
-            submap_tpl = topo_tpl.get(SUBSTITUION_MAPPINGS)
+    def get_sub_mapping_node_type(cls, topology_tpl):
+        if topology_tpl and isinstance(topology_tpl, dict):
+            submap_tpl = topology_tpl.get(SUBSTITUION_MAPPINGS)
             return Substitution_mappings.get_node_type(submap_tpl)
index 058da15..28fa57b 100644 (file)
@@ -64,16 +64,16 @@ class ToscaTemplate(object):
 
     '''Load the template data.'''
     def __init__(self, path=None, parsed_params=None, a_file=True,
-                 yaml_dict_tpl=None, submaped_node_template=None):
-        if submaped_node_template is None:
+                 yaml_dict_tpl=None, sub_mapped_node_template=None):
+        if sub_mapped_node_template is None:
             ExceptionCollector.start()
         self.a_file = a_file
         self.input_path = None
         self.path = None
         self.tpl = None
-        self.submaped_node_template = submaped_node_template
-        self.nested_tosca_tpls = {}
-        self.nested_tosca_templates = []
+        self.sub_mapped_node_template = sub_mapped_node_template
+        self.nested_tosca_tpls_with_topology = {}
+        self.nested_tosca_templates_with_topology = []
         if path:
             self.input_path = path
             self.path = self._get_path(path)
@@ -105,10 +105,10 @@ class ToscaTemplate(object):
                 self.relationship_templates = self._relationship_templates()
                 self.nodetemplates = self._nodetemplates()
                 self.outputs = self._outputs()
-                self._handle_nested_topo_templates()
+                self._handle_nested_tosca_templates_with_topology()
                 self.graph = ToscaGraph(self.nodetemplates)
 
-        if submaped_node_template is None:
+        if sub_mapped_node_template is None:
             ExceptionCollector.stop()
         self.verify_template()
 
@@ -117,7 +117,7 @@ class ToscaTemplate(object):
                                 self._get_all_custom_defs(),
                                 self.relationship_types,
                                 self.parsed_params,
-                                self.submaped_node_template)
+                                self.sub_mapped_node_template)
 
     def _inputs(self):
         return self.topology_template.inputs
@@ -199,8 +199,8 @@ class ToscaTemplate(object):
                 toscaparser.imports.ImportsLoader(imports, self.path,
                                                   type_defs, self.tpl)
 
-            nested_topo_tpls = custom_service.get_nested_topo_tpls()
-            self._update_nested_topo_tpls(nested_topo_tpls)
+            nested_tosca_tpls = custom_service.get_nested_tosca_tpls()
+            self._update_nested_tosca_tpls_with_topology(nested_tosca_tpls)
 
             custom_defs = custom_service.get_custom_defs()
             if not custom_defs:
@@ -214,26 +214,29 @@ class ToscaTemplate(object):
                     custom_defs.update(inner_custom_types)
         return custom_defs
 
-    def _update_nested_topo_tpls(self, nested_topo_tpls):
-        for tpl in nested_topo_tpls:
+    def _update_nested_tosca_tpls_with_topology(self, nested_tosca_tpls):
+        for tpl in nested_tosca_tpls:
             filename, tosca_tpl = list(tpl.items())[0]
             if (tosca_tpl.get(TOPOLOGY_TEMPLATE) and
-               filename not in list(self.nested_tosca_tpls.keys())):
-                self.nested_tosca_tpls.update(tpl)
+                filename not in list(
+                    self.nested_tosca_tpls_with_topology.keys())):
+                self.nested_tosca_tpls_with_topology.update(tpl)
 
-    def _handle_nested_topo_templates(self):
-        for filename, tosca_tpl in self.nested_tosca_tpls.items():
+    def _handle_nested_tosca_templates_with_topology(self):
+        for fname, tosca_tpl in self.nested_tosca_tpls_with_topology.items():
             for nodetemplate in self.nodetemplates:
-                if self._is_substitution_mapped_node(nodetemplate, tosca_tpl):
+                if self._is_sub_mapped_node(nodetemplate, tosca_tpl):
                     nested_template = ToscaTemplate(
-                        path=filename, parsed_params=self.parsed_params,
+                        path=fname, parsed_params=self.parsed_params,
                         yaml_dict_tpl=tosca_tpl,
-                        submaped_node_template=nodetemplate)
+                        sub_mapped_node_template=nodetemplate)
                     if nested_template.has_substitution_mappings():
-                        filenames = [tpl.path for tpl in
-                                     self.nested_tosca_templates]
-                        if filename not in filenames:
-                            self.nested_tosca_templates.append(nested_template)
+                        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)
 
     def _validate_field(self):
         version = self._tpl_version()
@@ -298,19 +301,19 @@ class ToscaTemplate(object):
 
             log.info(msg)
 
-    def _is_substitution_mapped_node(self, nodetemplate, tosca_tpl):
+    def _is_sub_mapped_node(self, nodetemplate, tosca_tpl):
         """Return True if the nodetemple is substituted."""
         if (nodetemplate and not nodetemplate.substitution_mapped and
-                self.get_submaped_node_type(tosca_tpl) == nodetemplate.type and
-                len(nodetemplate.interfaces) < 1):
+                self.get_sub_mapping_node_type(tosca_tpl) == nodetemplate.type
+                and len(nodetemplate.interfaces) < 1):
             return True
         else:
             return False
 
-    def get_submaped_node_type(self, tosca_tpl):
+    def get_sub_mapping_node_type(self, tosca_tpl):
         """Return substitution mappings node type."""
         if tosca_tpl:
-            return TopologyTemplate.get_submaped_node_type(
+            return TopologyTemplate.get_sub_mapping_node_type(
                 tosca_tpl.get(TOPOLOGY_TEMPLATE))
 
     def has_substitution_mappings(self):
@@ -320,5 +323,5 @@ class ToscaTemplate(object):
 
     def has_nested_templates(self):
         """Return True if the tosca template has nested templates."""
-        return self.nested_tosca_templates is not None and \
-            len(self.nested_tosca_templates) >= 1
+        return self.nested_tosca_templates_with_topology is not None and \
+            len(self.nested_tosca_templates_with_topology) >= 1