Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user/backup-restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Before starting the backup, the following checks are performed:
### Running Tasks

The backup fails if any Foreman or Pulp tasks are running (unless `--wait-for-tasks` is used).
Foreman tasks are checked only when backing up a Foreman server; content proxy backups check only Pulp tasks.

If `--wait-for-tasks` is specified:

Expand Down
4 changes: 4 additions & 0 deletions src/roles/backup/tasks/preflight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
failed_when: false
changed_when: false
no_log: true
when: enabled_features | has_feature('foreman')

- name: Set Foreman running tasks count
ansible.builtin.set_fact:
backup_foreman_running_tasks: "{{ backup_foreman_tasks_check.resources | default([]) | length }}"
when: enabled_features | has_feature('foreman')

- name: Wait for Foreman tasks to complete (if --wait-for-tasks)
theforeman.foreman.wait_for_task:
Expand All @@ -26,6 +28,7 @@
timeout: "{{ task_wait_timeout | default(3600) }}"
loop: "{{ backup_foreman_tasks_check.resources | map(attribute='id') | list }}"
when:
- enabled_features | has_feature('foreman')
- wait_for_tasks | default(false)
- backup_foreman_running_tasks | int > 0
changed_when: false
Expand All @@ -37,6 +40,7 @@
There are {{ backup_foreman_running_tasks }} running Foreman task(s).
Please wait for these to complete or use --wait-for-tasks flag.
when:
- enabled_features | has_feature('foreman')
- not (wait_for_tasks | default(false))
- backup_foreman_running_tasks | int > 0

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/check_role_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ def test_check_foreman_api_has_feature_guards():

def test_check_foreman_tasks_has_feature_guards():
ensure_role_has_feature_guards('check_foreman_tasks', ['tasks'])


def test_backup_foreman_task_checks_have_feature_guards():
preflight_yaml = os.path.join(ROLES_DIR, 'backup', 'tasks', 'preflight.yaml')
with open(preflight_yaml, 'r') as f:
all_tasks = yaml.safe_load(f)

foreman_tasks = [task for task in all_tasks if 'Foreman' in task.get('name', '')]
assert len(foreman_tasks) == 4
for task in foreman_tasks:
when_condition = task.get('when', [])
when_conditions = when_condition if isinstance(when_condition, list) else [when_condition]
assert "enabled_features | has_feature('foreman')" in when_conditions, \
f"Task '{task.get('name')}' must only run on a Foreman server."
Loading