From e0d37de9d0d43cc1c5ede8d3f42e271068590f4d Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez <dabarren@gmail.com>
Date: Fri, 19 Jan 2018 09:42:21 +0100
Subject: [PATCH] Fixes ceph deploy gates

- Ceph images are not being built when using depends-on a kolla build
  job.
- Sync inventory files with current ones which causes ceph to fail due
  missing groups.
- Small corrections in ceph config.yml syntax.
- fix preparse the disk only once
- enable ceph nfs only when enable_ceph_nfs is true

Co-Authored-By: Jeffrey Zhang <zhang.lei.fly@gmail.com>
Change-Id: Id0c7963bf59e2af4944834dcd16589a638e78ba5
---
 ansible/roles/ceph/tasks/config.yml |  6 ++--
 ansible/roles/ceph/tasks/deploy.yml |  4 ++-
 tests/run.yml                       | 16 ++++++----
 tests/templates/inventory.j2        | 46 ++++++++++++++++++++++++-----
 tools/setup_gate.sh                 |  4 ---
 5 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/ansible/roles/ceph/tasks/config.yml b/ansible/roles/ceph/tasks/config.yml
index 52abcae137..7aa953bfac 100644
--- a/ansible/roles/ceph/tasks/config.yml
+++ b/ansible/roles/ceph/tasks/config.yml
@@ -26,11 +26,11 @@
     - name: "ceph-rgw"
       group: ceph-rgw
     - name: "ceph-mgr"
-      group: "ceph-mgr"
+      group: ceph-mgr
     - name: "ceph-mds"
-      group: "ceph-mds"
+      group: ceph-mds
     - name: "ceph-nfs"
-      group: "ceph-nfs"
+      group: ceph-nfs
 
 - name: Copying over ceph.conf
   vars:
diff --git a/ansible/roles/ceph/tasks/deploy.yml b/ansible/roles/ceph/tasks/deploy.yml
index 937c064ad4..39dc253203 100644
--- a/ansible/roles/ceph/tasks/deploy.yml
+++ b/ansible/roles/ceph/tasks/deploy.yml
@@ -13,7 +13,9 @@
   when: inventory_hostname in groups['ceph-mgr']
 
 - include: start_nfss.yml
-  when: inventory_hostname in groups['ceph-nfs']
+  when:
+    - enable_ceph_nfs | bool
+    - inventory_hostname in groups['ceph-nfs']
 
 - include: bootstrap_osds.yml
   when: inventory_hostname in groups['ceph-osd']
diff --git a/tests/run.yml b/tests/run.yml
index d1828402c1..cb9d834a91 100644
--- a/tests/run.yml
+++ b/tests/run.yml
@@ -1,4 +1,14 @@
 ---
+- hosts: all
+  vars:
+    kolla_ansible_src_dir: "src/{{ zuul.project.canonical_hostname }}/openstack/kolla-ansible"
+    kolla_ansible_full_src_dir: "{{ zuul.executor.work_root }}/{{ kolla_ansible_src_dir }}"
+  tasks:
+    - name: Prepare ceph disks
+      script: "{{ kolla_ansible_full_src_dir }}/tests/setup_ceph_disks.sh"
+      when: scenario == "ceph"
+      become: true
+
 - hosts: primary
   vars:
     kolla_inventory_path: "/etc/kolla/inventory"
@@ -92,11 +102,6 @@
       shell: "{{ kolla_ansible_src_dir }}/tools/generate_passwords.py"
       delegate_to: "primary"
 
-    - name: Prepare ceph disks
-      script: "{{ kolla_ansible_full_src_dir }}/tests/setup_ceph_disks.sh"
-      when: scenario == "ceph"
-      become: true
-
     - name: generate ceph config overrides
       template:
         src: "{{ kolla_ansible_full_src_dir }}/tests/templates/ceph-overrides.j2"
@@ -113,6 +118,7 @@
           export NODEPOOL_TARBALLS_MIRROR=http://{{ zuul_site_mirror_fqdn }}:8080/tarballs
           export BUILD_IMAGE={{ need_build_image }}
           export KOLLA_SRC_DIR={{ ansible_env.HOME }}/src/git.openstack.org/openstack/kolla
+          export ACTION={{ scenario }}
 
           tools/setup_gate.sh
         executable: /bin/bash
diff --git a/tests/templates/inventory.j2 b/tests/templates/inventory.j2
index bd20478418..2a3efbaad8 100644
--- a/tests/templates/inventory.j2
+++ b/tests/templates/inventory.j2
@@ -10,11 +10,21 @@
 {{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_become=true ansible_user={{ hostvars[host]['ansible_user'] }}
 {% endfor %}
 
-[compute]
+# inner-compute is the groups of compute nodes which do not have
+# external reachability
+[inner-compute]
+
+# external-compute is the groups of compute nodes which can reach
+# outside
+[external-compute]
 {% for host in hostvars %}
 {{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_become=true ansible_user={{ hostvars[host]['ansible_user'] }}
 {% endfor %}
 
+[compute:children]
+inner-compute
+external-compute
+
 [storage]
 {% for host in hostvars %}
 {{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_become=true ansible_user={{ hostvars[host]['ansible_user'] }}
@@ -187,6 +197,9 @@ control
 [tacker:children]
 control
 
+[vitrage:children]
+control
+
 # Tempest
 [tempest:children]
 control
@@ -292,9 +305,15 @@ neutron
 neutron
 
 # Ceph
+[ceph-mds:children]
+ceph
+
 [ceph-mgr:children]
 ceph
 
+[ceph-nfs:children]
+ceph
+
 [ceph-mon:children]
 ceph
 
@@ -488,18 +507,12 @@ sahara
 sahara
 
 # Ceilometer
-[ceilometer-api:children]
-ceilometer
-
 [ceilometer-central:children]
 ceilometer
 
 [ceilometer-notification:children]
 ceilometer
 
-[ceilometer-collector:children]
-ceilometer
-
 [ceilometer-compute:children]
 compute
 
@@ -561,6 +574,9 @@ designate
 [designate-central:children]
 designate
 
+[designate-producer:children]
+designate
+
 [designate-mdns:children]
 network
 
@@ -598,3 +614,19 @@ tacker
 
 [tacker-conductor:children]
 tacker
+
+# Vitrage
+[vitrage-api:children]
+vitrage
+
+[vitrage-notifier:children]
+vitrage
+
+[vitrage-graph:children]
+vitrage
+
+[vitrage-collector:children]
+vitrage
+
+[vitrage-ml:children]
+vitrage
diff --git a/tools/setup_gate.sh b/tools/setup_gate.sh
index 749b3795e6..501307a18d 100755
--- a/tools/setup_gate.sh
+++ b/tools/setup_gate.sh
@@ -160,10 +160,6 @@ setup_node
 tools/kolla-ansible -i ${RAW_INVENTORY} bootstrap-servers > /tmp/logs/ansible/bootstrap-servers
 prepare_images
 
-if echo $ACTION | grep -q "ceph"; then
-    ansible-playbook -i ${RAW_INVENTORY} tests/ansible_setup_ceph_disks.yml > /tmp/logs/ansible/setup_ceph_disks
-fi
-
 # Create dummy interface for neutron
 ansible -m shell -i ${RAW_INVENTORY} -a "ip l a fake_interface type dummy" all