From 1c331739270096d6d821fb82e26d9c60924fa00f Mon Sep 17 00:00:00 2001
From: Vikram Hosakote <vhosakot@cisco.com>
Date: Thu, 3 Mar 2016 20:47:11 +0000
Subject: [PATCH] Reconfigure nova service

This patch set implements reconfiguring the nova service.

Change-Id: If078efd9ca98f815ca7830de912a4bc8916ff403
Partially-implements: bp kolla-reconfig
---
 ansible/roles/nova/tasks/do_reconfigure.yml | 212 ++++++++++++++++++++
 ansible/roles/nova/tasks/reconfigure.yml    |  10 +
 2 files changed, 222 insertions(+)
 create mode 100644 ansible/roles/nova/tasks/do_reconfigure.yml

diff --git a/ansible/roles/nova/tasks/do_reconfigure.yml b/ansible/roles/nova/tasks/do_reconfigure.yml
new file mode 100644
index 0000000000..edc48c4141
--- /dev/null
+++ b/ansible/roles/nova/tasks/do_reconfigure.yml
@@ -0,0 +1,212 @@
+---
+- name: Ensuring the nova libvirt, conductor, api, consoleauth and scheduler containers are up
+  kolla_docker:
+    name: "{{ item.name }}"
+    action: "get_container_state"
+  register: container_state
+  failed_when: container_state.Running == false
+  when: inventory_hostname in groups[item.group]
+  with_items:
+    - { name: nova_libvirt, group: compute }
+    - { name: nova_conductor, group: nova-conductor }
+    - { name: nova_api, group: nova-api }
+    - { name: nova_consoleauth, group: nova-consoleauth }
+    - { name: nova_scheduler, group: nova-scheduler }
+
+- name: Ensuring the nova_compute container is up
+  kolla_docker:
+    name: "nova_compute"
+    action: "get_container_state"
+  register: container_state
+  failed_when: container_state.Running == false
+  when:
+    - inventory_hostname in groups['compute']
+    - not enable_nova_fake | bool
+
+- name: Ensuring the nova_compute_ironic container is up
+  kolla_docker:
+    name: "nova_compute_ironic"
+    action: "get_container_state"
+  register: container_state
+  failed_when: container_state.Running == false
+  when:
+    - inventory_hostname in groups['nova-compute-ironic']
+    - enable_ironic | bool
+
+- name: Ensuring the nova_novncproxy container is up
+  kolla_docker:
+    name: "nova_novncproxy"
+    action: "get_container_state"
+  register: container_state
+  failed_when: container_state.Running == false
+  when:
+    - inventory_hostname in groups['nova-novncproxy']
+    - nova_console == 'novnc'
+
+- name: Ensuring the nova_spicehtml5proxy container is up
+  kolla_docker:
+    name: "nova_spicehtml5proxy"
+    action: "get_container_state"
+  register: container_state
+  failed_when: container_state.Running == false
+  when:
+    - inventory_hostname in groups['nova-spicehtml5proxy']
+    - nova_console == 'spice'
+
+- include: config.yml
+
+- name: Check the configs for nova libvirt, conductor, api, consoleauth and scheduler containers
+  command: docker exec {{ item.name }} /usr/local/bin/kolla_set_configs --check
+  changed_when: false
+  failed_when: false
+  register: check_results
+  when: inventory_hostname in groups[item.group]
+  with_items:
+    - { name: nova_libvirt, group: compute }
+    - { name: nova_conductor, group: nova-conductor }
+    - { name: nova_api, group: nova-api }
+    - { name: nova_consoleauth, group: nova-consoleauth }
+    - { name: nova_scheduler, group: nova-scheduler }
+
+- name: Check the configs in the nova_compute container
+  command: docker exec nova_compute /usr/local/bin/kolla_set_configs --check
+  changed_when: false
+  failed_when: false
+  when:
+    - inventory_hostname in groups['compute']
+    - not enable_nova_fake | bool
+
+- name: Check the configs in the nova_compute_ironic container
+  command: docker exec nova_compute_ironic /usr/local/bin/kolla_set_configs --check
+  changed_when: false
+  failed_when: false
+  when:
+    - inventory_hostname in groups['nova-compute-ironic']
+    - enable_ironic | bool
+
+- name: Check the configs in the nova_novncproxy container
+  command: docker exec nova_novncproxy /usr/local/bin/kolla_set_configs --check
+  changed_when: false
+  failed_when: false
+  when:
+    - inventory_hostname in groups['nova-novncproxy']
+    - nova_console == 'novnc'
+
+- name: Check the configs in the nova_spicehtml5proxy container
+  command: docker exec nova_spicehtml5proxy /usr/local/bin/kolla_set_configs --check
+  changed_when: false
+  failed_when: false
+  when:
+    - inventory_hostname in groups['nova-spicehtml5proxy']
+    - nova_console == 'spice'
+
+# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS'
+# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE',
+# just remove the container and start again
+- name: Containers config strategy for nova libvirt, conductor, api, consoleauth and scheduler containers
+  kolla_docker:
+    name: "{{ item.name }}"
+    action: "get_container_env"
+  register: container_envs
+  when: inventory_hostname in groups[item.group]
+  with_items:
+    - { name: nova_libvirt, group: compute }
+    - { name: nova_conductor, group: nova-conductor }
+    - { name: nova_api, group: nova-api }
+    - { name: nova_consoleauth, group: nova-consoleauth }
+    - { name: nova_scheduler, group: nova-scheduler }
+
+- name: Remove the nova libvirt, conductor, api, consoleauth and scheduler containers
+  kolla_docker:
+    name: "{{ item[0]['name'] }}"
+    action: "remove_container"
+  register: remove_containers
+  when:
+    - config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE'
+    - item[2]['rc'] == 1
+    - inventory_hostname in groups[item[0]['group']]
+  with_together:
+    - [{ name: nova_libvirt, group: compute },
+       { name: nova_conductor, group: nova-conductor },
+       { name: nova_api, group: nova-api },
+       { name: nova_consoleauth, group: nova-consoleauth },
+       { name: nova_scheduler, group: nova-scheduler }]
+    - container_envs.results
+    - check_results.results
+
+- include: start.yml
+  when: remove_containers.changed
+
+- name: Restart the nova libvirt, conductor, api, consoleauth and scheduler containers
+  kolla_docker:
+    name: "{{ item[0]['name'] }}"
+    action: "restart_container"
+  when:
+    - config_strategy == 'COPY_ALWAYS'
+    - item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
+    - item[2]['rc'] == 1
+    - inventory_hostname in groups[item[0]['group']]
+  with_together:
+    - [{ name: nova_libvirt, group: compute },
+       { name: nova_conductor, group: nova-conductor },
+       { name: nova_api, group: nova-api },
+       { name: nova_consoleauth, group: nova-consoleauth },
+       { name: nova_scheduler, group: nova-scheduler }]
+    - container_envs.results
+    - check_results.results
+
+- name: Restart the nova_compute container
+  kolla_docker:
+    name: "nova_compute"
+    action: "restart_container"
+  when:
+    - config_strategy == 'COPY_ALWAYS'
+    - item[0]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
+    - item[1]['rc'] == 1
+    - inventory_hostname in groups['compute']
+    - not enable_nova_fake | bool
+  with_together:
+    - container_envs.results
+    - check_results.results
+
+- name: Restart the nova_compute_ironic container
+  kolla_docker:
+    name: "nova_compute_ironic"
+    action: "restart_container"
+  when:
+    - config_strategy == 'COPY_ALWAYS'
+    - item[0]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
+    - item[1]['rc'] == 1
+    - inventory_hostname in groups['nova-compute-ironic']
+    - enable_ironic | bool
+  with_together:
+    - container_envs.results
+    - check_results.results
+
+- name: Restart the nova_novncproxy container
+  kolla_docker:
+    name: "nova_novncproxy"
+    action: "restart_container"
+  when:
+    - config_strategy == 'COPY_ALWAYS'
+    - item[0]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
+    - item[1]['rc'] == 1
+    - inventory_hostname in groups['nova-novncproxy']
+    - nova_console == 'novnc'
+  with_together:
+    - container_envs.results
+    - check_results.results
+
+- name: Restart the nova_spicehtml5proxy container
+  kolla_docker:
+    name: "nova_spicehtml5proxy"
+    action: "restart_container"
+  when:
+    - config_strategy == 'COPY_ALWAYS'
+    - item[0]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
+    - item[1]['rc'] == 1
+    - inventory_hostname in groups['nova-spicehtml5proxy']
+    - nova_console == 'spice'
+  with_together:
+    - container_envs.results
+    - check_results.results
diff --git a/ansible/roles/nova/tasks/reconfigure.yml b/ansible/roles/nova/tasks/reconfigure.yml
index ed97d539c0..5c4cf7d3eb 100644
--- a/ansible/roles/nova/tasks/reconfigure.yml
+++ b/ansible/roles/nova/tasks/reconfigure.yml
@@ -1 +1,11 @@
 ---
+- include: do_reconfigure.yml
+  serial: "30%"
+  when: inventory_hostname in groups['compute']
+        or inventory_hostname in groups['nova-conductor']
+        or inventory_hostname in groups['nova-api']
+        or inventory_hostname in groups['nova-consoleauth']
+        or inventory_hostname in groups['nova-scheduler']
+        or inventory_hostname in groups['nova-compute-ironic']
+        or inventory_hostname in groups['nova-novncproxy']
+        or inventory_hostname in groups['nova-spicehtml5proxy']