QTS inherits napalm-device-types' POSIX scheduled jobs through LinuxDriver, with Debian's paths. On QTS they are wrong, so QtsScheduledJobsMixin puts all four verbs on QTS's crontab: /etc/config/crontab (admin's, uid 0, no user field), written first, then loaded with crontab /etc/config/crontab and /etc/init.d/crond.sh restart. Without those two steps QTS forgets the change on the next boot.
Changes
get_scheduled_jobs() reads /etc/config/crontab as admin's crontab, plus the other users' crontabs in crond's spool, in one round trip. crond's copy of admin's crontab and cron.update are skipped. It reads no /etc/crontab, cron.d, run-parts, anacron or systemd, because BusyBox crond reads none of them. The time zone comes from getcfg System 'Time Zone' when that is an IANA name, else from readlink /etc/localtime. A box without /etc/config/crontab raises rather than returning an empty list.
The firmware's own lines are platform, matched against a conservative list of the commands stock QTS writes (QTS_PLATFORM_COMMANDS). A line that chains another command stays the admin's. Platform lines only take run: QTS's scripts and UI keep these lines, and only a real box can show whether they leave a switched-off line alone.
manage_scheduled_job() enables and disables the admin's lines and runs any line now. Writes use cp, so the file keeps its inode, mode, owner and links. A run is bounded with sleep/kill rather than timeout, which QTS's BusyBox may not have. Staging uses mktemp with a template.
put_scheduled_job() and delete_scheduled_job() write an application's job as marked lines in /etc/config/crontab (OWN_CRON_D_DIR = None). They only run as admin, and root is accepted as admin. Any other user is refused, because every other crontab lives in RAM and is lost at the next boot.
CRON_SYSTEM_FILES, CRON_D_DIRS and RUN_PARTS_DIRS are empty.
tests/test_scheduled_jobs.py: the commands run under a real sh (dash) and under BusyBox ash with only BusyBox applets on PATH, against a directory standing in for the NAS. crontab, getcfg and crond.sh are replaced by stubs that log their calls. The fixtures are synthetic because no QTS box was reachable (#13).
One test pins exactly the scheduled-job verbs QTS offers, so a new verb added in napalm-linux or napalm-device-types fails it. Another pins the actions each kind of job gets.
ruff, mypy, napalm-standard check and ratchet, and bandit pass. 116 tests pass, coverage is 90% (the new module 100%).
CI will fail until napalm-device-types 4.26.0 and napalm-linux 0.16.0 are installable.
Still needs a live check on a QTS 4 and a QTS 5 box: the platform command list, uid 0's name (admin), what getcfg System 'Time Zone' prints, BusyBox mktemp/cp/crontab, the bounded run, and whether QTS rewrites a switched-off firmware line.
## Summary
QTS inherits napalm-device-types' POSIX scheduled jobs through `LinuxDriver`, with Debian's paths. On QTS they are wrong, so `QtsScheduledJobsMixin` puts all four verbs on QTS's crontab: `/etc/config/crontab` (admin's, uid 0, no user field), written first, then loaded with `crontab /etc/config/crontab` and `/etc/init.d/crond.sh restart`. Without those two steps QTS forgets the change on the next boot.
## Changes
- `get_scheduled_jobs()` reads `/etc/config/crontab` as admin's crontab, plus the other users' crontabs in crond's spool, in one round trip. crond's copy of admin's crontab and `cron.update` are skipped. It reads no `/etc/crontab`, cron.d, run-parts, anacron or systemd, because BusyBox crond reads none of them. The time zone comes from `getcfg System 'Time Zone'` when that is an IANA name, else from `readlink /etc/localtime`. A box without `/etc/config/crontab` raises rather than returning an empty list.
- The firmware's own lines are `platform`, matched against a conservative list of the commands stock QTS writes (`QTS_PLATFORM_COMMANDS`). A line that chains another command stays the admin's. Platform lines only take `run`: QTS's scripts and UI keep these lines, and only a real box can show whether they leave a switched-off line alone.
- `manage_scheduled_job()` enables and disables the admin's lines and runs any line now. Writes use `cp`, so the file keeps its inode, mode, owner and links. A run is bounded with `sleep`/`kill` rather than `timeout`, which QTS's BusyBox may not have. Staging uses `mktemp` with a template.
- `put_scheduled_job()` and `delete_scheduled_job()` write an application's job as marked lines in `/etc/config/crontab` (`OWN_CRON_D_DIR = None`). They only run as admin, and `root` is accepted as admin. Any other user is refused, because every other crontab lives in RAM and is lost at the next boot.
- `CRON_SYSTEM_FILES`, `CRON_D_DIRS` and `RUN_PARTS_DIRS` are empty.
- Floors: `napalm-device-types>=4.26.0`, `napalm-linux>=0.16.0`.
## Related Issue
Closes #17
Part of NetOrk/netork#1933 (napalm-device-types PR NAPALM/napalm-device-types#87, napalm-linux NAPALM/napalm-linux#67).
## Testing
- `tests/test_scheduled_jobs.py`: the commands run under a real `sh` (dash) and under BusyBox `ash` with only BusyBox applets on `PATH`, against a directory standing in for the NAS. `crontab`, `getcfg` and `crond.sh` are replaced by stubs that log their calls. The fixtures are synthetic because no QTS box was reachable (#13).
- One test pins exactly the scheduled-job verbs QTS offers, so a new verb added in napalm-linux or napalm-device-types fails it. Another pins the actions each kind of job gets.
- ruff, mypy, napalm-standard check and ratchet, and bandit pass. 116 tests pass, coverage is 90% (the new module 100%).
- CI will fail until napalm-device-types 4.26.0 and napalm-linux 0.16.0 are installable.
- Still needs a live check on a QTS 4 and a QTS 5 box: the platform command list, uid 0's name (`admin`), what `getcfg System 'Time Zone'` prints, BusyBox `mktemp`/`cp`/`crontab`, the bounded run, and whether QTS rewrites a switched-off firmware line.
napalm-linux now brings napalm-device-types' POSIX scheduled jobs, with
Debian's paths. On QTS they are wrong: the crontab that survives a boot
is /etc/config/crontab (admin's, no user field), crond runs a copy of
it, and a change made only through crontab is gone after the next boot.
BusyBox crond reads no /etc/crontab, cron.d, run-parts or anacron, and
there is no systemd.
QtsScheduledJobsMixin reads /etc/config/crontab as admin's and the other
users' crontabs from crond's spool in one round trip, and writes the
file first, then loads it and restarts crond. The firmware's own lines
are platform by a conservative command list and only run, until a real
box shows whether QTS leaves one switched off alone. An application's
job is marked lines in admin's crontab; a run is bounded without
timeout, which QTS's BusyBox cannot be relied on to have.
Requires napalm-device-types 4.26.0 and napalm-linux 0.16.0.
Closes#17
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
QTS inherits napalm-device-types' POSIX scheduled jobs through
LinuxDriver, with Debian's paths. On QTS they are wrong, soQtsScheduledJobsMixinputs all four verbs on QTS's crontab:/etc/config/crontab(admin's, uid 0, no user field), written first, then loaded withcrontab /etc/config/crontaband/etc/init.d/crond.sh restart. Without those two steps QTS forgets the change on the next boot.Changes
get_scheduled_jobs()reads/etc/config/crontabas admin's crontab, plus the other users' crontabs in crond's spool, in one round trip. crond's copy of admin's crontab andcron.updateare skipped. It reads no/etc/crontab, cron.d, run-parts, anacron or systemd, because BusyBox crond reads none of them. The time zone comes fromgetcfg System 'Time Zone'when that is an IANA name, else fromreadlink /etc/localtime. A box without/etc/config/crontabraises rather than returning an empty list.platform, matched against a conservative list of the commands stock QTS writes (QTS_PLATFORM_COMMANDS). A line that chains another command stays the admin's. Platform lines only takerun: QTS's scripts and UI keep these lines, and only a real box can show whether they leave a switched-off line alone.manage_scheduled_job()enables and disables the admin's lines and runs any line now. Writes usecp, so the file keeps its inode, mode, owner and links. A run is bounded withsleep/killrather thantimeout, which QTS's BusyBox may not have. Staging usesmktempwith a template.put_scheduled_job()anddelete_scheduled_job()write an application's job as marked lines in/etc/config/crontab(OWN_CRON_D_DIR = None). They only run as admin, androotis accepted as admin. Any other user is refused, because every other crontab lives in RAM and is lost at the next boot.CRON_SYSTEM_FILES,CRON_D_DIRSandRUN_PARTS_DIRSare empty.napalm-device-types>=4.26.0,napalm-linux>=0.16.0.Related Issue
Closes #17
Part of NetOrk/netork#1933 (napalm-device-types PR NAPALM/napalm-device-types#87, napalm-linux NAPALM/napalm-linux#67).
Testing
tests/test_scheduled_jobs.py: the commands run under a realsh(dash) and under BusyBoxashwith only BusyBox applets onPATH, against a directory standing in for the NAS.crontab,getcfgandcrond.share replaced by stubs that log their calls. The fixtures are synthetic because no QTS box was reachable (#13).admin), whatgetcfg System 'Time Zone'prints, BusyBoxmktemp/cp/crontab, the bounded run, and whether QTS rewrites a switched-off firmware line.