From 1989cfe10393c123743cedeaf6e60544f899f335 Mon Sep 17 00:00:00 2001 From: ZhijunWei Date: Sat, 19 May 2018 23:19:53 +0000 Subject: [PATCH] Optimize reconfigure action for iscsi Complete the reconfigure optimise action for iscsi Co-Authored-By: caoyuan Co-Authored-By: mgoddard Change-Id: I6a1f24bc13bdea148857de9e6f4df79ff97bc9bc Partially-implements: blueprint better-reconfigure Closes-Bug: #1772215 --- ansible/roles/iscsi/defaults/main.yml | 56 ++++++++++++++++++ ansible/roles/iscsi/handlers/main.yml | 34 +++++++++++ ansible/roles/iscsi/tasks/config.yml | 69 +++++++++++------------ ansible/roles/iscsi/tasks/deploy.yml | 3 +- ansible/roles/iscsi/tasks/precheck.yml | 3 +- ansible/roles/iscsi/tasks/pull.yml | 18 ++---- ansible/roles/iscsi/tasks/reconfigure.yml | 1 + ansible/roles/iscsi/tasks/start.yml | 49 ---------------- ansible/roles/iscsi/tasks/stop.yml | 23 ++------ ansible/roles/iscsi/tasks/upgrade.yml | 4 +- 10 files changed, 139 insertions(+), 121 deletions(-) create mode 100644 ansible/roles/iscsi/handlers/main.yml delete mode 100644 ansible/roles/iscsi/tasks/start.yml diff --git a/ansible/roles/iscsi/defaults/main.yml b/ansible/roles/iscsi/defaults/main.yml index b210e82cd6..1ac0be4566 100644 --- a/ansible/roles/iscsi/defaults/main.yml +++ b/ansible/roles/iscsi/defaults/main.yml @@ -1,6 +1,47 @@ --- project_name: "iscsi" +iscsi_services: + iscsid: + container_name: iscsid + group: iscsid + enabled: "{{ enable_iscsid_for_cinder or enable_iscsid_for_ironic }}" + image: "{{ iscsid_image_full }}" + ipc_mode: "host" + privileged: True + volumes: + - "{{ node_config_directory }}/iscsid/:{{ 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" + dimensions: "{{ iscsid_dimensions }}" + tgtd: + container_name: tgtd + group: tgtd + enabled: "{{ enable_tgtd }}" + image: "{{ tgtd_image_full }}" + ipc_mode: "host" + privileged: True + volumes: + - "{{ node_config_directory }}/tgtd/:{{ 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" + dimensions: "{{ tgtd_dimensions }}" + + #################### # Docker #################### @@ -14,3 +55,18 @@ iscsid_image_full: "{{ iscsid_image }}:{{ iscsid_tag }}" tgtd_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ iscsi_install_type }}-tgtd" tgtd_tag: "{{ iscsi_tag }}" tgtd_image_full: "{{ tgtd_image }}:{{ tgtd_tag }}" + +iscsid_dimensions: "{{ default_container_dimensions }}" +tgtd_dimensions: "{{ default_container_dimensions }}" + +enable_iscsid_for_cinder: >- + {{ (inventory_hostname in groups['compute'] + or inventory_hostname in groups['cinder-volume']) + and enable_cinder | bool + and enable_cinder_backend_iscsi | bool }} +enable_iscsid_for_ironic: >- + {{ inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool }} +enable_tgtd: >- + {{ enable_cinder | bool and + enable_cinder_backend_lvm | bool and + cinder_iscsi_helper == "tgtadm" }} diff --git a/ansible/roles/iscsi/handlers/main.yml b/ansible/roles/iscsi/handlers/main.yml new file mode 100644 index 0000000000..17438f8200 --- /dev/null +++ b/ansible/roles/iscsi/handlers/main.yml @@ -0,0 +1,34 @@ +--- +- name: Restart iscsid container + vars: + service_name: "iscsid" + service: "{{ iscsi_services[service_name] }}" + 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 }}" + dimensions: "{{ service.dimensions }}" + when: + - kolla_action != "config" + +- name: Restart tgtd container + vars: + service_name: "tgtd" + service: "{{ iscsi_services[service_name] }}" + 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 }}" + dimensions: "{{ service.dimensions }}" + when: + - kolla_action != "config" diff --git a/ansible/roles/iscsi/tasks/config.yml b/ansible/roles/iscsi/tasks/config.yml index 3669812db5..11f357aa95 100644 --- a/ansible/roles/iscsi/tasks/config.yml +++ b/ansible/roles/iscsi/tasks/config.yml @@ -5,55 +5,50 @@ vars: modules: - name: configfs - when: ( ( inventory_hostname in groups['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool ) - or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool ) + when: + - inventory_hostname in groups[iscsi_services.iscsid.group] + - iscsi_services.iscsid.enabled | bool - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" - state: "directory" - owner: "{{ config_owner_user }}" - group: "{{ config_owner_group }}" - mode: "0770" - become: true - when: ( ( inventory_hostname in groups['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool ) - or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool ) - with_items: - - "iscsid" - -- name: Copying over config.json files for services - template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - mode: "0660" - become: true - when: ( ( inventory_hostname in groups['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool ) - or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool ) - with_items: - - "iscsid" - -- 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: - - enable_cinder_backend_lvm | bool - - inventory_hostname in groups['tgtd'] - with_items: - - "tgtd" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ iscsi_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: - - enable_cinder_backend_lvm | bool - - inventory_hostname in groups['tgtd'] - with_items: - - "tgtd" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ iscsi_services }}" + notify: + - "Restart {{ item.key }} container" + +- name: Check iscsi 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 }}" + dimensions: "{{ item.value.dimensions }}" + when: + - kolla_action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ iscsi_services }}" + notify: + - "Restart {{ item.key }} container" diff --git a/ansible/roles/iscsi/tasks/deploy.yml b/ansible/roles/iscsi/tasks/deploy.yml index fae82a1da6..375dcad19b 100644 --- a/ansible/roles/iscsi/tasks/deploy.yml +++ b/ansible/roles/iscsi/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/iscsi/tasks/precheck.yml b/ansible/roles/iscsi/tasks/precheck.yml index b0c24d2ecb..8e776ba780 100644 --- a/ansible/roles/iscsi/tasks/precheck.yml +++ b/ansible/roles/iscsi/tasks/precheck.yml @@ -14,4 +14,5 @@ state: stopped when: - container_facts['iscsid'] is not defined - - inventory_hostname in groups['iscsid'] + - inventory_hostname in groups[iscsi_services.iscsid.group] + - iscsi_services.iscsid.enabled | bool diff --git a/ansible/roles/iscsi/tasks/pull.yml b/ansible/roles/iscsi/tasks/pull.yml index b91fa58b8a..5e09cd5054 100644 --- a/ansible/roles/iscsi/tasks/pull.yml +++ b/ansible/roles/iscsi/tasks/pull.yml @@ -1,16 +1,10 @@ --- -- name: Pulling iscsid image - become: true +- name: Pulling iscsi images kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ iscsid_image_full }}" - when: inventory_hostname in groups['iscsid'] - -- name: Pulling tgtd image - become: true - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ tgtd_image_full }}" - when: inventory_hostname in groups['tgtd'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ iscsi_services }}" diff --git a/ansible/roles/iscsi/tasks/reconfigure.yml b/ansible/roles/iscsi/tasks/reconfigure.yml index ed97d539c0..f670a5b78d 100644 --- a/ansible/roles/iscsi/tasks/reconfigure.yml +++ b/ansible/roles/iscsi/tasks/reconfigure.yml @@ -1 +1,2 @@ --- +- include_tasks: deploy.yml diff --git a/ansible/roles/iscsi/tasks/start.yml b/ansible/roles/iscsi/tasks/start.yml deleted file mode 100644 index 7d706f0b65..0000000000 --- a/ansible/roles/iscsi/tasks/start.yml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- name: Starting iscsid container - become: true - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ iscsid_image_full }}" - name: "iscsid" - ipc_mode: "host" - privileged: True - volumes: - - "{{ node_config_directory }}/iscsid/:{{ 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['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool ) - or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool ) - -- name: Starting tgtd container - become: true - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ tgtd_image_full }}" - name: "tgtd" - ipc_mode: "host" - privileged: True - volumes: - - "{{ node_config_directory }}/tgtd/:{{ 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['tgtd'] - - enable_cinder | bool - - enable_cinder_backend_lvm | bool - - cinder_iscsi_helper == "tgtadm" diff --git a/ansible/roles/iscsi/tasks/stop.yml b/ansible/roles/iscsi/tasks/stop.yml index dcb016a0a7..13fc08797a 100644 --- a/ansible/roles/iscsi/tasks/stop.yml +++ b/ansible/roles/iscsi/tasks/stop.yml @@ -1,19 +1,6 @@ --- -- name: Stopping iscsid container - kolla_docker: - action: "stop_container" - common_options: "{{ docker_common_options }}" - name: "iscsid" - when: ( ( inventory_hostname in groups['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool ) - or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool and 'iscsid' not in skip_stop_containers) - -- name: Stopping tgtd container - kolla_docker: - action: "stop_container" - common_options: "{{ docker_common_options }}" - name: "tgtd" - when: - - inventory_hostname in groups['tgtd'] - - enable_cinder | bool - - enable_cinder_backend_lvm | bool - - "'tgtd' not in skip_stop_containers" +- import_role: + role: service-stop + vars: + project_services: "{{ iscsi_services }}" + service_name: "{{ project_name }}" diff --git a/ansible/roles/iscsi/tasks/upgrade.yml b/ansible/roles/iscsi/tasks/upgrade.yml index fae82a1da6..f670a5b78d 100644 --- a/ansible/roles/iscsi/tasks/upgrade.yml +++ b/ansible/roles/iscsi/tasks/upgrade.yml @@ -1,4 +1,2 @@ --- -- include_tasks: config.yml - -- include_tasks: start.yml +- include_tasks: deploy.yml