From d2e00019b49e6a07adb89b84536921a06c19ff0e Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Thu, 9 Feb 2017 22:25:49 -0800 Subject: [PATCH] Conditionally run appropriate db_sync commands Take advantage of the return code given by keystone_manage db_sync's 'check' option to conditionally run the appropriate database migration commands. 0 - currently up to date 1 - error requiring operator intervention 2 - expand required 3 - migrate required 4 - contract required Related-Bug: 1642212 Change-Id: I129590ff6ac4e45bfd9b3ea21ad6615f66d37d31 --- tasks/keystone_db_setup.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tasks/keystone_db_setup.yml b/tasks/keystone_db_setup.yml index 8d6d07dd..9217194d 100644 --- a/tasks/keystone_db_setup.yml +++ b/tasks/keystone_db_setup.yml @@ -27,16 +27,28 @@ - "{{ keystone_wsgi_program_names }}" - "{{ keystone_system_service_name }}" +- name: Check current state of Keystone DB + command: "{{ keystone_bin }}/keystone-manage db_sync --check" + register: keystone_db_sync_check + failed_when: keystone_db_sync_check.rc == 1 + changed_when: "{{ keystone_db_sync_check.rc not in [2, 3, 4] }}" + - name: Perform a Keystone DB sync expand command: "{{ keystone_bin }}/keystone-manage db_sync --expand" - changed_when: true become: yes become_user: "{{ keystone_system_user_name }}" + when: keystone_db_sync_check.rc == 2 - name: Perform a Keystone DB sync migrate command: "{{ keystone_bin }}/keystone-manage db_sync --migrate" - changed_when: true become: yes become_user: "{{ keystone_system_user_name }}" + when: "{{ keystone_db_sync_check.rc in [2, 3] }}" + notify: + - Perform a Keystone DB sync contract + +- name: Check if Keystone DB sync contract is required + command: "true" + changed_when: keystone_db_sync_check.rc == 4 notify: - Perform a Keystone DB sync contract