feat(scheduled-jobs): OMV's own jobs through Cron RPC, generated files platform (#18) #19

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

Summary

Scheduled jobs on OpenMediaVault. The driver inherits napalm-linux's reading and writers (PosixScheduledJobsMixin), and adds OMV's own jobs through its RPC. The Linux path never writes a cron file OMV generates.

Changes

  • Generated files are platform (PLATFORM_SOURCES): /etc/cron.d/openmediavault-* (userdefined, powermngmt, rsync, mkrrdgraph, and the files plugins write there), /etc/cron.hourly/openmediavault-flushmailq, /etc/cron.{daily,weekly}/openmediavault-apticron and /etc/cron.daily/openmediavault-samba-recycle. I took this list from OMV's salt states on master. These jobs can only be run. _sj_write, _sj_switch and _sj_delete_cron refuse such a path as a second guard. The run-parts scripts the openmediavault package ships (for example openmediavault-check_locked_users) are not generated, so they stay package jobs and are switched as on Linux.
  • OMV's jobs come from RPC. Cron.getList is called once for all four types (userdefined, reboot, shutdown, standby), and a list shorter than its total raises. The returned jobs replace the lines of openmediavault-userdefined and openmediavault-powermngmt, and the reading also shows the disabled jobs, which the generated files leave out. Each job maps as follows:
    • key="omv:<uuid>", kind="cron"
    • source="omv:cron", or "omv:powermgmt" for a power job
    • schedule is the cron line as OMV writes it: */n for the every-N flags, @hourly, @weekly, @reboot and so on for the shortcuts
    • managed_by is application when the comment starts with napalm-scheduled-job: <name>, admin otherwise
    • the digest also covers sendemail, comment and type
  • Switching: Cron.set with the job unchanged except enable. The digest is checked first.
  • Running: Cron.execute, then Exec.getOutput until the job stops running. A failing job comes back as success: false with OMV's message. After 300 s the job is stopped with Exec.stop. A power job has no run, because Cron.execute only runs a user-defined job's script.
  • put_scheduled_job creates or changes an OMV job with Cron.set, so it shows in the web UI. The cron expression is written in OMV's fields: lists of values, */n where OMV has a flag for it, Sunday as 7. A weekday step next to a day of month is refused, because it would change cron's either-day rule. The user must exist on the NAS. A multi-line command is allowed, because OMV wraps the command in a script. A change keeps the job's existing sendemail setting.
  • delete_scheduled_job uses Cron.delete and only works on application jobs. A non-omv: key goes to napalm-linux.
  • Each write runs Config.applyChanges with {"modules": ["cron"]} (only conf.system.cron.job, conf.system.time and conf.system.powermngmnt mark the cron module dirty). Changes pending in the web UI for other modules stay pending.
  • Raised the floors to napalm-device-types>=4.26.0 and napalm-linux>=0.16.0. Updated the CHANGELOG and the README method table.

Related Issue

Closes #18
Part of NetOrk/netork#1933

Testing

  • tests/test_scheduled_jobs.py has 51 tests. They run against a synthetic NAS: the napalm-linux report, plus omv-rpc answers in OMV's shapes (Cron.getList returns comma-separated strings, Cron.set takes lists). A capability test lists the verbs OMV offers. Other tests check that no command ever writes a generated file, that a generated job still runs, and that every other job keeps napalm-linux's behaviour.
  • Full suite: 121 passed, _scheduled_jobs.py at 100 % coverage. ruff format, ruff check, mypy (strict), napalm-standard check, napalm-standard ratchet and bandit are green. Tested against napalm-device-types feature/scheduled-jobs (4.26.0) and napalm-linux feature/scheduled-jobs.
  • Not tested on a real NAS.
## Summary Scheduled jobs on OpenMediaVault. The driver inherits napalm-linux's reading and writers (`PosixScheduledJobsMixin`), and adds OMV's own jobs through its RPC. The Linux path never writes a cron file OMV generates. ## Changes - **Generated files are `platform`** (`PLATFORM_SOURCES`): `/etc/cron.d/openmediavault-*` (userdefined, powermngmt, rsync, mkrrdgraph, and the files plugins write there), `/etc/cron.hourly/openmediavault-flushmailq`, `/etc/cron.{daily,weekly}/openmediavault-apticron` and `/etc/cron.daily/openmediavault-samba-recycle`. I took this list from OMV's salt states on master. These jobs can only be run. `_sj_write`, `_sj_switch` and `_sj_delete_cron` refuse such a path as a second guard. The run-parts scripts the `openmediavault` package ships (for example `openmediavault-check_locked_users`) are not generated, so they stay `package` jobs and are switched as on Linux. - **OMV's jobs come from RPC.** `Cron.getList` is called once for all four types (`userdefined`, `reboot`, `shutdown`, `standby`), and a list shorter than its `total` raises. The returned jobs replace the lines of `openmediavault-userdefined` and `openmediavault-powermngmt`, and the reading also shows the disabled jobs, which the generated files leave out. Each job maps as follows: - `key="omv:<uuid>"`, `kind="cron"` - `source="omv:cron"`, or `"omv:powermgmt"` for a power job - `schedule` is the cron line as OMV writes it: `*/n` for the every-N flags, `@hourly`, `@weekly`, `@reboot` and so on for the shortcuts - `managed_by` is `application` when the comment starts with `napalm-scheduled-job: <name>`, `admin` otherwise - the digest also covers `sendemail`, `comment` and `type` - **Switching:** `Cron.set` with the job unchanged except `enable`. The digest is checked first. - **Running:** `Cron.execute`, then `Exec.getOutput` until the job stops running. A failing job comes back as `success: false` with OMV's message. After 300 s the job is stopped with `Exec.stop`. A power job has no `run`, because `Cron.execute` only runs a user-defined job's script. - **`put_scheduled_job`** creates or changes an OMV job with `Cron.set`, so it shows in the web UI. The cron expression is written in OMV's fields: lists of values, `*/n` where OMV has a flag for it, Sunday as `7`. A weekday step next to a day of month is refused, because it would change cron's either-day rule. The user must exist on the NAS. A multi-line command is allowed, because OMV wraps the command in a script. A change keeps the job's existing `sendemail` setting. - **`delete_scheduled_job`** uses `Cron.delete` and only works on application jobs. A non-`omv:` key goes to napalm-linux. - Each write runs `Config.applyChanges` with `{"modules": ["cron"]}` (only `conf.system.cron.job`, `conf.system.time` and `conf.system.powermngmnt` mark the `cron` module dirty). Changes pending in the web UI for other modules stay pending. - Raised the floors to `napalm-device-types>=4.26.0` and `napalm-linux>=0.16.0`. Updated the CHANGELOG and the README method table. ## Related Issue Closes #18 Part of NetOrk/netork#1933 ## Testing - `tests/test_scheduled_jobs.py` has 51 tests. They run against a synthetic NAS: the napalm-linux report, plus `omv-rpc` answers in OMV's shapes (`Cron.getList` returns comma-separated strings, `Cron.set` takes lists). A capability test lists the verbs OMV offers. Other tests check that no command ever writes a generated file, that a generated job still runs, and that every other job keeps napalm-linux's behaviour. - Full suite: 121 passed, `_scheduled_jobs.py` at 100 % coverage. `ruff format`, `ruff check`, `mypy` (strict), `napalm-standard check`, `napalm-standard ratchet` and `bandit` are green. Tested against napalm-device-types `feature/scheduled-jobs` (4.26.0) and napalm-linux `feature/scheduled-jobs`. - Not tested on a real NAS.
christianmanivong added 1 commit 2026-11-03 04:46:42 +00:00
feat(scheduled-jobs): OMV's own jobs through Cron RPC, generated files platform (#18)
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 14s
driver / test (3.12) (pull_request) Failing after 46s
driver / test (3.13) (pull_request) Failing after 43s
driver / types (pull_request) Failing after 1m1s
driver / lowest (pull_request) Failing after 20s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Failing after 1m4s
CI / driver (pull_request) Failing after 2m16s
driver / publish (pull_request) Skipped
cc00c225a2
OpenMediaVault writes several cron files itself, from its own database,
and writes them again on every apply: an edit napalm-linux made there
would be taken back without a word. So every file OMV generates
(/etc/cron.d/openmediavault-*, the mail-queue flush, apticron and the
recycle-bin cleanup) is platform and only runs; the inherited writers
refuse it.

The web UI's "Scheduled Jobs" and the power-management schedule live in
conf.system.cron.job. They are read through Cron.getList, disabled ones
included, instead of the lines OMV generates for them, and switched with
Cron.set, run with Cron.execute (followed through Exec.getOutput), made
with Cron.set and removed with Cron.delete. An application's job on OMV is
an OMV job, visible in its web UI, marked by its comment. Each write
applies the cron module alone, so changes pending in the web UI for other
modules stay pending. Every other job keeps napalm-linux's behaviour.

Requires napalm-device-types 4.26.0 and napalm-linux 0.16.0.

Closes #18
christianmanivong added 1 commit 2026-11-03 06:33:55 +00:00
feat(scheduled-jobs): refuse every write while OMV's cron module has changes pending
driver / lint (pull_request) Successful in 18s
driver / standard (pull_request) Successful in 22s
driver / types (pull_request) Failing after 1m19s
driver / test (3.13) (pull_request) Failing after 58s
driver / test (3.12) (pull_request) Failing after 1m4s
driver / lowest (pull_request) Failing after 23s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Failing after 1m12s
CI / driver (pull_request) Failing after 2m32s
driver / publish (pull_request) Skipped
f1524b8349
An apply of the cron module would put someone's half-finished web-UI edit
live along with ours. Decided 2026-11-03 (NetOrk/netork#1933).

Refs #18
christianmanivong added 2 commits 2026-11-03 07:35:47 +00:00
# Conflicts:
#	pyproject.toml
chore(scheduled-jobs): require napalm-device-types 4.27.0
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m2s
driver / test (3.13) (pull_request) Successful in 54s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / lowest (pull_request) Successful in 26s
driver / build (pull_request) Successful in 36s
driver / security (pull_request) Successful in 1m27s
CI / driver (pull_request) Successful in 2m36s
driver / publish (pull_request) Skipped
c2e0ad3758
4.26.0 went out with the sshd drop-in change; the scheduled-jobs
contract is in 4.27.0.
christianmanivong merged commit 509cf01a70 into main 2026-11-03 08:20:28 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Blocks
You do not have permission to read 1 dependency
Reference: NAPALM/napalm-openmediavault#19