From bca5c325eb86c5cb1008faf2107783ec168a5c66 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Fri, 2 Jun 2017 20:13:51 +0100 Subject: [PATCH] Implement data migrations for rolling upgrades In order to cater for artifact-based installed, and rolling upgrades, this patch implements a set of local facts to inform the db sync and online migrations tasks. The 'cinder_all_software_updated' variables will be set by the playbook on each run to ensure that the online migrations only happen once all venvs are homogenous. This ensures that the playbook can be executed in a serialised fashion and the data will not be corrupted. Change-Id: I9aacda78f92355374af3f4ab24d2d9a9b47491ed --- ...nder-data-migrations-ce31707c078b335c.yaml | 9 ++++ tasks/cinder_db_setup.yml | 41 +++++++++++++++++++ tasks/cinder_install.yml | 30 ++++++++++++++ tasks/main.yml | 15 +++++-- 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/cinder-data-migrations-ce31707c078b335c.yaml diff --git a/releasenotes/notes/cinder-data-migrations-ce31707c078b335c.yaml b/releasenotes/notes/cinder-data-migrations-ce31707c078b335c.yaml new file mode 100644 index 00000000..c3971733 --- /dev/null +++ b/releasenotes/notes/cinder-data-migrations-ce31707c078b335c.yaml @@ -0,0 +1,9 @@ +--- +features: + - The ``os_cinder`` role now provides for doing + online data migrations once the db sync has + been completed. The data migrations will not + be executed until the boolean variable + ``cinder_all_software_updated`` is true. This + variable will need to be set by the playbook + consuming the role. diff --git a/tasks/cinder_db_setup.yml b/tasks/cinder_db_setup.yml index 0ff6c669..fc1ecd30 100644 --- a/tasks/cinder_db_setup.yml +++ b/tasks/cinder_db_setup.yml @@ -17,4 +17,45 @@ command: "{{ cinder_bin }}/cinder-manage db sync" become: yes become_user: "{{ cinder_system_user_name }}" + when: + - "ansible_local['openstack_ansible']['cinder']['need_db_sync'] | bool" changed_when: false + register: dbsync + +- name: Disable the db sync requirement + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: cinder + option: need_db_sync + value: False + when: + - dbsync | succeeded + +- name: Record the need for online data migrations + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: cinder + option: need_online_data_migrations + value: True + when: + - dbsync | succeeded + +- name: Perform online data migrations + command: "{{ cinder_bin }}/cinder-manage db online-data-migrations" + become: yes + become_user: "{{ cinder_system_user_name }}" + when: + - "(cinder_all_software_updated | default('no')) | bool" + - "ansible_local['openstack_ansible']['cinder']['need_online_data_migrations'] | bool" + changed_when: false + register: data_migrations + +- name: Disable the online migrations requirement + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: cinder + option: need_online_data_migrations + value: False + when: + - data_migrations | succeeded + diff --git a/tasks/cinder_install.yml b/tasks/cinder_install.yml index 5d09d591..b0093c66 100644 --- a/tasks/cinder_install.yml +++ b/tasks/cinder_install.yml @@ -112,6 +112,36 @@ virtualenv-tools --update-path=auto --reinitialize {{ cinder_bin | dirname }} when: cinder_get_venv | changed +- name: Record the need for a db sync + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: cinder + option: need_db_sync + value: True + when: cinder_get_venv | changed or + cinder_venv_dir | changed or + install_packages | changed + +- name: Initialise the online data migration local fact + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: cinder + option: need_online_data_migrations + value: False + when: cinder_get_venv | changed or + cinder_venv_dir | changed or + install_packages | changed + +- name: Record the need for a service restart + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: cinder + option: need_service_restart + value: True + when: cinder_get_venv | changed or + cinder_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 7cd87b67..ea3b269b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -33,21 +33,28 @@ tags: - cinder-install +- name: refresh local facts + setup: + filter: ansible_local + gather_subset: "!all" + tags: + - cinder-config + - include: cinder_post_install.yml tags: - cinder-config - include: cinder_db_setup.yml when: - - groups['cinder_all'] | length > 0 - - inventory_hostname == groups['cinder_all'][0] + - groups['cinder_api'] | length > 0 + - inventory_hostname == groups['cinder_api'][0] tags: - cinder-config - include: cinder_service_setup.yml when: - - groups['cinder_all'] | length > 0 - - inventory_hostname == groups['cinder_all'][0] + - groups['cinder_api'] | length > 0 + - inventory_hostname == groups['cinder_api'][0] tags: - cinder-config