From 13f8aef9f84555ba41bcce238067d4aec5a23889 Mon Sep 17 00:00:00 2001 From: ZhijunWei Date: Fri, 18 May 2018 14:09:45 +0000 Subject: [PATCH] Optimize reconfiguration for multipathd Change-Id: I288fa5ea202376d481de6966150e7e050e390f03 Partially-implements: blueprint better-reconfigure Co-Authored-By: caoyuan Closes-Bug: #1796219 --- ansible/roles/multipathd/defaults/main.yml | 21 +++++++++ ansible/roles/multipathd/handlers/main.yml | 24 ++++++++++ ansible/roles/multipathd/tasks/config.yml | 54 ++++++++++++++++------ ansible/roles/multipathd/tasks/deploy.yml | 3 +- ansible/roles/multipathd/tasks/pull.yml | 7 ++- ansible/roles/multipathd/tasks/start.yml | 22 --------- ansible/roles/multipathd/tasks/upgrade.yml | 3 +- 7 files changed, 95 insertions(+), 39 deletions(-) create mode 100644 ansible/roles/multipathd/handlers/main.yml delete mode 100644 ansible/roles/multipathd/tasks/start.yml diff --git a/ansible/roles/multipathd/defaults/main.yml b/ansible/roles/multipathd/defaults/main.yml index 0a2a56dff0..302655aadd 100644 --- a/ansible/roles/multipathd/defaults/main.yml +++ b/ansible/roles/multipathd/defaults/main.yml @@ -1,6 +1,27 @@ --- project_name: "multipathd" +multipathd_services: + multipathd: + container_name: multipathd + group: multipathd + enabled: true + ipc_mode: "host" + privileged: True + image: "{{ multipathd_image_full }}" + volumes: + - "{{ node_config_directory }}/multipathd/:{{ container_config_directory }}/:ro" + - "kolla_logs:/var/log/kolla/" + - "/etc/localtime:/etc/localtime:ro" + - "/dev/:/dev/" + - "/run/:/run/:shared" + - "/sys/fs/cgroup:/sys/fs/cgroup:ro" + - "/lib/modules:/lib/modules:ro" + - "/sys/kernel/config:/configfs" + - "cinder:/var/lib/cinder" + - "iscsi_info:/etc/iscsi" + + #################### # Docker #################### diff --git a/ansible/roles/multipathd/handlers/main.yml b/ansible/roles/multipathd/handlers/main.yml new file mode 100644 index 0000000000..2f71142d54 --- /dev/null +++ b/ansible/roles/multipathd/handlers/main.yml @@ -0,0 +1,24 @@ +--- +- name: Restart multipathd container + vars: + service_name: "multipathd" + service: "{{ multipathd_services[service_name] }}" + config_json: "{{ multipathd_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + multipathd_conf: "{{ multipathd_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + multipathd_container: "{{ check_multipathd_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + become: true + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + ipc_mode: "{{ service.ipc_mode }}" + privileged: "{{ service.privileged }}" + volumes: "{{ service.volumes|reject('equalto', '')|list }}" + when: + - kolla_action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or multipathd_conf.changed | bool + or multipathd_container.changed | bool diff --git a/ansible/roles/multipathd/tasks/config.yml b/ansible/roles/multipathd/tasks/config.yml index 57567133c5..bed2b99cad 100644 --- a/ansible/roles/multipathd/tasks/config.yml +++ b/ansible/roles/multipathd/tasks/config.yml @@ -1,31 +1,59 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" owner: "{{ config_owner_user }}" group: "{{ config_owner_group }}" mode: "0770" become: true - when: inventory_hostname in groups['multipathd'] - with_items: - - "multipathd" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ multipathd_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" mode: "0660" become: true - when: inventory_hostname in groups['multipathd'] - with_items: - - "multipathd" + register: multipathd_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ multipathd_services }}" + notify: + - Restart multipathd container - name: Copying over multipath.conf template: - src: "{{ role_path }}/templates/multipath.conf.j2" - dest: "{{ node_config_directory }}/{{ item }}/multipath.conf" + src: "multipath.conf.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/multipath.conf" mode: "0660" become: true - with_items: - - "multipathd" + register: multipathd_confs + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ multipathd_services }}" + notify: + - Restart multipathd container + +- name: Check multipathd containers + kolla_docker: + action: "compare_container" + common_options: "{{ docker_common_options }}" + name: "{{ item.value.container_name }}" + image: "{{ item.value.image }}" + ipc_mode: "{{ item.value.ipc_mode }}" + privileged: "{{ item.value.privileged | default(False) }}" + volumes: "{{ item.value.volumes }}" + register: check_multipathd_containers + when: + - kolla_action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ multipathd_services }}" + notify: + - Restart multipathd container diff --git a/ansible/roles/multipathd/tasks/deploy.yml b/ansible/roles/multipathd/tasks/deploy.yml index fae82a1da6..375dcad19b 100644 --- a/ansible/roles/multipathd/tasks/deploy.yml +++ b/ansible/roles/multipathd/tasks/deploy.yml @@ -1,4 +1,5 @@ --- - include_tasks: config.yml -- include_tasks: start.yml +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/multipathd/tasks/pull.yml b/ansible/roles/multipathd/tasks/pull.yml index d515cfec17..78b4b72cda 100644 --- a/ansible/roles/multipathd/tasks/pull.yml +++ b/ansible/roles/multipathd/tasks/pull.yml @@ -4,5 +4,8 @@ kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ multipathd_image_full }}" - when: inventory_hostname in groups['multipathd'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ multipathd_services }}" diff --git a/ansible/roles/multipathd/tasks/start.yml b/ansible/roles/multipathd/tasks/start.yml deleted file mode 100644 index fe560dd9de..0000000000 --- a/ansible/roles/multipathd/tasks/start.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: Starting multipathd container - become: true - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ multipathd_image_full }}" - name: "multipathd" - ipc_mode: "host" - privileged: True - volumes: - - "{{ node_config_directory }}/multipathd/:{{ container_config_directory }}/:ro" - - "kolla_logs:/var/log/kolla/" - - "/etc/localtime:/etc/localtime:ro" - - "/dev/:/dev/" - - "/run/:/run/:shared" - - "/sys/fs/cgroup:/sys/fs/cgroup:ro" - - "/lib/modules:/lib/modules:ro" - - "/sys/kernel/config:/configfs" - - "cinder:/var/lib/cinder" - - "iscsi_info:/etc/iscsi" - when: inventory_hostname in groups['multipathd'] diff --git a/ansible/roles/multipathd/tasks/upgrade.yml b/ansible/roles/multipathd/tasks/upgrade.yml index fae82a1da6..375dcad19b 100644 --- a/ansible/roles/multipathd/tasks/upgrade.yml +++ b/ansible/roles/multipathd/tasks/upgrade.yml @@ -1,4 +1,5 @@ --- - include_tasks: config.yml -- include_tasks: start.yml +- name: Flush handlers + meta: flush_handlers