Merge "Disable syslog in heat-translator for functest integration"
[parser.git] / tosca2heat / tosca-parser / toscaparser / elements / entity_type.py
index 5d620a5..9fd6c4d 100644 (file)
@@ -29,6 +29,11 @@ class EntityType(object):
                ('derived_from', 'properties', 'attributes', 'requirements',
                 'interfaces', 'capabilities', 'type', 'artifacts')
 
+    TOSCA_DEF_SECTIONS = ['node_types', 'data_types', 'artifact_types',
+                          'group_types', 'relationship_types',
+                          'capability_types', 'interface_types',
+                          'policy_types']
+
     '''TOSCA definition file.'''
     TOSCA_DEF_FILE = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
@@ -36,7 +41,15 @@ class EntityType(object):
 
     loader = toscaparser.utils.yamlparser.load_yaml
 
-    TOSCA_DEF = loader(TOSCA_DEF_FILE)
+    TOSCA_DEF_LOAD_AS_IS = loader(TOSCA_DEF_FILE)
+
+    # Map of definition with pre-loaded values of TOSCA_DEF_FILE_SECTIONS
+    TOSCA_DEF = {}
+    for section in TOSCA_DEF_SECTIONS:
+        if section in TOSCA_DEF_LOAD_AS_IS.keys():
+            value = TOSCA_DEF_LOAD_AS_IS[section]
+            for key in value.keys():
+                TOSCA_DEF[key] = value[key]
 
     RELATIONSHIP_TYPE = (DEPENDSON, HOSTEDON, CONNECTSTO, ATTACHESTO,
                          LINKSTO, BINDSTO) = \
@@ -56,7 +69,8 @@ class EntityType(object):
     GROUP_PREFIX = 'tosca.groups.'
     # currently the data types are defined only for network
     # but may have changes in the future.
-    DATATYPE_PREFIX = 'tosca.datatypes.network.'
+    DATATYPE_PREFIX = 'tosca.datatypes.'
+    DATATYPE_NETWORK_PREFIX = DATATYPE_PREFIX + 'network.'
     TOSCA = 'tosca'
 
     def derived_from(self, defs):
@@ -79,7 +93,7 @@ class EntityType(object):
             return False
 
     def entity_value(self, defs, key):
-        if key in defs:
+        if defs and key in defs:
             return defs[key]
 
     def get_value(self, ndtype, defs=None, parent=None):
@@ -88,7 +102,7 @@ class EntityType(object):
             if not hasattr(self, 'defs'):
                 return None
             defs = self.defs
-        if ndtype in defs:
+        if defs and ndtype in defs:
             # copy the value to avoid that next operations add items in the
             # item definitions
             value = copy.copy(defs[ndtype])
@@ -96,7 +110,7 @@ class EntityType(object):
             p = self
             if p:
                 while p:
-                    if ndtype in p.defs:
+                    if p.defs and ndtype in p.defs:
                         # get the parent value
                         parent_value = p.defs[ndtype]
                         if value:
@@ -106,8 +120,14 @@ class EntityType(object):
                                         value[k] = v
                             if isinstance(value, list):
                                 for p_value in parent_value:
-                                    if p_value not in value:
-                                        value.append(p_value)
+                                    if isinstance(p_value, dict):
+                                        if list(p_value.keys())[0] not in [
+                                            list(item.keys())[0] for item in
+                                            value]:
+                                            value.append(p_value)
+                                    else:
+                                        if p_value not in value:
+                                            value.append(p_value)
                         else:
                             value = copy.copy(parent_value)
                     p = p.parent_type
@@ -139,7 +159,12 @@ class EntityType(object):
 def update_definitions(version):
     exttools = ExtTools()
     extension_defs_file = exttools.get_defs_file(version)
-
     loader = toscaparser.utils.yamlparser.load_yaml
-
-    EntityType.TOSCA_DEF.update(loader(extension_defs_file))
+    nfv_def_file = loader(extension_defs_file)
+    nfv_def = {}
+    for section in EntityType.TOSCA_DEF_SECTIONS:
+        if section in nfv_def_file.keys():
+            value = nfv_def_file[section]
+            for key in value.keys():
+                nfv_def[key] = value[key]
+    EntityType.TOSCA_DEF.update(nfv_def)