openstack-ansible-os_neutron/handlers/main.yml
Jesse Pretorius afe63f6f19 Resolve migration issues
A run_once task decides on a host without the
context of conditionals related to the task.
The filter is done prior to evaluating any
conditionals.

Also, only the neutron-server neutron.conf has
the database connection credentials as a
security measure, so it is not able to execute
the database migrations.

This patch ensures that the database migrations
are only run once, but are also executed
wherever neutron-server is. It also adds
multiple instances of neutron-server and
neutron-agents to better test against problems
of this nature happening again.

Additionally, the patch uses the handlers for
the offline migrations to ensure that
neutron-server is only restarted once when a
new tag is deployed.

Change-Id: I672ceb0848415c8f2653ebc8f7556db77f7f001c
2017-06-22 19:24:03 +01:00

88 lines
3.2 KiB
YAML

---
# Copyright 2014, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Stop services
service:
name: "{{ item.service_name }}"
enabled: yes
state: "stopped"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ filtered_neutron_services }}"
register: _stop
until: _stop | success
retries: 5
delay: 2
listen: "Restart neutron services"
# NOTE(cloudnull):
# When installing or upgrading it is possible that an old metadata proxy process will not
# be restarted by the metadata agent when a version changes. To fix it the ns-metadata
# proxy pids are killed if they're not running the current tag. Once the old processeses
# are removed the metadata agent will respawn the missing process within 60 seconds using
# the correct code.
- name: Run ns-metadata-proxy process cleanup
shell: |
for ns_pid in $(pgrep neutron-ns-meta); do
echo $(readlink -f "/proc/$ns_pid/exe") | grep -qv "{{ neutron_venv_tag }}"
if [ $? -eq 0 ]; then
if kill -9 "$ns_pid"; then
logger -s "old metadata proxy pid found and has been cleaned up on: \"$ns_pid\""
fi
fi
done
when: "'neutron-metadata-agent' in (filtered_neutron_services | map(attribute='service_key') | list)"
listen: "Restart neutron services"
# Note (odyssey4me):
# The policy.json file is currently read continually by the services
# and is not only read on service start. We therefore cannot template
# directly to the file read by the service because the new policies
# may not be valid until the service restarts. This is particularly
# important during a major upgrade. We therefore only put the policy
# file in place after the service has been stopped.
#
- name: Copy new policy file into place
copy:
src: "{{ neutron_conf_dir }}/policy.json-{{ neutron_venv_tag }}"
dest: "{{ neutron_conf_dir }}/policy.json"
owner: "root"
group: "{{ neutron_system_group_name }}"
mode: "0640"
remote_src: yes
listen: "Restart neutron services"
- name: Perform a DB contract
command: "{{ neutron_bin }}/neutron-db-manage upgrade --contract"
become: yes
become_user: "{{ neutron_system_user_name }}"
delegate_to: "{{ groups[neutron_services['neutron-server']['group']][0] }}"
when:
- "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool"
run_once: yes
listen: "Restart neutron services"
- name: Start services
service:
name: "{{ item.service_name }}"
enabled: yes
state: "started"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ filtered_neutron_services }}"
register: _start
until: _start | success
retries: 5
delay: 2
listen: "Restart neutron services"