Fix BlockStorageAttachment bug when translate compute node 83/20083/1
authorshangxdy <shang.xiaodong@zte.com.cn>
Sun, 28 Aug 2016 09:25:28 +0000 (17:25 +0800)
committerjulien zhang <zhang.jun3g@zte.com.cn>
Thu, 1 Sep 2016 02:20:12 +0000 (02:20 +0000)
Currently, when translate compute node with local_storage and
high_availability, there is not BlockStorageAttache resource created
about block storage, and only BlockStorage created.
If only local_storage requirement in compute node, the result is
correct.
The reason is the function logic of _get_attachment_node is error. and
the patch will fixit.

JIRA:PARSER-100

Change-Id: I36456089ae65102d4b17797d266c850d8c16b29d
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
(cherry picked from commit aef34ad9a966ca64aa365ee6aaada702b986f68b)

tosca2heat/heat-translator/translator/hot/translate_node_templates.py
tosca2heat/heat-translator/translator/tests/data/hot_output/hot_nfv_sample.yaml
tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml

index f32d42b..4dd9556 100644 (file)
@@ -533,14 +533,20 @@ class TranslateNodeTemplates(object):
     def _get_attachment_node(self, node, suffix, volume_name):
         attach = False
         ntpl = self.nodetemplates
-        for key, value in node.relationships.items():
-            if key.is_derived_from('tosca.relationships.AttachesTo'):
-                if value.is_derived_from('tosca.nodes.BlockStorage'):
+        for key_r, value_n in node.relationships.items():
+            if key_r.is_derived_from('tosca.relationships.AttachesTo'):
+                if value_n.is_derived_from('tosca.nodes.BlockStorage'):
                     attach = True
             if attach:
                 relationship_tpl = None
                 for req in node.requirements:
                     for key, val in req.items():
+                        if isinstance(val, dict):
+                            if value_n.name != val.get('node'):
+                                continue
+                        else:
+                            if value_n.name != val:
+                                continue
                         attach = val
                         relship = val.get('relationship')
                         for rkey, rval in val.items():
index d66569d..d67f022 100644 (file)
@@ -15,6 +15,7 @@ resources:
       user_data_format: SOFTWARE_CONFIG
     depends_on:
       - VDU2
+      - BlockStorage
 
   VDU2:
     type: OS::Nova::Server
@@ -25,6 +26,20 @@ resources:
       - port: { get_resource: CP2 }
       user_data_format: SOFTWARE_CONFIG
 
+  BlockStorage:
+    type: OS::Cinder::Volume
+    properties:
+      size: 10
+
+  tosca.relationships.attachesto_1:
+    type: OS::Cinder::VolumeAttachment
+    properties:
+      instance_uuid:
+        get_resource: VDU1
+      mountpoint: /data
+      volume_id:
+        get_resource: BlockStorage
+
   CP1:
     type: OS::Neutron::Port
     properties:
index e5c8d3c..edbbbe5 100644 (file)
@@ -23,6 +23,17 @@ topology_template:
             version: 6.5
       requirements:
         - high_availability: VDU2
+        - local_storage:
+            node: BlockStorage
+            relationship:
+              type: tosca.relationships.AttachesTo
+              properties:
+                location: /data
+
+    BlockStorage:
+      type: tosca.nodes.BlockStorage
+      properties:
+        size: 10 GB
 
     VDU2:
       type: tosca.nodes.nfv.VDU