Optimize reconfiguration for heat

Change-Id: I0e8b16bba5c826a97a4e9bd07891f5f3fb549334
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-17 17:48:50 +08:00
parent 78b8f47bd5
commit a755e7f0a4
9 changed files with 163 additions and 161 deletions

View File

@ -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
####################

View File

@ -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

View File

@ -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] }}"

View File

@ -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

View File

@ -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

View File

@ -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 }}"

View File

@ -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

View File

@ -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']

View File

@ -3,4 +3,5 @@
- include: bootstrap_service.yml
- include: start.yml
- name: Flush handlers
meta: flush_handlers