Optimize reconfigure action for cinder

Co-Authored-By: Mauricio Lima <mauriciolimab@gmail.com>
Change-Id: I8718c4a63f1d645f3e947f8ce90d196f9cbfd91a
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-19 12:42:27 +08:00 committed by Mauricio Lima
parent 5e1217903f
commit 60d24417df
9 changed files with 214 additions and 210 deletions

View File

@ -1,6 +1,52 @@
--- ---
project_name: "cinder" project_name: "cinder"
cinder_services:
cinder-api:
container_name: cinder_api
group: cinder-api
enabled: true
image: "{{ cinder_api_image_full }}"
volumes:
- "{{ node_config_directory }}/cinder-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
cinder-scheduler:
container_name: cinder_scheduler
group: cinder-scheduler
enabled: true
image: "{{ cinder_scheduler_image_full }}"
volumes:
- "{{ node_config_directory }}/cinder-scheduler/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
cinder-volume:
container_name: cinder_volume
group: cinder-volume
enabled: true
image: "{{ cinder_volume_image_full }}"
volumes:
- "{{ node_config_directory }}/cinder-volume/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "/dev/:/dev/"
- "/run/:/run/:shared"
- "{% if enable_iscsid | bool %}cinder:/var/lib/cinder{% endif %}"
- "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}"
- "kolla_logs:/var/log/kolla/"
cinder-backup:
container_name: cinder_backup
group: cinder-backup
enabled: true
image: "{{ cinder_backup_image_full }}"
volumes:
- "{{ node_config_directory }}/cinder-backup/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "/dev/:/dev/"
- "/run/:/run/:shared"
- "{% if enable_cinder_backend_lvm | bool %}cinder:/var/lib/cinder{% endif %}"
- "{% if enable_cinder_backend_lvm | bool %}iscsi_info:/etc/iscsi{% endif %}"
- "kolla_logs:/var/log/kolla/"
#################### ####################
# Ceph # Ceph
#################### ####################

View File

@ -0,0 +1,92 @@
---
- name: Restart cinder-api container
vars:
service_name: "cinder-api"
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 }}"
policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
cinder_api_container: "{{ check_cinder_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 cinder_conf.changed | bool
or policy_json.changed | bool
or cinder_api_container.changed |
- name: Restart cinder-scheduler container
vars:
service_name: "cinder-scheduler"
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 }}"
policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
cinder_scheduler_container: "{{ check_cinder_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 cinder_conf.changed | bool
or policy_json.changed | bool
or cinder_scheduler_container.changed | bool
- name: Restart cinder-volume container
vars:
service_name: "cinder-volume"
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 }}"
policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
cinder_volume_container: "{{ check_cinder_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 cinder_conf.changed | bool
or policy_json.changed | bool
or cinder_volume_container.changed | bool
- name: Restart cinder-backup container
vars:
service_name: "cinder-backup"
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 }}"
policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
cinder_backup_container: "{{ check_cinder_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 cinder_conf.changed | bool
or policy_json.changed | bool
or cinder_backup_container.changed | bool

View File

@ -1,5 +1,7 @@
--- ---
- name: Running Cinder bootstrap container - name: Running Cinder bootstrap container
vars:
cinder_api: "{{ cinder_services['cinder-api'] }}"
kolla_docker: kolla_docker:
action: "start_container" action: "start_container"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
@ -7,14 +9,11 @@
environment: environment:
KOLLA_BOOTSTRAP: KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
image: "{{ cinder_api_image_full }}" image: "{{ cinder_api.image }}"
labels: labels:
BOOTSTRAP: BOOTSTRAP:
name: "bootstrap_cinder" name: "bootstrap_cinder"
restart_policy: "never" restart_policy: "never"
volumes: volumes: "{{ cinder_api.volumes }}"
- "{{ node_config_directory }}/cinder-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
run_once: True run_once: True
delegate_to: "{{ groups['cinder-api'][0] }}" delegate_to: "{{ groups[cinder_api.group][0] }}"

View File

@ -1,43 +1,52 @@
--- ---
- name: Ensuring config directories exist - name: Ensuring config directories exist
file: file:
path: "{{ node_config_directory }}/{{ item }}" path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory" state: "directory"
recurse: yes recurse: yes
with_items: when:
- "cinder-api" - inventory_hostname in groups[item.value.group]
- "cinder-backup" - item.value.enabled | bool
- "cinder-scheduler" with_dict: "{{ cinder_services }}"
- "cinder-volume"
- name: Copying over config.json files for services - name: Copying over config.json files for services
template: template:
src: "{{ item }}.json.j2" src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json" dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
with_items: register: cinder_config_jsons
- "cinder-api" when:
- "cinder-backup" - inventory_hostname in groups[item.value.group]
- "cinder-scheduler" - item.value.enabled | bool
- "cinder-volume" with_dict: "{{ cinder_services }}"
notify:
- Restart cinder-api container
- Restart cinder-scheduler container
- Restart cinder-volume container
- Restart cinder-backup container
- name: Copying over cinder.conf - name: Copying over cinder.conf
merge_configs: merge_configs:
vars: vars:
service_name: "{{ item }}" service_name: "{{ item.key }}"
sources: sources:
- "{{ role_path }}/templates/cinder.conf.j2" - "{{ role_path }}/templates/cinder.conf.j2"
- "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/global.conf"
- "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/database.conf"
- "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/messaging.conf"
- "{{ node_custom_config }}/cinder.conf" - "{{ node_custom_config }}/cinder.conf"
- "{{ node_custom_config }}/cinder/{{ item }}.conf" - "{{ node_custom_config }}/cinder/{{ item.key }}.conf"
- "{{ node_custom_config }}/cinder/{{ inventory_hostname }}/cinder.conf" - "{{ node_custom_config }}/cinder/{{ inventory_hostname }}/cinder.conf"
dest: "{{ node_config_directory }}/{{ item }}/cinder.conf" dest: "{{ node_config_directory }}/{{ item.key }}/cinder.conf"
with_items: register: cinder_confs
- "cinder-api" when:
- "cinder-backup" - item.value.enabled | bool
- "cinder-scheduler" - inventory_hostname in groups[item.value.group]
- "cinder-volume" with_dict: "{{ cinder_services }}"
notify:
- Restart cinder-api container
- Restart cinder-scheduler container
- Restart cinder-volume container
- Restart cinder-backup container
- name: Check if policies shall be overwritten - name: Check if policies shall be overwritten
local_action: stat path="{{ node_custom_config }}/cinder/policy.json" local_action: stat path="{{ node_custom_config }}/cinder/policy.json"
@ -46,18 +55,21 @@
- name: Copying over existing policy.json - name: Copying over existing policy.json
template: template:
src: "{{ node_custom_config }}/cinder/policy.json" src: "{{ node_custom_config }}/cinder/policy.json"
dest: "{{ node_config_directory }}/{{ item }}/policy.json" dest: "{{ node_config_directory }}/{{ item.key }}/policy.json"
with_items: register: cinder_policy_jsons
- "cinder-api"
- "cinder-backup"
- "cinder-scheduler"
- "cinder-volume"
when: when:
cinder_policy.stat.exists - cinder_policy.stat.exists
- inventory_hostname in groups[item.value.group]
with_dict: "{{ cinder_services }}"
notify:
- Restart cinder-api container
- Restart cinder-scheduler container
- Restart cinder-volume container
- Restart cinder-backup container
- name: Copying over nfs_shares files for cinder_volume - name: Copying over nfs_shares files for cinder_volume
template: template:
src: "{{ item }}" src: "{{ item.key }}"
dest: "{{ node_config_directory }}/cinder-volume/nfs_shares" dest: "{{ node_config_directory }}/cinder-volume/nfs_shares"
with_first_found: with_first_found:
- files: - files:
@ -66,3 +78,22 @@
- "{{ node_custom_config }}/cinder/cinder-volume/nfs_shares.j2" - "{{ node_custom_config }}/cinder/cinder-volume/nfs_shares.j2"
- "{{ node_custom_config }}/cinder/{{ inventory_hostname }}/nfs_shares.j2" - "{{ node_custom_config }}/cinder/{{ inventory_hostname }}/nfs_shares.j2"
skip: "{{ not enable_cinder_backend_nfs | bool and not enable_cinder_backend_hnas_nfs | bool }}" skip: "{{ not enable_cinder_backend_nfs | bool and not enable_cinder_backend_hnas_nfs | bool }}"
- name: Check cinder 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_cinder_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ cinder_services }}"
notify:
- Restart cinder-api container
- Restart cinder-scheduler container
- Restart cinder-volume container
- Restart cinder-backup container

View File

@ -26,11 +26,8 @@
- include: bootstrap.yml - include: bootstrap.yml
when: inventory_hostname in groups['cinder-api'] when: inventory_hostname in groups['cinder-api']
- include: start.yml - name: Flush handlers
when: inventory_hostname in groups['cinder-api'] or meta: flush_handlers
inventory_hostname in groups['cinder-volume'] or
inventory_hostname in groups['cinder-scheduler'] or
inventory_hostname in groups['cinder-backup']
- include: check.yml - include: check.yml
when: inventory_hostname in groups['cinder-api'] or when: inventory_hostname in groups['cinder-api'] or

View File

@ -1,28 +1,10 @@
--- ---
- name: Pulling cinder-api image - name: Pulling cinder images
kolla_docker: kolla_docker:
action: "pull_image" action: "pull_image"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
image: "{{ cinder_api_image_full }}" image: "{{ item.value.image }}"
when: inventory_hostname in groups['cinder-api'] when:
- inventory_hostname in groups[item.value.group]
- name: Pulling cinder-backup image - item.value.enabled | bool
kolla_docker: with_dict: "{{ cinder_services }}"
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ cinder_backup_image_full }}"
when: inventory_hostname in groups['cinder-backup']
- name: Pulling cinder-scheduler image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ cinder_scheduler_image_full }}"
when: inventory_hostname in groups['cinder-scheduler']
- name: Pulling cinder-volume image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ cinder_volume_image_full }}"
when: inventory_hostname in groups['cinder-volume']

View File

@ -1,79 +1,2 @@
--- ---
- name: Ensuring the containers up - include: deploy.yml
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: cinder_api, group: cinder-api }
- { name: cinder_scheduler, group: cinder-scheduler }
- { name: cinder_volume, group: cinder-volume }
- { name: cinder_backup, group: cinder-backup }
- 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: cinder_api, group: cinder-api }
- { name: cinder_scheduler, group: cinder-scheduler }
- { name: cinder_volume, group: cinder-volume }
- { name: cinder_backup, group: cinder-backup }
# 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: cinder_api, group: cinder-api }
- { name: cinder_scheduler, group: cinder-scheduler }
- { name: cinder_volume, group: cinder-volume }
- { name: cinder_backup, group: cinder-backup }
- 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: cinder_api, group: cinder-api },
{ name: cinder_scheduler, group: cinder-scheduler },
{ name: cinder_volume, group: cinder-volume },
{ name: cinder_backup, group: cinder-backup }]
- "{{ 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: cinder_api, group: cinder-api },
{ name: cinder_scheduler, group: cinder-scheduler },
{ name: cinder_volume, group: cinder-volume },
{ name: cinder_backup, group: cinder-backup }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"

View File

@ -1,67 +0,0 @@
---
- name: Starting cinder-api container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
name: "cinder_api"
image: "{{ cinder_api_image_full }}"
volumes:
- "{{ node_config_directory }}/cinder-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['cinder-api']
- name: Starting cinder-scheduler container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
name: "cinder_scheduler"
image: "{{ cinder_scheduler_image_full }}"
volumes:
- "{{ node_config_directory }}/cinder-scheduler/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['cinder-scheduler']
- name: Prepare volumes list for cinder-volume
set_fact:
cinder_volume_mounts:
- "{{ node_config_directory }}/cinder-volume/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "/dev/:/dev/"
- "/run/:/run/:shared"
- "{% if enable_iscsid | bool %}cinder:/var/lib/cinder{% endif %}"
- "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}"
- "kolla_logs:/var/log/kolla/"
- name: Starting cinder-volume container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
name: "cinder_volume"
image: "{{ cinder_volume_image_full }}"
privileged: True
ipc_mode: "host"
volumes: '{{ cinder_volume_mounts | reject("equalto", "") | list }}'
when: inventory_hostname in groups['cinder-volume']
- name: Prepare volumes list for cinder-backup
set_fact:
cinder_backup_mounts:
- "{{ node_config_directory }}/cinder-backup/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "/dev/:/dev/"
- "/run/:/run/:shared"
- "{% if enable_cinder_backend_lvm | bool %}cinder:/var/lib/cinder{% endif %}"
- "{% if enable_cinder_backend_lvm | bool %}iscsi_info:/etc/iscsi{% endif %}"
- "kolla_logs:/var/log/kolla/"
- name: Starting cinder-backup container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
name: "cinder_backup"
image: "{{ cinder_backup_image_full }}"
privileged: True
volumes: '{{ cinder_backup_mounts | reject("equalto", "") | list }}'
when: inventory_hostname in groups['cinder-backup']

View File

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