From 8a5fb5df53a25d4c45e070f15ab036bc5617cb76 Mon Sep 17 00:00:00 2001 From: Nolan Brubaker Date: Mon, 19 Jun 2017 13:39:32 -0400 Subject: [PATCH] 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. In order for a load balancer to know that a service should be drained, we must set a flag within the role communicating the update. Combined backport of: https://review.openstack.org/475470 https://review.openstack.org/478214 Change-Id: I4a4d8f23f05a16d25878340ede019be7ccdb7196 (cherry picked from commit 647c4e33f1fcba771f23f7aabf0dc061b22f79ab) --- tasks/glance_db_setup.yml | 37 +++++++++++++++++++++++++++++++++---- tasks/glance_install.yml | 10 ++++++++++ tasks/main.yml | 18 ++++++++++++++++-- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/tasks/glance_db_setup.yml b/tasks/glance_db_setup.yml index d9a66e91..ec355425 100644 --- a/tasks/glance_db_setup.yml +++ b/tasks/glance_db_setup.yml @@ -13,14 +13,43 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Perform a Glance DB sync - command: "{{ glance_bin }}/glance-manage db_sync" +- 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 -- name: Load glance metadata definitions - command: "{{ glance_bin }}/glance-manage db_load_metadefs {{ glance_etc_dir }}/metadefs" +# 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') diff --git a/tasks/glance_install.yml b/tasks/glance_install.yml index d285bfa2..1f9cb5ad 100644 --- a/tasks/glance_install.yml +++ b/tasks/glance_install.yml @@ -113,6 +113,16 @@ virtualenv-tools --update-path=auto --reinitialize {{ glance_bin | dirname }} when: glance_get_venv | changed +- name: Record the need for a service restart + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: glance + option: need_service_restart + value: True + when: glance_get_venv | changed or + glance_venv_dir | changed or + install_packages | changed + - name: Record the venv tag deployed ini_file: dest: "/etc/ansible/facts.d/openstack_ansible.fact" diff --git a/tasks/main.yml b/tasks/main.yml index 35222728..5b593081 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -33,6 +33,13 @@ tags: - glance-install +- name: refresh local facts + setup: + filter: ansible_local + gather_subset: "!all" + tags: + - glance-config + - include: glance_post_install.yml tags: - glance-config @@ -42,12 +49,19 @@ - glance-config - include: glance_db_setup.yml - when: inventory_hostname == groups['glance_all'][0] + run_once: true tags: - glance-config - include: glance_service_setup.yml - when: inventory_hostname == groups['glance_all'][0] + run_once: true + tags: + - glance-config + +- name: refresh local facts + setup: + filter: ansible_local + gather_subset: "!all" tags: - glance-config