B&R: Fail faster if restore in progress flag present

The check that causes the "restore_platform.yml" playbook to fail
if a restore is already in progress was happening very late.

Move the check into it's own role that is now called first.
Additionally, added the argument: "force_restore" to have the
playbook ignore the restore in progress flag.

TEST PLAN
PASS: Run "restore_platform.yml"" for about 30 seconds, then abort it.
  Run again, playbook must fail.
PASS: Run "restore_platform.yml" for about 30 seconds, then abort it.
  Run again with "force_restore=true", playbook should continue.

Story: 2010117
Task: 46375
Signed-off-by: Joshua Kraitberg <joshua.kraitberg@windriver.com>
Change-Id: Iea50c359caaadfb4d986598c1b9b8a2a5eee72ea
This commit is contained in:
Joshua Kraitberg
2022-09-21 16:02:47 -04:00
parent b80bcfc894
commit acb7a67830
4 changed files with 26 additions and 11 deletions

View File

@@ -105,6 +105,10 @@ host_backup_dir: "{{ lookup('env', 'HOME') }}"
#
restore_in_progress_flag: /etc/platform/.restore_in_progress
# By default, restore cannot run if a restore is already in progress.
# By setting this to true, the restore_in_progress_flag will be ignored.
force_restore: false
# This variable is set to true when restore_openstack playbook is
# played again to bring up remaining OpenStack services after Ceph
# data is restored.

View File

@@ -1,6 +1,6 @@
---
#
# Copyright (c) 2019 Wind River Systems, Inc.
# Copyright (c) 2019-2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -13,6 +13,7 @@
roles:
- common/prepare-env
- restore-platform/precheck
- common/validate-target
- restore-platform/prepare-env
- restore-platform/restore-sw-patches

View File

@@ -0,0 +1,20 @@
---
#
# Copyright (c) 2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# ROLE DESCRIPTION:
# This role will prevent you from re-running restores
# unless you provde the force_restore flag.
#
- name: Check if restore is in progress
stat:
path: "{{ restore_in_progress_flag }}"
register: restore_in_progress
- name: Fail if restore is already in progress
fail:
msg: "Restore is already in progress!"
when: restore_in_progress.stat.exists
ignore_errors: "{{ force_restore|bool }}"

View File

@@ -92,16 +92,6 @@
msg: "Host {{ ansible_host }} has been unlocked. Cannot perform restore."
when: initial_config_done.stat.exists
- name: Check if restore is in progress
stat:
path: "{{ restore_in_progress_flag }}"
register: restore_in_progress
- name: Fail if restore is already in progress
fail:
msg: " Restore is already in progress!"
when: restore_in_progress.stat.exists
- name: Set restore file parameter
set_fact:
restore_data_file: "{{ target_backup_dir }}/{{ backup_filename }}"