Change the way how volume map is constructed 29/95129/1
authorMichal Zegan <m.zegan@samsung.com>
Thu, 5 Sep 2019 16:36:47 +0000 (18:36 +0200)
committerMichal Zegan <m.zegan@samsung.com>
Fri, 6 Sep 2019 10:26:09 +0000 (12:26 +0200)
This commit modifies volume handling in heat template in cicdansible.
Namely, it simplifies the generation of node to volume list mapping and makes it
more readable and understandable, and also
more flexible, because now parts of it could be
conditionalized. This is required for a followup commit.

Change-Id: I204aefd819f40050a2cb9e6a031dfb2c62da1f48
Issue-ID: OOM-2042
Signed-off-by: Michal Zegan <m.zegan@samsung.com>
tools/cicdansible/heat/installer.yaml
tools/cicdansible/heat/node.yaml

index 8fff3a7..7dd585d 100644 (file)
@@ -256,6 +256,33 @@ resources:
     properties:
       floatingip_id: { get_param: installer_ip }
       port_id: { get_attr: [installer, port_id] }
+  #Map of node volumes, taken from volumes output param.
+  node_volumes:
+    type: OS::Heat::Value
+    properties:
+      type: json
+      #We need yaql transformation to be done on the volume map.
+      value:
+        yaql:
+          data:
+            #This is a map of node number to value of "volumes" attribute, that contains
+            #a list of volumes written as pairs [volumeid, mountpoint].
+            volumes: { get_attr: [nodes, attributes, volumes] }
+          #We need yaql expressions to transform node numbers to node names in the form "node0" and similar.
+          #However we don't need anything more complicated.
+          expression: "$.data.volumes?.items()?.toDict('node'+str($[0]), $[1])"
+  #List of infra specific volumes (not a map as above).
+  infra_volumes:
+    type: OS::Heat::Value
+    properties:
+      value:
+        - [{ get_resource: resources_storage }, "/opt/onap"]
+  #Contains node0 specific volume list.
+  node0_volumes:
+    type: OS::Heat::Value
+    properties:
+      value:
+        - [{ get_resource: nfs_storage }, "/dockerdata-nfs"]
 #Output values
 outputs:
   installer_ip:
@@ -270,14 +297,10 @@ outputs:
   volumes:
     description: "map of volumes per each instance"
     value:
+      #Can do deep merging only with yaql.
       yaql:
         data:
-          resources_volid: { get_resource: resources_storage }
-          nfs_volid: { get_resource: nfs_storage }
-          docker_volids: { get_attr: [nodes, docker_storage_id] }
-        #This is going to create a map, where keys are instance names, and values are lists of
-        #pairs of volume ids and their mount points.
-        #This is done by merging few generated maps together, base map is taken by
-        #enumerating over docker storage volumes and transforming them into a map like
-        #{"node0"=>["volid","/var/lib/docker"],...], node1=>...}
-        expression: 'dict($.data.docker_volids.enumerate().select(["node"+str($[0]), [[$[1], "/var/lib/docker"]]])).mergeWith({"infra" => [[$.data.resources_volid, "/opt/onap"]], "node0" => [[$.data.nfs_volid, "/dockerdata-nfs"]]})'
+          node_volumes: { get_attr: [node_volumes, value]}
+          infra_volumes: { infra: { get_attr: [infra_volumes, value] }}
+          node0_volumes: {node0: { get_attr: [node0_volumes, value] }}
+        expression: "$.data.node_volumes?.mergeWith($.data.infra_volumes)?.mergeWith($.data.node0_volumes)"
index b6048d8..7f6af35 100644 (file)
@@ -55,5 +55,5 @@ outputs:
     value: { get_attr: ["instance", "port_id"] }
   ip:
     value: { get_attr: ["instance", "ip"] }
-  docker_storage_id:
-    value: { get_resource: docker_storage }
+  volumes:
+    value: [[{ get_resource: docker_storage }, "/var/lib/docker"]]