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
This commit is contained in:
Jesse Pretorius 2016-09-28 16:32:09 +01:00
parent 2653926436
commit 4888d5a5d1
9 changed files with 50 additions and 55 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
# {{ ansible_managed }}
description "{{ item.key }}"
description "{{ item.value.service_name }}"
author "Kevin Carter <kevin.carter@rackspace.com>"
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