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

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
This commit is contained in:
Christian Manivong committed 2026-11-03 07:33:55 +01:00
1 parent cc00c225a2
commit f1524b8349
3 files changed
+32 -3

No files matched your search

+3 -1
View File
@@ -15,7 +15,9 @@ All notable changes to this driver. The format follows
through `Exec.getOutput` (stopped after 300 s), and an application's job is made with
`Cron.set` and removed with `Cron.delete` -- an OMV job like any other, its comment
`napalm-scheduled-job: <name> <description>`. Each write applies the `cron` module alone,
so changes pending in the web UI for other modules stay pending. The cron files OMV
so changes pending in the web UI for other modules stay pending; while the `cron` module
itself has changes pending, every write is refused, or the apply would put them live too.
The cron files OMV
generates (`/etc/cron.d/openmediavault-*`, `/etc/cron.hourly/openmediavault-flushmailq`,
`/etc/cron.{daily,weekly}/openmediavault-apticron`,
`/etc/cron.daily/openmediavault-samba-recycle`) are `platform` and only run: the Linux path
+18 -2
View File
@@ -23,7 +23,9 @@ They are switched with ``Cron.set`` (the job as it is, but ``enable``), run with
``Cron.set`` and removed with ``Cron.delete`` -- so an application's job on OMV
is an OMV job, in the web UI like any other. Each write applies the ``cron``
module and nothing else (``Config.applyChanges``): changes left pending in the
web UI for other modules stay pending.
web UI for other modules stay pending. While the ``cron`` module itself has changes
pending, every write is refused: an apply would put someone's half-finished edit
live along with it (decided 2026-11-03, NetOrk/netork#1933).
The scripts OMV's package ships to the run-parts directories
(``/etc/cron.daily/openmediavault-check_locked_users`` and the like) are not
@@ -74,7 +76,9 @@ NEW_UUID = "fa4b1c66-ef79-11e5-87a0-0002b3a176b4"
#: napalm-device-types' job marker, as the comment of an OMV job (``# `` is cron's).
COMMENT_MARKER = "napalm-scheduled-job: "
_KEY = "omv:"
_APPLY = {"modules": ["cron"], "force": False}
#: The module the scheduled jobs are, in OMV's configuration.
_MODULE = "cron"
_APPLY = {"modules": [_MODULE], "force": False}
#: Salt restarts cron when it deploys: give it time.
_APPLY_TIMEOUT = 600
_SHORTCUTS = {
@@ -236,6 +240,8 @@ class OmvScheduledJobsMixin(PosixScheduledJobsMixin):
timeout: float = 60,
) -> Any: ...
def _omv_dirty_modules(self) -> list[str]: ...
# -- reading ---------------------------------------------------------------------------------
def _sj_read(self) -> Reading:
@@ -278,8 +284,17 @@ class OmvScheduledJobsMixin(PosixScheduledJobsMixin):
# -- writing ---------------------------------------------------------------------------------
def _omv_clean(self) -> None:
""":raises ScheduledJobRefused: while the ``cron`` module has changes pending."""
if _MODULE in self._omv_dirty_modules():
raise ScheduledJobRefused(
"OpenMediaVault has unapplied changes to its scheduled jobs; apply or "
"revert them in its web UI first"
)
def _omv_set(self, raw: dict[str, Any]) -> dict[str, Any]:
"""``Cron.set`` *raw*, then deploy the ``cron`` module alone."""
self._omv_clean()
stored: dict[str, Any] = self._omv_rpc("Cron", "set", _set_params(raw))
self._omv_rpc("Config", "applyChanges", dict(_APPLY), _APPLY_TIMEOUT)
return stored
@@ -404,6 +419,7 @@ class OmvScheduledJobsMixin(PosixScheduledJobsMixin):
raise ScheduledJobRefused(
f"{key} was not written by an application; it is only switched"
)
self._omv_clean()
self._omv_rpc("Cron", "delete", {"uuid": raw["uuid"]})
self._omv_rpc("Config", "applyChanges", dict(_APPLY), _APPLY_TIMEOUT)
return {"success": True, "output": f"{key} deleted"}
+11
View File
@@ -131,6 +131,8 @@ class Nas:
return CommandResult("", "", 0)
def sudo_status(self, command: str, read_timeout: float = 100):
if command.startswith("cat ") and "dirtymodules" in command:
return json.dumps(self.dirty), 0
argv = shlex.split(command)
assert argv[:3] == ["omv-rpc", "-u", "admin"], command
method = f"{argv[3]}.{argv[4]}"
@@ -694,3 +696,12 @@ def test_delete_of_any_other_job_is_the_linux_one(driver, nas):
with pytest.raises(ScheduledJobRefused):
driver.delete_scheduled_job(certbot["key"], digest=certbot["digest"])
assert _wrote(nas) == []
def test_a_cron_module_with_changes_pending_refuses_every_write(driver, nas):
"""An apply would put someone's half-finished web-UI edit live along with ours."""
nas.dirty = ["apt", "cron"]
job = _by_key(driver)[f"omv:{SYNC}"]
with pytest.raises(ScheduledJobRefused, match="unapplied changes"):
driver.manage_scheduled_job(job["key"], "disable", digest=job["digest"])
assert nas.called("Cron.set") == [] and nas.called("Config.applyChanges") == []