From edb842e10a0464bf747d042a629614c8a5715f55 Mon Sep 17 00:00:00 2001 From: Mauricio Lima Date: Mon, 23 Jan 2017 11:43:57 -0300 Subject: [PATCH] Optimize reconfiguration for panko Co-Authored-By: caoyuan Change-Id: I9ee4345b3cd5bdeda859fda07f972b80f3e20689 Partially-implements: blueprint better-reconfigure --- ansible/roles/panko/defaults/main.yml | 12 +++ ansible/roles/panko/handlers/main.yml | 24 ++++++ .../roles/panko/tasks/bootstrap_service.yml | 11 ++- ansible/roles/panko/tasks/config.yml | 74 ++++++++++++++----- ansible/roles/panko/tasks/deploy.yml | 4 +- ansible/roles/panko/tasks/reconfigure.yml | 64 +--------------- ansible/roles/panko/tasks/start.yml | 12 --- ansible/roles/panko/tasks/upgrade.yml | 3 +- 8 files changed, 103 insertions(+), 101 deletions(-) create mode 100644 ansible/roles/panko/handlers/main.yml delete mode 100644 ansible/roles/panko/tasks/start.yml diff --git a/ansible/roles/panko/defaults/main.yml b/ansible/roles/panko/defaults/main.yml index 4986300410..7668d943de 100644 --- a/ansible/roles/panko/defaults/main.yml +++ b/ansible/roles/panko/defaults/main.yml @@ -1,6 +1,18 @@ --- project_name: "panko" +panko_services: + panko-api: + container_name: panko_api + group: panko-api + enabled: true + image: "{{ panko_api_image_full }}" + volumes: + - "{{ node_config_directory }}/panko-api/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + + #################### # Database #################### diff --git a/ansible/roles/panko/handlers/main.yml b/ansible/roles/panko/handlers/main.yml new file mode 100644 index 0000000000..90c323ba61 --- /dev/null +++ b/ansible/roles/panko/handlers/main.yml @@ -0,0 +1,24 @@ +--- +- name: Restart panko-api container + vars: + service_name: "panko-api" + service: "{{ panko_services[service_name] }}" + config_json: "{{ panko_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + panko_conf: "{{ panko_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ panko_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + panko_api_container: "{{ check_panko_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or panko_conf.changed | bool + or panko_wsgi.changed | bool + or policy_json.changed | bool + or panko_api_container.changed | bool diff --git a/ansible/roles/panko/tasks/bootstrap_service.yml b/ansible/roles/panko/tasks/bootstrap_service.yml index 9ac8bab2e7..16d4e5e195 100644 --- a/ansible/roles/panko/tasks/bootstrap_service.yml +++ b/ansible/roles/panko/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running panko bootstrap container + vars: + panko_api: "{{ panko_services['panko-api'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -8,14 +10,11 @@ KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" PANKO_DATABASE_TYPE: "{{ panko_database_type }}" - image: "{{ panko_api_image_full }}" + image: "{{ panko_api.image }}" labels: BOOTSTRAP: name: "bootstrap_panko" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/panko-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" + volumes: "{{ panko_api.volumes }}" run_once: True - delegate_to: "{{ groups['panko-api'][0] }}" + delegate_to: "{{ groups[panko_api.group][0] }}" diff --git a/ansible/roles/panko/tasks/config.yml b/ansible/roles/panko/tasks/config.yml index 71d608d4b7..1b8e0a4c9e 100644 --- a/ansible/roles/panko/tasks/config.yml +++ b/ansible/roles/panko/tasks/config.yml @@ -1,41 +1,61 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "panko-api" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ panko_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "panko-api" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: panko_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ panko_services }}" + notify: + - Restart panko-api container - name: Copying over panko.conf merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/panko.conf.j2" - "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/panko.conf" - - "{{ node_custom_config }}/panko/{{ item }}.conf" - - "{{ node_custom_config }}/panko/{{ inventory_hostname }}/{{ item }}.conf" - dest: "{{ node_config_directory }}/{{ item }}/panko.conf" - with_items: - - "panko-api" + - "{{ node_custom_config }}/panko/{{ item.key }}.conf" + - "{{ node_custom_config }}/panko/{{ inventory_hostname }}/{{ item.key }}.conf" + dest: "{{ node_config_directory }}/{{ item.key }}/panko.conf" + register: panko_confs + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ panko_services }}" + notify: + - Restart panko-api container - name: Copying over wsgi-panko files for services + vars: + service: "{{ panko_services['panko-api']}}" template: src: "wsgi-panko.conf.j2" dest: "{{ node_config_directory }}/{{ item }}/wsgi-panko.conf" + register: panko_wsgi + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool with_items: - "panko-api" + notify: + - Restart panko-api container - name: Check if policies shall be overwritten local_action: stat path="{{ node_custom_config }}/panko/policy.json" @@ -44,8 +64,28 @@ - name: Copying over existing policy.json template: src: "{{ node_custom_config }}/panko/policy.json" - dest: "{{ node_config_directory }}/{{ item }}/policy.json" - with_items: - - "panko-api" + dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" + register: panko_policy_jsons when: - panko_policy.stat.exists + - panko_policy.stat.exists + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ panko_services }}" + notify: + - Restart panko-api container + +- name: Check panko containers + kolla_docker: + action: "compare_container" + common_options: "{{ docker_common_options }}" + name: "{{ item.value.container_name }}" + image: "{{ item.value.image }}" + volumes: "{{ item.value.volumes }}" + register: check_panko_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ panko_services }}" + notify: + - Restart panko-api container diff --git a/ansible/roles/panko/tasks/deploy.yml b/ansible/roles/panko/tasks/deploy.yml index 063a4691cd..933bd9459d 100644 --- a/ansible/roles/panko/tasks/deploy.yml +++ b/ansible/roles/panko/tasks/deploy.yml @@ -8,5 +8,5 @@ - include: bootstrap.yml when: inventory_hostname in groups['panko-api'] -- include: start.yml - when: inventory_hostname in groups['panko-api'] +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/panko/tasks/reconfigure.yml b/ansible/roles/panko/tasks/reconfigure.yml index d58756d0d1..e078ef1318 100644 --- a/ansible/roles/panko/tasks/reconfigure.yml +++ b/ansible/roles/panko/tasks/reconfigure.yml @@ -1,64 +1,2 @@ --- -- name: Ensuring the containers 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: panko_api, group: panko-api } - -- include: config.yml - -- name: Check the configs - 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: panko_api, group: panko-api } - -# 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 - kolla_docker: - name: "{{ item.name }}" - action: "get_container_env" - register: container_envs - when: inventory_hostname in groups[item.group] - with_items: - - { name: panko_api, group: panko-api } - -- name: Remove the containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "remove_container" - register: remove_containers - when: - - inventory_hostname in groups[item[0]['group']] - - config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE' - - item[2]['rc'] == 1 - with_together: - - [{ name: panko_api, group: panko-api }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" - -- include: start.yml - when: remove_containers.changed - -- name: Restart containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "restart_container" - when: - - inventory_hostname in groups[item[0]['group']] - - config_strategy == 'COPY_ALWAYS' - - item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE' - - item[2]['rc'] == 1 - with_together: - - [{ name: panko_api, group: panko-api }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/panko/tasks/start.yml b/ansible/roles/panko/tasks/start.yml deleted file mode 100644 index 12f9b0efe8..0000000000 --- a/ansible/roles/panko/tasks/start.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Starting panko-api container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ panko_api_image_full }}" - name: "panko_api" - volumes: - - "{{ node_config_directory }}/panko-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['panko-api'] diff --git a/ansible/roles/panko/tasks/upgrade.yml b/ansible/roles/panko/tasks/upgrade.yml index 308053080c..c38db1adf4 100644 --- a/ansible/roles/panko/tasks/upgrade.yml +++ b/ansible/roles/panko/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: bootstrap_service.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers