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.
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.
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
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
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
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-apticronand/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_switchand_sj_delete_cronrefuse such a path as a second guard. The run-parts scripts theopenmediavaultpackage ships (for exampleopenmediavault-check_locked_users) are not generated, so they staypackagejobs and are switched as on Linux.Cron.getListis called once for all four types (userdefined,reboot,shutdown,standby), and a list shorter than itstotalraises. The returned jobs replace the lines ofopenmediavault-userdefinedandopenmediavault-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 jobscheduleis the cron line as OMV writes it:*/nfor the every-N flags,@hourly,@weekly,@rebootand so on for the shortcutsmanaged_byisapplicationwhen the comment starts withnapalm-scheduled-job: <name>,adminotherwisesendemail,commentandtypeCron.setwith the job unchanged exceptenable. The digest is checked first.Cron.execute, thenExec.getOutputuntil the job stops running. A failing job comes back assuccess: falsewith OMV's message. After 300 s the job is stopped withExec.stop. A power job has norun, becauseCron.executeonly runs a user-defined job's script.put_scheduled_jobcreates or changes an OMV job withCron.set, so it shows in the web UI. The cron expression is written in OMV's fields: lists of values,*/nwhere OMV has a flag for it, Sunday as7. 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 existingsendemailsetting.delete_scheduled_jobusesCron.deleteand only works on application jobs. A non-omv:key goes to napalm-linux.Config.applyChangeswith{"modules": ["cron"]}(onlyconf.system.cron.job,conf.system.timeandconf.system.powermngmntmark thecronmodule dirty). Changes pending in the web UI for other modules stay pending.napalm-device-types>=4.26.0andnapalm-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.pyhas 51 tests. They run against a synthetic NAS: the napalm-linux report, plusomv-rpcanswers in OMV's shapes (Cron.getListreturns comma-separated strings,Cron.settakes 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._scheduled_jobs.pyat 100 % coverage.ruff format,ruff check,mypy(strict),napalm-standard check,napalm-standard ratchetandbanditare green. Tested against napalm-device-typesfeature/scheduled-jobs(4.26.0) and napalm-linuxfeature/scheduled-jobs.