From 4888d5a5d1d9c184cdb8996a2154a8a62a2a27f0 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Wed, 28 Sep 2016 16:32:09 +0100 Subject: [PATCH] Updating service group mapping implementation This patch updates the work done in https://review.openstack.org/377055 to match up to the implementation in https://review.openstack.org/378613 which aims to bring the implementation in line with the os_neutron role. - The variable ;cinder_service_names; is renamed to 'cinder_services'. - Common variables shared by each service's template files have been updated to use the service namespaced variables. - Unused handlers have been removed. - Unused variables have been removed. - The handler to reload the services now only tries to restart the service if the host is in the group for the service according to the service group mapping. This allows us to ensure that handler failures are no longer ignored and that no execution time is wasted trying to restart services which do not exist on the host. - Currently the reload of upstart/systemd scripts may not happen if only one script changes as the task uses a loop with only one result register. This patch implements handlers to reload upstart/systemd scripts to ensure that this happens when any one of the scripts change. Change-Id: Icca1f3ef930962c1179687b1a7ef4dcce5ca47f2 --- defaults/main.yml | 14 ++++++-------- handlers/main.yml | 21 +++++++++++++++++---- tasks/cinder_init_common.yml | 4 ++-- tasks/cinder_init_systemd.yml | 21 ++++++++------------- tasks/cinder_init_upstart.yml | 15 +++------------ tasks/cinder_install.yml | 4 +--- templates/cinder-systemd-init.j2 | 4 ++-- templates/cinder-systemd-tempfiles.j2 | 4 ++-- templates/cinder-upstart-init.j2 | 18 +++++++++--------- 9 files changed, 50 insertions(+), 55 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 4252d883..399bc840 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -102,7 +102,6 @@ cinder_service_adminuri: "{{ cinder_service_adminuri_proto }}://{{ internal_lb_v cinder_service_adminurl: "{{ cinder_service_adminuri }}/v1/%(tenant_id)s" cinder_service_internaluri: "{{ cinder_service_internaluri_proto }}://{{ internal_lb_vip_address }}:{{ cinder_service_port }}" cinder_service_internalurl: "{{ cinder_service_internaluri }}/v1/%(tenant_id)s" -cinder_service_program_name: cinder-api cinder_service_v2_name: cinderv2 cinder_service_v2_port: 8776 @@ -121,7 +120,6 @@ cinder_keystone_auth_plugin: password ## In order to enable the cinder backup you MUST set ``cinder_service_backup_program_enabled`` to "true" cinder_service_backup_program_enabled: false -cinder_service_backup_program_name: cinder-backup # cinder_service_backup_driver: Options include 'cinder.backup.drivers.swift' or # 'cinder.backup.drivers.ceph' cinder_service_backup_driver: cinder.backup.drivers.swift @@ -148,10 +146,6 @@ cinder_service_backup_metadata_version: 2 cinder_swift_catalog_info: "object-store:swift:internalURL" -cinder_service_volume_program_name: cinder-volume - -cinder_service_scheduler_program_name: cinder-scheduler - # If ``cinder_osapi_volume_workers`` is unset the system will use half the number of # available VCPUS to compute the number of api workers to use. # cinder_osapi_volume_workers: 16 @@ -246,16 +240,20 @@ cinder_pip_packages: - python-cinderclient - python-keystoneclient -# Service Names -cinder_service_names: +## Service Name-Group Mapping +cinder_services: cinder-api: group: cinder_api + service_name: cinder-api cinder-scheduler: group: cinder_scheduler + service_name: cinder-scheduler cinder-volume: group: cinder_volume + service_name: cinder-volume cinder-backup: group: cinder_backup + service_name: cinder-backup condition: "{{ cinder_service_backup_program_enabled | bool }}" # This variable is used by the repo_build process to determine diff --git a/handlers/main.yml b/handlers/main.yml index 8d6d1123..987fc0b5 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -13,13 +13,26 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Reload systemd daemon + command: "systemctl daemon-reload" + notify: + - Restart cinder services + +- name: Reload upstart init scripts + shell: | + initctl reload-configuration + notify: + - Restart cinder services + - name: Restart cinder services service: - name: "{{ item.key }}" + name: "{{ item.value.service_name }}" state: restarted - pattern: "{{ item.key }}" - with_dict: "{{ cinder_service_names }}" - failed_when: false + pattern: "{{ item.value.service_name }}" + with_dict: "{{ cinder_services }}" + when: + - inventory_hostname in groups[item.value.group] + - "{{ item.value.condition | default(true) }}" - name: Ensure tgt service restarted service: diff --git a/tasks/cinder_init_common.yml b/tasks/cinder_init_common.yml index b4c58e7b..2d3077bb 100644 --- a/tasks/cinder_init_common.yml +++ b/tasks/cinder_init_common.yml @@ -24,9 +24,9 @@ - name: Load service service: - name: "{{ item.key }}" + name: "{{ item.value.service_name }}" enabled: "yes" - with_dict: "{{ cinder_service_names }}" + with_dict: "{{ cinder_services }}" when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" diff --git a/tasks/cinder_init_systemd.yml b/tasks/cinder_init_systemd.yml index 7bf148b8..9441c500 100644 --- a/tasks/cinder_init_systemd.yml +++ b/tasks/cinder_init_systemd.yml @@ -16,24 +16,24 @@ - name: Create TEMP run dir file: - path: "/var/run/{{ item.key }}" + path: "/var/run/{{ item.value.service_name }}" state: directory owner: "{{ cinder_system_user_name }}" group: "{{ cinder_system_group_name }}" mode: "02755" - with_dict: "{{ cinder_service_names }}" + with_dict: "{{ cinder_services }}" when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" - name: Create TEMP lock dir file: - path: "/var/lock/{{ item.key }}" + path: "/var/lock/{{ item.value.service_name }}" state: directory owner: "{{ cinder_system_user_name }}" group: "{{ cinder_system_group_name }}" mode: "02755" - with_dict: "{{ cinder_service_names }}" + with_dict: "{{ cinder_services }}" when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" @@ -45,7 +45,7 @@ mode: "0644" owner: "root" group: "root" - with_dict: "{{ cinder_service_names }}" + with_dict: "{{ cinder_services }}" when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" @@ -53,18 +53,13 @@ - name: Place the systemd init script template: src: "cinder-systemd-init.j2" - dest: "/etc/systemd/system/{{ item.key }}.service" + dest: "/etc/systemd/system/{{ item.value.service_name }}.service" mode: "0644" owner: "root" group: "root" - register: systemd_init - with_dict: "{{ cinder_service_names }}" + with_dict: "{{ cinder_services }}" when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" - -- name: Reload the systemd daemon - command: "systemctl daemon-reload" - when: systemd_init | changed notify: - - Restart cinder services + - Reload systemd daemon diff --git a/tasks/cinder_init_upstart.yml b/tasks/cinder_init_upstart.yml index 477c80dc..7105a638 100644 --- a/tasks/cinder_init_upstart.yml +++ b/tasks/cinder_init_upstart.yml @@ -16,22 +16,13 @@ - name: Place the init script template: src: "cinder-upstart-init.j2" - dest: "/etc/init/{{ item.key }}.conf" + dest: "/etc/init/{{ item.value.service_name }}.conf" mode: "0644" owner: "root" group: "root" - register: upstart_init - with_dict: "{{ cinder_service_names }}" + with_dict: "{{ cinder_services }}" when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" notify: - - Restart cinder services - -- name: Reload init scripts - shell: | - initctl reload-configuration - when: upstart_init | changed - register: upstart_init - notify: - - Restart cinder services + - Reload upstart init scripts diff --git a/tasks/cinder_install.yml b/tasks/cinder_install.yml index 970fe3f5..54d2aab9 100644 --- a/tasks/cinder_install.yml +++ b/tasks/cinder_install.yml @@ -14,12 +14,10 @@ # limitations under the License. - include: cinder_install_apt.yml - static: no when: ansible_pkg_mgr == 'apt' - include: cinder_install_yum.yml - when: - - ansible_pkg_mgr == 'yum' + when: ansible_pkg_mgr == 'yum' - name: Create developer mode constraint file copy: diff --git a/templates/cinder-systemd-init.j2 b/templates/cinder-systemd-init.j2 index effb6183..c353c120 100644 --- a/templates/cinder-systemd-init.j2 +++ b/templates/cinder-systemd-init.j2 @@ -11,9 +11,9 @@ User={{ cinder_system_user_name }} Group={{ cinder_system_group_name }} {% if program_override is defined %} -ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ item.key }}.log +ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ item.value.service_name }}.log {% else %} -ExecStart={{ cinder_bin }}/{{ item.key }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ item.key }}.log +ExecStart={{ cinder_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ item.value.service_name }}.log {% endif %} # Give a reasonable amount of time for the server to start up/shut down diff --git a/templates/cinder-systemd-tempfiles.j2 b/templates/cinder-systemd-tempfiles.j2 index 459df529..b8ba6c28 100644 --- a/templates/cinder-systemd-tempfiles.j2 +++ b/templates/cinder-systemd-tempfiles.j2 @@ -1,4 +1,4 @@ # {{ ansible_managed }} -D /var/lock/{{ item.key }} 2755 {{ cinder_system_user_name }} {{ cinder_system_group_name }} -D /var/run/{{ item.key }} 2755 {{ cinder_system_user_name }} {{ cinder_system_group_name }} +D /var/lock/{{ item.value.service_name }} 2755 {{ cinder_system_user_name }} {{ cinder_system_group_name }} +D /var/run/{{ item.value.service_name }} 2755 {{ cinder_system_user_name }} {{ cinder_system_group_name }} diff --git a/templates/cinder-upstart-init.j2 b/templates/cinder-upstart-init.j2 index 4c863691..ed44b312 100644 --- a/templates/cinder-upstart-init.j2 +++ b/templates/cinder-upstart-init.j2 @@ -1,6 +1,6 @@ # {{ ansible_managed }} -description "{{ item.key }}" +description "{{ item.value.service_name }}" author "Kevin Carter " start on runlevel [2345] @@ -10,18 +10,18 @@ respawn respawn limit 10 5 # Set the RUNBIN environment variable -env RUNBIN="{{ cinder_bin }}/{{ item.key }}" +env RUNBIN="{{ cinder_bin }}/{{ item.value.service_name }}" # Change directory to service users home chdir "{{ cinder_system_home_folder }}" # Pre start actions pre-start script - mkdir -p "/var/run/{{ item.key }}" - chown {{ cinder_system_user_name }}:{{ cinder_system_group_name }} "/var/run/{{ item.key }}" + mkdir -p "/var/run/{{ item.value.service_name }}" + chown {{ cinder_system_user_name }}:{{ cinder_system_group_name }} "/var/run/{{ item.value.service_name }}" - mkdir -p "/var/lock/{{ item.key }}" - chown {{ cinder_system_user_name }}:{{ cinder_system_group_name }} "/var/lock/{{ item.key }}" + mkdir -p "/var/lock/{{ item.value.service_name }}" + chown {{ cinder_system_user_name }}:{{ cinder_system_group_name }} "/var/lock/{{ item.value.service_name }}" . {{ cinder_bin }}/activate @@ -29,14 +29,14 @@ end script # Post stop actions post-stop script - rm "/var/run/{{ item.key }}/{{ item.key }}.pid" + rm "/var/run/{{ item.value.service_name }}/{{ item.value.service_name }}.pid" end script # Run the start up job exec start-stop-daemon --start \ --chuid {{ cinder_system_user_name }} \ --make-pidfile \ - --pidfile /var/run/{{ item.key }}/{{ item.key }}.pid \ + --pidfile /var/run/{{ item.value.service_name }}/{{ item.value.service_name }}.pid \ --exec "{{ program_override|default('$RUNBIN') }}" \ -- {{ program_config_options|default('') }} \ - --log-file=/var/log/cinder/{{ item.key }}.log + --log-file=/var/log/cinder/{{ item.value.service_name }}.log