From: Manuel Buil <mbuil@suse.com>
Date: Tue, 30 Oct 2018 14:37:39 +0000 (+0100)
Subject: Bug fix: Fetch vm names from idf
X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F29%2F64229%2F8;p=releng-xci.git

Bug fix: Fetch vm names from idf

Currently we were taking the names of the nodes to be generated from the
NODE_NAMES variable whereas ansible was fetching the names from the
dynamic_inventory.py which uses idf. This resulted in problems: when
doing ha, ansible was provisioning a compute as a controller and
vicebersa.

This patch forces create_nodes role to fetch the name from idf and thus
align with the naming schema of ansible

deploy-scenario:k8-calico-nofeature
installer-type:kubespray

Change-Id: Id1473727405701fd9ed0cb2f1394ee8676cec337
Signed-off-by: Manuel Buil <mbuil@suse.com>
---

diff --git a/xci/playbooks/roles/create-nodes/README.md b/xci/playbooks/roles/create-nodes/README.md
index bf079b9e..bf190296 100644
--- a/xci/playbooks/roles/create-nodes/README.md
+++ b/xci/playbooks/roles/create-nodes/README.md
@@ -71,7 +71,7 @@ vm_disk_cache: Disk cache mode to use by VMs disk.
                if that is not set, to 'writeback'.
 
 node_names: Space-separated names for nodes to be created.
-            Defaults to shell variable 'NODE_NAMES'.
+            It is taken from the hostnames variable in idf.
             If not set, VM names will be autogenerated.
             Note that independent on the number of names in this list,
             at most 'test_vm_num_nodes' VMs will be created.
diff --git a/xci/playbooks/roles/create-nodes/defaults/main.yml b/xci/playbooks/roles/create-nodes/defaults/main.yml
index 02a429cf..889f9c10 100644
--- a/xci/playbooks/roles/create-nodes/defaults/main.yml
+++ b/xci/playbooks/roles/create-nodes/defaults/main.yml
@@ -5,7 +5,6 @@ baremetal_json_file: '/tmp/baremetal.json'
 # We collect these parameters from the pdf
 vm_nic: "virtio"
 vm_disk_cache: unsafe
-node_names: "{{ lookup('env', 'NODE_NAMES').split() }}"
 node_groups: {}
 node_default_groups: "{{ lookup('env', 'DEFAULT_HOST_GROUPS').split() | default(['baremetal'], true) }}"
 
diff --git a/xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml b/xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml
index c067781f..8aeea321 100644
--- a/xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml
+++ b/xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml
@@ -28,12 +28,15 @@
 - name: "Generating the json describing baremetal nodes"
   block:
 
+  - set_fact:
+      node_name: "{{ ('kubespray' in installer_type) | ternary(idf.kubespray.hostnames[item.name], idf.osa.hostnames[item.name]) }}"
+
   - set_fact:
       host_group: "{{ node_default_groups }}"
 
   - set_fact:
-      host_group: "{{ node_default_groups | union(node_groups[item.name]) }}"
-    when: node_groups[item.name] is defined
+      host_group: "{{ node_default_groups | union(node_groups[node_name]) }}"
+    when: node_groups[node_name] is defined
 
   - name: BAREMETAL - Fetch the ip
     set_fact:
@@ -46,8 +49,8 @@
   - name: BAREMETAL - set the json entry for baremetal nodes
     set_fact:
       node_data:
-        name: "{{ item.name }}"
-        uuid: "{{ item.name | to_uuid }}"
+        name: "{{ node_name }}"
+        uuid: "{{ node_name | to_uuid }}"
         host_groups: "{{ host_group }}"
         driver: "ipmi"
         driver_info:
@@ -74,6 +77,6 @@
 
   - name: BAREMETAL - add created node info
     set_fact:
-      nodes_json_data: "{{ nodes_json_data | combine({item.name: node_data}) }}"
+      nodes_json_data: "{{ nodes_json_data | combine({node_name: node_data}) }}"
 
   when: (num_nodes | int) > (nodes_json_data | length | int) + 1
diff --git a/xci/playbooks/roles/create-nodes/tasks/create_vm.yml b/xci/playbooks/roles/create-nodes/tasks/create_vm.yml
index 10989870..8934fb6a 100644
--- a/xci/playbooks/roles/create-nodes/tasks/create_vm.yml
+++ b/xci/playbooks/roles/create-nodes/tasks/create_vm.yml
@@ -2,7 +2,7 @@
 - name: "Creating VM"
   block:
   - set_fact:
-      vm_name: "{{ node_names[item.0 | int] }}"
+      vm_name: "{{ ('kubespray' in installer_type) | ternary(idf.kubespray.hostnames[item.1.name], idf.osa.hostnames[item.1.name]) }}"
 
   - set_fact:
       vm_log_file: "{{ node_logdir }}/{{ vm_name }}_console.log"