Add system cron discovery and management; bump to 0.2.0
CI / test (3.11) (pull_request) Successful in 48s
CI / test (3.13) (pull_request) Successful in 54s

This commit is contained in:
mdaleo404 committed 2026-09-26 08:43:00 +01:00
1 parent 62d505a17e
commit 58d8d0f378
19 files changed
+1129 -55

No files matched your search

+48
View File
@@ -11,6 +11,7 @@ from schedls.runner import CommandRunner
pytestmark = pytest.mark.integration
NAME = "schedls-it-cron"
SYSTEM_NAME = "schedls-it-system"
def _backend_or_skip() -> CronBackend:
@@ -62,3 +63,50 @@ def test_cron_lifecycle_preserves_content() -> None:
assert backend.find(NAME) is None
finally:
_restore(backend, original)
def test_system_cron_discovery_never_executes() -> None:
if not os.path.isdir("/etc/cron.d"):
pytest.skip("/etc/cron.d not present")
backend = CronBackend(CommandRunner())
jobs = backend.discover([Scope.SYSTEM])
for job in jobs:
assert job.backend is Backend.CRON
assert job.scope is Scope.SYSTEM
assert not job.command.argv
assert job.cron is not None
def test_system_cron_lifecycle() -> None:
if os.geteuid() != 0:
pytest.skip("system cron mutation requires root")
if os.environ.get("SCHEDLS_RUN_CRON_TESTS") != "1":
pytest.skip("set SCHEDLS_RUN_CRON_TESTS=1 to allow cron.d mutation")
if not os.path.isdir("/etc/cron.d"):
pytest.skip("/etc/cron.d not present")
backend = CronBackend(CommandRunner())
path = f"/etc/cron.d/schedls-{SYSTEM_NAME}"
spec = JobSpec(
name=SYSTEM_NAME,
backend=Backend.CRON,
scope=Scope.SYSTEM,
command=Command(argv=("/usr/bin/true",)),
cron_expression="15 2 * * *",
run_as="root",
)
try:
plan = backend.plan_create(spec)
assert path in [change.path for change in plan.files]
backend.apply(plan)
job = backend.find(SYSTEM_NAME)
assert job is not None
assert job.managed is True
assert job.cron is not None and job.cron.user == "root"
backend.apply(backend.plan_remove(job))
assert not os.path.exists(path)
assert backend.find(SYSTEM_NAME) is None
finally:
if os.path.exists(path):
os.unlink(path)