Files
FabledSteward/tests/test_ansible_schedule_due.py
bvandeusen 4a0a3ee46e
CI / lint (push) Successful in 3s
CI / unit (push) Successful in 7s
CI / integration (push) Successful in 2m20s
CI / publish (push) Successful in 49s
feat(ansible): scheduled recurring playbook runs
Adds cron-like recurring runs (the engine the maintenance-automation work
needs). New AnsibleSchedule model + migration 0018; a core ScheduledTask
(ansible_scheduled_runs, 60s) fires due schedules, each creating a
system-triggered AnsibleRun (triggered_by=None). Centralises the
resolve-inventory → create-run → launch flow in ansible/runner.trigger_run,
shared by the manual route (refactored to use it) and the scheduler.

Schedules UI under /ansible/schedules: create/edit/pause/delete/run-now,
with interval presets, scope targeting (all / group / target), extra-vars /
limit / tags / dry-run, and last-run status (resolved via last_run_id) +
next-run. Unit test for the due-check.

Task #549 (milestone #37).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 11:04:02 -04:00

29 lines
925 B
Python

"""Unit tests for the schedule due-check (pure, no DB)."""
from datetime import datetime, timedelta, timezone
from types import SimpleNamespace
from steward.ansible.scheduler import is_due
NOW = datetime(2026, 6, 16, 12, 0, 0, tzinfo=timezone.utc)
def _sched(enabled=True, last=None, interval=3600):
return SimpleNamespace(enabled=enabled, last_run_at=last, interval_seconds=interval)
def test_never_run_is_due():
assert is_due(_sched(last=None), NOW) is True
def test_disabled_is_never_due():
assert is_due(_sched(enabled=False, last=None), NOW) is False
def test_due_when_interval_elapsed():
assert is_due(_sched(last=NOW - timedelta(seconds=3600), interval=3600), NOW) is True
assert is_due(_sched(last=NOW - timedelta(seconds=3700), interval=3600), NOW) is True
def test_not_due_before_interval():
assert is_due(_sched(last=NOW - timedelta(seconds=1800), interval=3600), NOW) is False