openstack-ansible-os_glance/tasks/glance_db_setup.yml
Nolan Brubaker 647c4e33f1 Only sync glance database on major versions
Since Glance doesn't yet have rolling upgrades, nor is the tooling
idempotent, we avoid running the database operations during minor
upgrades to maintain uptime.

Major upgrades will still run the sync operations, and the database will
be synced if there is no existing database regardless of the type of
upgrade.

Change-Id: I4a4d8f23f05a16d25878340ede019be7ccdb7196
2017-06-26 11:48:59 -04:00

56 lines
2.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: Check Glance DB version
command: "{{ glance_bin }}/glance-manage db version"
become: yes
become_user: "{{ glance_system_user_name }}"
register: db_version
changed_when: false
# We only set to minor here if the version_compare filter passes, and we make
# sure that can't be accessed unless there's actually a '.' in the version.
# Passing in 'major' or 'testing' to version_compare causes a Jinja error.
- name: Determine whether a major or minor release was installed
set_fact:
upgrade_type: |-
{% set existing = glance_venv_tag %}
{% set upgrade_type = 'major' %}
{% if '.' in existing %}
{% set existing_major = existing.split('.')[0] %}
{% set venv_major = glance_venv_tag.split('.')[0] %}
{% if existing_major != venv_major %}
{% set upgrade_type = 'major' %}
{% elif existing | version_compare(glance_venv_tag, '!=', strict=True) %}
{% set upgrade_type = 'minor' %}
{% endif %}
{% endif %}
{{ upgrade_type }}
delegate_to: localhost
- name: Perform a Glance DB sync
command: "{{ glance_bin }}/glance-manage db sync"
changed_when: false
become: yes
become_user: "{{ glance_system_user_name }}"
when: upgrade_type == 'major' or db_version.stdout.startswith('Database is either not under migration control')
- name: Load glance metadata definitions
command: "{{ glance_bin }}/glance-manage db load_metadefs"
changed_when: false
become: yes
become_user: "{{ glance_system_user_name }}"
when: upgrade_type == 'major' or db_version.stdout.startswith('Database is either not under migration control')