From 1572fc73381dd5fabc520b5fa3fbb44b0ecd2e9d Mon Sep 17 00:00:00 2001 From: Jakub Duchek Date: Fri, 25 Sep 2026 01:11:59 +0200 Subject: [PATCH] skipped foreman tasks on proxy backups --- docs/user/backup-restore.md | 1 + src/roles/backup/tasks/preflight.yaml | 4 ++++ tests/unit/check_role_test.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/docs/user/backup-restore.md b/docs/user/backup-restore.md index deee1a095..d863b790e 100644 --- a/docs/user/backup-restore.md +++ b/docs/user/backup-restore.md @@ -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: diff --git a/src/roles/backup/tasks/preflight.yaml b/src/roles/backup/tasks/preflight.yaml index 06d240458..1c6903f66 100644 --- a/src/roles/backup/tasks/preflight.yaml +++ b/src/roles/backup/tasks/preflight.yaml @@ -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: @@ -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 @@ -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 diff --git a/tests/unit/check_role_test.py b/tests/unit/check_role_test.py index c7ba35990..495d4f56e 100644 --- a/tests/unit/check_role_test.py +++ b/tests/unit/check_role_test.py @@ -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."