From a755e7f0a47730696066fb7fbcd106e02e04d38d Mon Sep 17 00:00:00 2001 From: caoyuan Date: Tue, 17 Jan 2017 17:48:50 +0800 Subject: [PATCH] Optimize reconfiguration for heat Change-Id: I0e8b16bba5c826a97a4e9bd07891f5f3fb549334 Partially-implements: blueprint better-reconfigure --- ansible/roles/heat/defaults/main.yml | 29 +++++++ ansible/roles/heat/handlers/main.yml | 66 ++++++++++++++++ .../roles/heat/tasks/bootstrap_service.yml | 11 ++- ansible/roles/heat/tasks/config.yml | 76 +++++++++++++------ ansible/roles/heat/tasks/deploy.yml | 6 +- ansible/roles/heat/tasks/pull.yml | 23 ++---- ansible/roles/heat/tasks/reconfigure.yml | 74 +----------------- ansible/roles/heat/tasks/start.yml | 36 --------- ansible/roles/heat/tasks/upgrade.yml | 3 +- 9 files changed, 163 insertions(+), 161 deletions(-) create mode 100644 ansible/roles/heat/handlers/main.yml delete mode 100644 ansible/roles/heat/tasks/start.yml diff --git a/ansible/roles/heat/defaults/main.yml b/ansible/roles/heat/defaults/main.yml index 5b6999cdec..9897cd2007 100644 --- a/ansible/roles/heat/defaults/main.yml +++ b/ansible/roles/heat/defaults/main.yml @@ -1,6 +1,35 @@ --- project_name: "heat" +heat_services: + heat-api: + container_name: heat_api + group: heat-api + enabled: true + image: "{{ heat_api_image_full }}" + volumes: + - "{{ node_config_directory }}/heat-api/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + heat-api-cfn: + container_name: heat_api_cfn + group: heat-api-cfn + enabled: true + image: "{{ heat_api_cfn_image_full }}" + volumes: + - "{{ node_config_directory }}/heat-api-cfn/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + heat-engine: + container_name: heat_engine + group: heat-engine + enabled: true + image: "{{ heat_engine_image_full }}" + volumes: + - "{{ node_config_directory }}/heat-engine/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + #################### # Database #################### diff --git a/ansible/roles/heat/handlers/main.yml b/ansible/roles/heat/handlers/main.yml new file mode 100644 index 0000000000..94f0b4aa29 --- /dev/null +++ b/ansible/roles/heat/handlers/main.yml @@ -0,0 +1,66 @@ +--- +- name: Restart heat-api container + vars: + service_name: "heat-api" + service: "{{ heat_services[service_name] }}" + config_json: "{{ heat_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + heat_conf: "{{ heat_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ heat_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + heat_api_container: "{{ check_heat_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: + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or heat_conf.changed | bool + or policy_json.changed | bool + or heat_api_container.changed | bool + +- name: Restart heat-api-cfn container + vars: + service_name: "heat-api-cfn" + service: "{{ heat_services[service_name] }}" + config_json: "{{ heat_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + heat_conf: "{{ heat_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ heat_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + heat_api_cfn_container: "{{ check_heat_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: + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or heat_conf.changed | bool + or policy_json.changed | bool + or heat_api_cfn_container.changed | bool + +- name: Restart heat-engine container + vars: + service_name: "heat-engine" + service: "{{ heat_services[service_name] }}" + config_json: "{{ heat_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + heat_conf: "{{ heat_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ heat_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + heat_engine_container: "{{ check_heat_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: + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or heat_conf.changed | bool + or policy_json.changed | bool + or heat_engine_container.changed | bool diff --git a/ansible/roles/heat/tasks/bootstrap_service.yml b/ansible/roles/heat/tasks/bootstrap_service.yml index f3d874c1a5..40e93a9c9c 100644 --- a/ansible/roles/heat/tasks/bootstrap_service.yml +++ b/ansible/roles/heat/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running Heat bootstrap container + vars: + heat_api: "{{ heat_services['heat-api'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -13,14 +15,11 @@ OS_PASSWORD: "{{ openstack_auth.password }}" OS_PROJECT_NAME: "{{ openstack_auth.project_name }}" HEAT_DOMAIN_ADMIN_PASSWORD: "{{ heat_domain_admin_password }}" - image: "{{ heat_api_image_full }}" + image: "{{ heat_api.image }}" labels: BOOTSTRAP: name: "bootstrap_heat" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/heat-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" + volumes: "{{ heat_api.volumes }}" run_once: True - delegate_to: "{{ groups['heat-api'][0] }}" + delegate_to: "{{ groups[heat_api.group][0] }}" diff --git a/ansible/roles/heat/tasks/config.yml b/ansible/roles/heat/tasks/config.yml index 125062f905..232f04a8e5 100644 --- a/ansible/roles/heat/tasks/config.yml +++ b/ansible/roles/heat/tasks/config.yml @@ -1,22 +1,25 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "heat-api" - - "heat-api-cfn" - - "heat-engine" + when: inventory_hostname in groups[item.value.group] + with_dict: "{{ heat_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "heat-api" - - "heat-api-cfn" - - "heat-engine" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: heat_config_jsons + when: + - item.value.enabled | bool + - inventory_hostname in groups[item.value.group] + with_dict: "{{ heat_services }}" + notify: + - Restart heat-api container + - Restart heat-api-cfn container + - Restart heat-engine container - name: Copying over the heat-engine environment file template: @@ -28,20 +31,25 @@ - name: Copying over heat.conf merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/heat.conf.j2" - "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/heat.conf" - - "{{ node_custom_config }}/heat/{{ item }}.conf" + - "{{ node_custom_config }}/heat/{{ item.key }}.conf" - "{{ node_custom_config }}/heat/{{ inventory_hostname }}/heat.conf" - dest: "{{ node_config_directory }}/{{ item }}/heat.conf" - with_items: - - "heat-api" - - "heat-api-cfn" - - "heat-engine" + dest: "{{ node_config_directory }}/{{ item.key }}/heat.conf" + register: heat_confs + when: + - item.value.enabled | bool + - inventory_hostname in groups[item.value.group] + with_dict: "{{ heat_services }}" + notify: + - Restart heat-api container + - Restart heat-api-cfn container + - Restart heat-engine container - name: Check if policies shall be overwritten local_action: stat path="{{ node_custom_config }}/heat/policy.json" @@ -50,10 +58,30 @@ - name: Copying over existing policy.json template: src: "{{ node_custom_config }}/heat/policy.json" - dest: "{{ node_config_directory }}/{{ item }}/policy.json" - with_items: - - "heat-api" - - "heat-api-cfn" - - "heat-engine" + dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" + register: heat_policy_jsons when: - heat_policy.stat.exists + - heat_policy.stat.exists + - inventory_hostname in groups[item.value.group] + with_dict: "{{ heat_services }}" + notify: + - Restart heat-api container + - Restart heat-api-cfn container + - Restart heat-engine container + +- name: Check heat 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_heat_containers + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ heat_services }}" + notify: + - Restart heat-api container + - Restart heat-api-cfn container + - Restart heat-engine container diff --git a/ansible/roles/heat/tasks/deploy.yml b/ansible/roles/heat/tasks/deploy.yml index a27fbf2ccc..2607a81a52 100644 --- a/ansible/roles/heat/tasks/deploy.yml +++ b/ansible/roles/heat/tasks/deploy.yml @@ -10,7 +10,5 @@ - include: bootstrap.yml when: inventory_hostname in groups['heat-api'] -- include: start.yml - when: inventory_hostname in groups['heat-api'] or - inventory_hostname in groups['heat-api-cfn'] or - inventory_hostname in groups['heat-engine'] +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/heat/tasks/pull.yml b/ansible/roles/heat/tasks/pull.yml index b671b7b253..983bef4d25 100644 --- a/ansible/roles/heat/tasks/pull.yml +++ b/ansible/roles/heat/tasks/pull.yml @@ -1,21 +1,10 @@ --- -- name: Pulling heat-api image +- name: Pulling heat images kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ heat_api_image_full }}" - when: inventory_hostname in groups['heat-api'] - -- name: Pulling heat-api-cfn image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ heat_api_cfn_image_full }}" - when: inventory_hostname in groups['heat-api-cfn'] - -- name: Pulling heat-engine image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ heat_engine_image_full }}" - when: inventory_hostname in groups['heat-engine'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ heat_services }}" diff --git a/ansible/roles/heat/tasks/reconfigure.yml b/ansible/roles/heat/tasks/reconfigure.yml index 1e4bfeacd5..e078ef1318 100644 --- a/ansible/roles/heat/tasks/reconfigure.yml +++ b/ansible/roles/heat/tasks/reconfigure.yml @@ -1,74 +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: heat_api, group: heat-api } - - { name: heat_api_cfn, group: heat-api-cfn } - - { name: heat_engine, group: heat-engine } - -- 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: heat_api, group: heat-api } - - { name: heat_api_cfn, group: heat-api-cfn } - - { name: heat_engine, group: heat-engine } - -# 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: heat_api, group: heat-api } - - { name: heat_api_cfn, group: heat-api-cfn } - - { name: heat_engine, group: heat-engine } - -- 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: heat_api, group: heat-api }, - { name: heat_api_cfn, group: heat-api-cfn }, - { name: heat_engine, group: heat-engine }] - - "{{ 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: heat_api, group: heat-api }, - { name: heat_api_cfn, group: heat-api-cfn }, - { name: heat_engine, group: heat-engine }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/heat/tasks/start.yml b/ansible/roles/heat/tasks/start.yml deleted file mode 100644 index c1238e74e3..0000000000 --- a/ansible/roles/heat/tasks/start.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- name: Starting heat-api container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ heat_api_image_full }}" - name: "heat_api" - volumes: - - "{{ node_config_directory }}/heat-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['heat-api'] - -- name: Starting heat-api-cfn container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ heat_api_cfn_image_full }}" - name: "heat_api_cfn" - volumes: - - "{{ node_config_directory }}/heat-api-cfn/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['heat-api-cfn'] - -- name: Starting heat-engine container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ heat_engine_image_full }}" - name: "heat_engine" - volumes: - - "{{ node_config_directory }}/heat-engine/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['heat-engine'] diff --git a/ansible/roles/heat/tasks/upgrade.yml b/ansible/roles/heat/tasks/upgrade.yml index 308053080c..c38db1adf4 100644 --- a/ansible/roles/heat/tasks/upgrade.yml +++ b/ansible/roles/heat/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: bootstrap_service.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers