fix(scheduled-jobs): an own job goes to /etc/cron.d only where the host has it
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m21s
driver / lowest (pull_request) Successful in 39s
driver / test (3.13) (pull_request) Successful in 1m21s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 3m3s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m21s
driver / lowest (pull_request) Successful in 39s
driver / test (3.13) (pull_request) Successful in 1m21s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 3m3s
driver / publish (pull_request) Skipped
BusyBox crond reads no /etc/cron.d, so an Alpine host without systemd takes the job in the user's crontab instead of a file it would never run. Refs #86
This commit is contained in:
1 parent
f573fa53d2
commit
834cb2e0ea
2 files changed
+17
-2
No files matched your search
@@ -108,7 +108,8 @@ class PosixScheduledJobsMixin(ScheduledJobsMixin):
|
||||
ANACRONTAB: ClassVar[str] = "/etc/anacrontab"
|
||||
JOB_SCRIPT_DIR: ClassVar[str] = "/usr/local/libexec/scheduled-jobs"
|
||||
UNIT_DIR: ClassVar[str] = "/etc/systemd/system"
|
||||
#: Where a host without systemd takes an application's job as a file; None: its crontab.
|
||||
#: Where a host without systemd takes an application's job as a file, if the directory
|
||||
#: is there; else, or None, the user's crontab.
|
||||
OWN_CRON_D_DIR: ClassVar[str | None] = "/etc/cron.d"
|
||||
ROOT_GROUP: ClassVar[str] = "root"
|
||||
#: Prints "<octal mode> <owner> <group>" of the path appended.
|
||||
@@ -393,8 +394,16 @@ class PosixScheduledJobsMixin(ScheduledJobsMixin):
|
||||
spec["name"], spec.get("description") or "", line, enabled=spec["enabled"]
|
||||
)
|
||||
|
||||
def _sj_cron_d(self) -> str | None:
|
||||
""":attr:`OWN_CRON_D_DIR` where the host has it; BusyBox crond reads none."""
|
||||
directory = self.OWN_CRON_D_DIR
|
||||
if directory is None:
|
||||
return None
|
||||
found = self.run_command(_command(["test", "-d", directory]), timeout=30)
|
||||
return directory if found.exit_code == 0 else None
|
||||
|
||||
def _sj_put_cron(self, spec: ScheduledJobSpecDict, current: dict[str, object] | None) -> None:
|
||||
if self.OWN_CRON_D_DIR is not None:
|
||||
if self._sj_cron_d() is not None:
|
||||
self._sj_group(spec["run_as"])
|
||||
text = "\n".join(self._sj_cron_text(spec, system=True)) + "\n"
|
||||
self._sj_install(
|
||||
|
||||
@@ -484,6 +484,12 @@ class TestApplicationJobs:
|
||||
host.delete_scheduled_job("job:netork-tidy", digest=job["digest"])
|
||||
assert (root / "spool/nobody").read_text() == ""
|
||||
|
||||
def test_a_cron_d_that_is_not_there_is_the_crontab(self, root: Path):
|
||||
host = Host(root, systemd=False)
|
||||
host.OWN_CRON_D_DIR = str(root / "etc/no-cron.d") # type: ignore[misc]
|
||||
host.put_scheduled_job(SPEC)
|
||||
assert "netork-tidy" in (root / "spool/root").read_text()
|
||||
|
||||
def test_a_cron_line_holds_one_line(self, root: Path):
|
||||
with pytest.raises(ScheduledJobRefused, match="one line"):
|
||||
Host(root, systemd=False).put_scheduled_job({**SPEC, "command": "a\nb"})
|
||||
|
||||
Reference in new issue
Block a user