From 7d9cb44d1f2de6a7c6001e14e5c24e7c82de59b9 Mon Sep 17 00:00:00 2001
From: "wu.chunyang" <wu.chunyang@99cloud.net>
Date: Mon, 11 Feb 2019 21:08:44 +0800
Subject: [PATCH] Restart containers when ceph.conf changed

When ceph.conf changed, we need restart some containers.

Change-Id: Iddeaf9dd4f288165fcef288e5384d79b61a0910b
Closes-Bug: #1810010
---
 ansible/roles/cinder/handlers/main.yml       | 4 ++++
 ansible/roles/cinder/tasks/ceph.yml          | 3 +++
 ansible/roles/cinder/tasks/external_ceph.yml | 4 ++--
 ansible/roles/nova/handlers/main.yml         | 4 ++++
 ansible/roles/nova/tasks/ceph.yml            | 3 +++
 ansible/roles/nova/tasks/external_ceph.yml   | 4 ++--
 6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/ansible/roles/cinder/handlers/main.yml b/ansible/roles/cinder/handlers/main.yml
index 063b5a45b9..8a2d2dde06 100644
--- a/ansible/roles/cinder/handlers/main.yml
+++ b/ansible/roles/cinder/handlers/main.yml
@@ -56,6 +56,7 @@
     service: "{{ cinder_services[service_name] }}"
     config_json: "{{ cinder_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
     cinder_conf: "{{ cinder_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    ceph_conf: "{{ ceph_confs.results|selectattr('item.key', 'equalto', service_name)|first if ceph_confs is defined else none }}"
     policy_overwriting: "{{ cinder_policy_overwriting.results|selectattr('item.key', 'equalto', service_name)|first }}"
     cinder_volume_container: "{{ check_cinder_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
   become: true
@@ -76,6 +77,7 @@
       or cinder_conf.changed | bool
       or policy_overwriting.changed | bool
       or cinder_volume_container.changed | bool
+      or ( ceph_conf is not none and ceph_conf.changed | bool )
 
 - name: Restart cinder-backup container
   vars:
@@ -83,6 +85,7 @@
     service: "{{ cinder_services[service_name] }}"
     config_json: "{{ cinder_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
     cinder_conf: "{{ cinder_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    ceph_conf: "{{ ceph_confs.results|selectattr('item.key', 'equalto', service_name)|first if ceph_confs is defined else none }}"
     policy_overwriting: "{{ cinder_policy_overwriting.results|selectattr('item.key', 'equalto', service_name)|first }}"
     cinder_backup_container: "{{ check_cinder_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
   become: true
@@ -102,3 +105,4 @@
       or cinder_conf.changed | bool
       or policy_overwriting.changed | bool
       or cinder_backup_container.changed | bool
+      or ( ceph_conf is not none and ceph_conf.changed | bool )
diff --git a/ansible/roles/cinder/tasks/ceph.yml b/ansible/roles/cinder/tasks/ceph.yml
index 719458fc8a..38e9cb148e 100644
--- a/ansible/roles/cinder/tasks/ceph.yml
+++ b/ansible/roles/cinder/tasks/ceph.yml
@@ -12,11 +12,14 @@
     dest: "{{ node_config_directory }}/{{ item.key }}/ceph.conf"
     mode: "0660"
   become: true
+  register: ceph_confs
   when:
     - item.value.enabled | bool
     - inventory_hostname in groups[item.value.group]
     - item.key in services_need_config
   with_dict: "{{ cinder_services }}"
+  notify:
+    - Restart {{ item.key }} container
 
 - include_tasks: ../../ceph_pools.yml
   vars:
diff --git a/ansible/roles/cinder/tasks/external_ceph.yml b/ansible/roles/cinder/tasks/external_ceph.yml
index 2d63d06d9e..66b735d0fc 100644
--- a/ansible/roles/cinder/tasks/external_ceph.yml
+++ b/ansible/roles/cinder/tasks/external_ceph.yml
@@ -11,14 +11,14 @@
     dest: "{{ node_config_directory }}/{{ item.key }}/ceph.conf"
     mode: "0660"
   become: true
+  register: ceph_confs
   when:
     - item.value.enabled | bool
     - inventory_hostname in groups[item.value.group]
     - item.key in services_need_config
   with_dict: "{{ cinder_services }}"
   notify:
-    - Restart cinder-volume container
-    - Restart cinder-backup container
+    - Restart {{ item.key }} container
 
 - name: Copy over Ceph keyring files for cinder-volume
   copy:
diff --git a/ansible/roles/nova/handlers/main.yml b/ansible/roles/nova/handlers/main.yml
index 9c07db7c63..a634128179 100644
--- a/ansible/roles/nova/handlers/main.yml
+++ b/ansible/roles/nova/handlers/main.yml
@@ -80,6 +80,7 @@
     service_name: "nova-libvirt"
     service: "{{ nova_services[service_name] }}"
     config_json: "{{ config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    ceph_conf: "{{ ceph_confs.results|selectattr('item', 'equalto', service_name)|first if ceph_confs is defined else none }}"
     nova_libvirt_container: "{{ check_nova_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
   become: true
   kolla_docker:
@@ -103,6 +104,7 @@
     - config_json.changed | bool
       or nova_libvirt_confs.changed | bool
       or nova_libvirt_container.changed | bool
+      or ( ceph_conf is not none and ceph_conf.changed | bool )
 
 - name: Restart nova-scheduler container
   vars:
@@ -266,6 +268,7 @@
     service: "{{ nova_services[service_name] }}"
     config_json: "{{ config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
     nova_conf: "{{ nova_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    ceph_conf: "{{ ceph_confs.results|selectattr('item', 'equalto', service_name)|first if ceph_confs is defined else none }}"
     policy_overwriting: "{{ nova_policy_overwriting.results|selectattr('item.key', 'equalto', service_name)|first }}"
     nova_compute_container: "{{ check_nova_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
   become: true
@@ -289,6 +292,7 @@
       or vcenter_ca_file | bool
       or nova_compute_release_file | bool
       or nova_compute_container.changed | bool
+      or ( ceph_conf is not none and ceph_conf.changed | bool )
 
 - name: Restart nova-compute-ironic container
   vars:
diff --git a/ansible/roles/nova/tasks/ceph.yml b/ansible/roles/nova/tasks/ceph.yml
index 76aa128447..36a6bafc6f 100644
--- a/ansible/roles/nova/tasks/ceph.yml
+++ b/ansible/roles/nova/tasks/ceph.yml
@@ -20,10 +20,13 @@
     dest: "{{ node_config_directory }}/{{ item }}/ceph.conf"
     mode: "0660"
   become: true
+  register: ceph_confs
   with_items:
     - "nova-compute"
     - "nova-libvirt"
   when: inventory_hostname in groups['compute']
+  notify:
+    - Restart {{ item }} container
 
 - include_tasks: ../../ceph_pools.yml
   vars:
diff --git a/ansible/roles/nova/tasks/external_ceph.yml b/ansible/roles/nova/tasks/external_ceph.yml
index bbba9997d5..6d5663fa39 100644
--- a/ansible/roles/nova/tasks/external_ceph.yml
+++ b/ansible/roles/nova/tasks/external_ceph.yml
@@ -51,6 +51,7 @@
     dest: "{{ node_config_directory }}/{{ item }}/"
     mode: "0660"
   become: true
+  register: ceph_confs
   with_items:
     - nova-compute
     - nova-libvirt
@@ -58,8 +59,7 @@
     - inventory_hostname in groups['compute']
     - nova_backend == "rbd"
   notify:
-    - Restart nova-compute container
-    - Restart nova-libvirt container
+    - Restart {{ item }} container
 
 - name: Pushing nova secret xml for libvirt
   template: