From c6d119eb835b3f235cc6b715b00dbed840f4ccff Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Tue, 3 Nov 2026 08:11:48 +0100 Subject: [PATCH] fix(scheduled-jobs): a monotonic timer as its unit file says it, OnUnitActiveSec systemctl show names a timer's monotonic settings by their properties, OnUnitActiveUSec=3h; the schedule now reads as the unit file writes it. Found on a live Ubuntu host. Refs #86 --- napalm_device_types/_scheduled_reading.py | 9 +++++++-- tests/test_scheduled_jobs_posix.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/napalm_device_types/_scheduled_reading.py b/napalm_device_types/_scheduled_reading.py index adcbb59..009f622 100644 --- a/napalm_device_types/_scheduled_reading.py +++ b/napalm_device_types/_scheduled_reading.py @@ -203,8 +203,13 @@ def _timestamp(value: str) -> str | None: def _timer_entries(block: dict[str, list[str]], key: str) -> list[str]: - """``{ OnCalendar=daily ; next_elapse=… }`` → ``OnCalendar=daily``, one per entry.""" - return [v.strip(" {}").split(" ; ")[0].strip() for v in block.get(key, []) if v.strip()] + """``{ OnCalendar=daily ; next_elapse=… }`` → ``OnCalendar=daily``, one per entry. + + ``systemctl show`` names a monotonic setting by its property (``OnUnitActiveUSec``); + it is given as the unit file says it (``OnUnitActiveSec``). + """ + entries = (v.strip(" {}").split(" ; ")[0].strip() for v in block.get(key, []) if v.strip()) + return [re.sub(r"^(On\w+)USec=", r"\1Sec=", e) for e in entries] def _argv(exec_start: list[str]) -> str: diff --git a/tests/test_scheduled_jobs_posix.py b/tests/test_scheduled_jobs_posix.py index 258bf47..3029746 100644 --- a/tests/test_scheduled_jobs_posix.py +++ b/tests/test_scheduled_jobs_posix.py @@ -33,7 +33,7 @@ FragmentPath=/usr/lib/systemd/system/apt-daily.timer Id=fstrim.timer Unit=fstrim.service Description=Discard unused blocks once a week -TimersMonotonic={ OnUnitActiveSec=1w ; next_elapse=n/a } +TimersMonotonic={ OnUnitActiveUSec=1w ; next_elapse=n/a } NextElapseUSecRealtime=n/a LastTriggerUSec=n/a UnitFileState=static