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.
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.
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
FreeBSD and OpenBSD get scheduled jobs through napalm-device-types'
PosixScheduledJobsMixin, with the BSD paths and tools. On FreeBSD, everyperiodicscript is a job of its own, switched by itsperiodic.confknob.get_cron_jobs()is removed.Changes
napalm_bsd/scheduled_jobs.py:BsdScheduledJobsMixin, mixed intoBsdDriver. It sets/etc/crontaband/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 setsROOT_GROUP="wheel",STAT_ARGV=("stat","-f","%Lp %Su %Sg","--")andINSTALL=("install",). The report runs in one round trip, with a hook for moreshafter the cron report, and lines the base system ships read asplatform(PLATFORM_SOURCESandPLATFORM_COMMANDS)._sj_as: BSDsuhas no shell option (FreeBSD's-sis a MAC label), and-mstarts root's own login shell, which is csh on many FreeBSD hosts. So the script goes to/bin/shon stdin, andsu -m <user> -c /bin/shhands the shell a single word that every shell runs the same way.HOME,USERandLOGNAMEare 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 withkind="periodic"andschedule_kind="period".<period>_<name>_enable(security_status_<name>_enablefor the security scripts). Failing that, it is the one<period>_..._enableknob the script names. A${knob:-YES}default is respected./etc/defaults/periodic.confplussource_periodic_confs, in a subshell.sysrc -f /etc/periodic.conf <knob>=YES|NO, then check the value periodic now sees. If a laterperiodic.confstill overrides the knob, the result fails and says so.timeout 300 env PERIODIC=<period>; the security scripts getsecurity daily, as the daily run spawns them./etc/cron.dand/usr/local/etc/cron.d, and writes an application's own job to/etc/cron.d. Ownership comes frompkg which -q, guarded bypkg -Nso the bootstrap stub never prompts. The time zone comes from/var/db/zoneinfo, falling back toreadlink /etc/localtime./etc/crontaband/etc/periodic/*read asplatform./etc/daily,weeklyandmonthlystay one job each, as root's crontab lines, and read asplatformtogether withnewsyslog. Cron's-n/-q/-sflags are dropped when a line runs now. The time zone comes fromreadlink /etc/localtime.timeout(1)exists on OpenBSD 7.0 and later, so one bound covers both systems.get_cron_jobs()andparse.crontab()with their tests. The floor is nownapalm-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 realshover a directory tree that stands in for the host.crontab,install,stat,su,pkgandsysrcare replaced by logging scripts, and the recorded FreeBSD/etc/crontaband OpenBSD root crontab are used as fixtures.ruff format,ruff check,mypy,napalm-standard checkandratchet, andbanditare all clean.