feat(scheduled-jobs): FreeBSD and OpenBSD through PosixScheduledJobsMixin (#27) #28

Merged
christianmanivong merged 2 commits from feature/scheduled-jobs into main 2026-11-03 08:20:25 +00:00
Owner

Summary

FreeBSD and OpenBSD get scheduled jobs through napalm-device-types' PosixScheduledJobsMixin, with the BSD paths and tools. On FreeBSD, every periodic script is a job of its own, switched by its periodic.conf knob. get_cron_jobs() is removed.

Changes

  • napalm_bsd/scheduled_jobs.py: BsdScheduledJobsMixin, mixed into BsdDriver. It sets /etc/crontab and /var/cron/tabs; there is no run-parts, no anacron and no systemd (the systemd marker is cleared, so no timer is ever read or written). It sets ROOT_GROUP="wheel", STAT_ARGV=("stat","-f","%Lp %Su %Sg","--") and INSTALL=("install",). The report runs in one round trip, with a hook for more sh after the cron report, and lines the base system ships read as platform (PLATFORM_SOURCES and PLATFORM_COMMANDS).
  • _sj_as: BSD su has no shell option (FreeBSD's -s is a MAC label), and -m starts root's own login shell, which is csh on many FreeBSD hosts. So the script goes to /bin/sh on stdin, and su -m <user> -c /bin/sh hands the shell a single word that every shell runs the same way. HOME, USER and LOGNAME are set to the user's, as cron sets them.
  • napalm_bsd/periodic.py (FreeBSD): each executable script in /etc/periodic/{daily,weekly,monthly,security} and /usr/local/etc/periodic/... is a job with kind="periodic" and schedule_kind="period".
    • Its knob is <period>_<name>_enable (security_status_<name>_enable for the security scripts). Failing that, it is the one <period>_..._enable knob the script names. A ${knob:-YES} default is respected.
    • The values are read the way periodic reads them: /etc/defaults/periodic.conf plus source_periodic_confs, in a subshell.
    • Enable and disable run sysrc -f /etc/periodic.conf <knob>=YES|NO, then check the value periodic now sees. If a later periodic.conf still overrides the knob, the result fails and says so.
    • Run executes the script under timeout 300 env PERIODIC=<period>; the security scripts get security daily, as the daily run spawns them.
  • FreeBSD: reads /etc/cron.d and /usr/local/etc/cron.d, and writes an application's own job to /etc/cron.d. Ownership comes from pkg which -q, guarded by pkg -N so the bootstrap stub never prompts. The time zone comes from /var/db/zoneinfo, falling back to readlink /etc/localtime. /etc/crontab and /etc/periodic/* read as platform.
  • OpenBSD: no cron.d, so an application's own job becomes marked lines in the user's crontab. /etc/daily, weekly and monthly stay one job each, as root's crontab lines, and read as platform together with newsyslog. Cron's -n/-q/-s flags are dropped when a line runs now. The time zone comes from readlink /etc/localtime. timeout(1) exists on OpenBSD 7.0 and later, so one bound covers both systems.
  • Removed get_cron_jobs() and parse.crontab() with their tests. The floor is now napalm-device-types>=4.26.0. CHANGELOG and README are updated.

Related Issue

Closes #27
Part of NetOrk/netork#1933 (napalm-device-types#87)

Testing

  • tests/test_scheduled_jobs.py: the report, switching, running and writing are run by a real sh over a directory tree that stands in for the host. crontab, install, stat, su, pkg and sysrc are replaced by logging scripts, and the recorded FreeBSD /etc/crontab and OpenBSD root crontab are used as fixtures.
  • 188 tests pass, with coverage at 96 % (floor 94). ruff format, ruff check, mypy, napalm-standard check and ratchet, and bandit are all clean.
  • Not yet run on a real FreeBSD or OpenBSD host.
## Summary FreeBSD and OpenBSD get scheduled jobs through napalm-device-types' `PosixScheduledJobsMixin`, with the BSD paths and tools. On FreeBSD, every `periodic` script is a job of its own, switched by its `periodic.conf` knob. `get_cron_jobs()` is removed. ## Changes - `napalm_bsd/scheduled_jobs.py`: `BsdScheduledJobsMixin`, mixed into `BsdDriver`. It sets `/etc/crontab` and `/var/cron/tabs`; there is no run-parts, no anacron and no systemd (the systemd marker is cleared, so no timer is ever read or written). It sets `ROOT_GROUP="wheel"`, `STAT_ARGV=("stat","-f","%Lp %Su %Sg","--")` and `INSTALL=("install",)`. The report runs in one round trip, with a hook for more `sh` after the cron report, and lines the base system ships read as `platform` (`PLATFORM_SOURCES` and `PLATFORM_COMMANDS`). - `_sj_as`: BSD `su` has no shell option (FreeBSD's `-s` is a MAC label), and `-m` starts root's own login shell, which is csh on many FreeBSD hosts. So the script goes to `/bin/sh` on stdin, and `su -m <user> -c /bin/sh` hands the shell a single word that every shell runs the same way. `HOME`, `USER` and `LOGNAME` are set to the user's, as cron sets them. - `napalm_bsd/periodic.py` (FreeBSD): each executable script in `/etc/periodic/{daily,weekly,monthly,security}` and `/usr/local/etc/periodic/...` is a job with `kind="periodic"` and `schedule_kind="period"`. - Its knob is `<period>_<name>_enable` (`security_status_<name>_enable` for the security scripts). Failing that, it is the one `<period>_..._enable` knob the script names. A `${knob:-YES}` default is respected. - The values are read the way periodic reads them: `/etc/defaults/periodic.conf` plus `source_periodic_confs`, in a subshell. - Enable and disable run `sysrc -f /etc/periodic.conf <knob>=YES|NO`, then check the value periodic now sees. If a later `periodic.conf` still overrides the knob, the result fails and says so. - Run executes the script under `timeout 300 env PERIODIC=<period>`; the security scripts get `security daily`, as the daily run spawns them. - FreeBSD: reads `/etc/cron.d` and `/usr/local/etc/cron.d`, and writes an application's own job to `/etc/cron.d`. Ownership comes from `pkg which -q`, guarded by `pkg -N` so the bootstrap stub never prompts. The time zone comes from `/var/db/zoneinfo`, falling back to `readlink /etc/localtime`. `/etc/crontab` and `/etc/periodic/*` read as `platform`. - OpenBSD: no cron.d, so an application's own job becomes marked lines in the user's crontab. `/etc/daily`, `weekly` and `monthly` stay one job each, as root's crontab lines, and read as `platform` together with `newsyslog`. Cron's `-n`/`-q`/`-s` flags are dropped when a line runs now. The time zone comes from `readlink /etc/localtime`. `timeout(1)` exists on OpenBSD 7.0 and later, so one bound covers both systems. - Removed `get_cron_jobs()` and `parse.crontab()` with their tests. The floor is now `napalm-device-types>=4.26.0`. CHANGELOG and README are updated. ## Related Issue Closes #27 Part of NetOrk/netork#1933 (napalm-device-types#87) ## Testing - `tests/test_scheduled_jobs.py`: the report, switching, running and writing are run by a real `sh` over a directory tree that stands in for the host. `crontab`, `install`, `stat`, `su`, `pkg` and `sysrc` are replaced by logging scripts, and the recorded FreeBSD `/etc/crontab` and OpenBSD root crontab are used as fixtures. - 188 tests pass, with coverage at 96 % (floor 94). `ruff format`, `ruff check`, `mypy`, `napalm-standard check` and `ratchet`, and `bandit` are all clean. - Not yet run on a real FreeBSD or OpenBSD host.
christianmanivong added 1 commit 2026-11-03 04:53:23 +00:00
feat(scheduled-jobs): FreeBSD and OpenBSD through PosixScheduledJobsMixin (#27)
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 13s
driver / test (3.12) (pull_request) Failing after 15s
driver / test (3.13) (pull_request) Failing after 13s
driver / types (pull_request) Failing after 25s
driver / lowest (pull_request) Failing after 19s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Failing after 36s
CI / driver (pull_request) Failing after 1m10s
driver / publish (pull_request) Skipped
991e07043f
get_scheduled_jobs reads /etc/crontab and the user crontabs in
/var/cron/tabs, on FreeBSD also both cron.d directories and every
periodic script, in one round trip as root; manage_scheduled_job
enables, disables or runs one now; put_ and delete_scheduled_job write
and remove an application's own job (/etc/cron.d on FreeBSD, marked
lines in the user's crontab on OpenBSD).

A periodic script is what FreeBSD runs daily, weekly, monthly and for
the security run; it does its work only when its periodic.conf knob
says YES, so that knob is its enabled state, written with sysrc to
/etc/periodic.conf. A later periodic.conf that still overrides it is
reported instead of claimed as done. A script whose knob is not known
only runs; one whose knob is off does nothing when run and offers no run.

BSD su takes no shell (FreeBSD's -s is a MAC label) and -m starts
root's own shell, csh on many FreeBSD hosts, so another user's job goes
to /bin/sh on stdin. OpenBSD cron's -n/-q/-s flags are left off when a
line runs now. What the base system ships is platform: FreeBSD's
/etc/crontab and /etc/periodic, OpenBSD's newsyslog and
/etc/daily|weekly|monthly lines, which stay one job each.

get_cron_jobs goes: it read without root and missed cron.d, every other
user and periodic.

Requires napalm-device-types 4.26.0.

Closes #27
christianmanivong added 1 commit 2026-11-03 07:35:44 +00:00
chore(scheduled-jobs): require napalm-device-types 4.27.0
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 55s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 57s
driver / lowest (pull_request) Successful in 32s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m29s
driver / publish (pull_request) Skipped
aad4b3cfc1
4.26.0 went out with the sshd drop-in change; the scheduled-jobs
contract is in 4.27.0.
christianmanivong merged commit 198f50f6be into main 2026-11-03 08:20:25 +00:00
Sign in to join this conversation.