diff --git a/.github/scripts/track-binaries.py b/.github/scripts/track-binaries.py index 63f8227a..4637376a 100644 --- a/.github/scripts/track-binaries.py +++ b/.github/scripts/track-binaries.py @@ -93,7 +93,7 @@ Stdlib only. GITHUB_TOKEN or GH_TOKEN, if set, is sent to api.github.com only. """ - +from __future__ import annotations import argparse import hashlib diff --git a/docs/skills/systemd-sysupdate-verification.md b/docs/skills/systemd-sysupdate-verification.md index 5ad86f44..0e98cbb7 100644 --- a/docs/skills/systemd-sysupdate-verification.md +++ b/docs/skills/systemd-sysupdate-verification.md @@ -67,6 +67,9 @@ the same names (`files/os/sysupdate.d/.feature` and `3N-.transfer`), enabled per node with `updatectl enable zfs` or a drop-in such as `/etc/sysupdate.d/zfs.feature.d/enable.conf` containing `[Feature] Enabled=true`. +`bluefin-sysupdate-migrate` renames that drop-in directory to +`zfs.feature.d.disabled` when the release stops shipping the feature, and +restores it when a later release ships the feature again. The k0s and NVIDIA Container Toolkit sysexts stay separate components (`files/os/sysupdate.k0s.d/`, `files/os/sysupdate.nvidia-container-toolkit.d/`; `systemd-sysupdate --component= update`) with their own version axes. diff --git a/elements/bluefin-server/os-k0s-first-boot.bst b/elements/bluefin-server/os-k0s-first-boot.bst index ef2c22fd..0e20ac2a 100644 --- a/elements/bluefin-server/os-k0s-first-boot.bst +++ b/elements/bluefin-server/os-k0s-first-boot.bst @@ -13,7 +13,10 @@ description: | Kubernetes; the boot deadline; the diskless update check; bluefin-update-status.service for the login banners and bluefin-update-status-migrate.service, which enables it on nodes that - updated from an image without it). + updated from an image without it), and bluefin-sysupdate-migrate.service + plus the systemd-sysupdate.service drop-in + (05-bluefin-prune-deprecated-features.conf), which archive enabled + sysupdate features the remote release no longer ships. sources: - kind: local diff --git a/elements/bluefin-server/os-stack.bst b/elements/bluefin-server/os-stack.bst index 38384b22..9d3673e2 100644 --- a/elements/bluefin-server/os-stack.bst +++ b/elements/bluefin-server/os-stack.bst @@ -19,6 +19,9 @@ depends: # A/B System Update Configurations - bluefin-server/os-sysupdate.bst + # Prune sysupdate features the release no longer ships, before an update + - bluefin-server/os-sysupdate-feature-migrate.bst + # Runtime helpers (bluefin-host): update status, reboot interlocks, boot # deadline, diskless update check, sysext fetch, first-boot naming - bluefin-server/os-host.bst diff --git a/elements/bluefin-server/os-sysupdate-feature-migrate.bst b/elements/bluefin-server/os-sysupdate-feature-migrate.bst new file mode 100644 index 00000000..95b70305 --- /dev/null +++ b/elements/bluefin-server/os-sysupdate-feature-migrate.bst @@ -0,0 +1,15 @@ +kind: import +description: | + Install the systemd-sysupdate deprecated-feature migration helper so a + feature the release no longer ships cannot silently stop the next update. + + The executable lands in /usr/bin; the boot-time unit (enabled by a wants + symlink in bluefin-server-usr.bst) and the ExecStartPre drop-in on systemd-sysupdate.service are + shipped next to the other system units. + +sources: + - kind: local + path: files/os/sysupdate-migrate + +config: + target: /usr/bin diff --git a/elements/oci/bluefin-server-usr.bst b/elements/oci/bluefin-server-usr.bst index d580c7ef..18603d00 100644 --- a/elements/oci/bluefin-server-usr.bst +++ b/elements/oci/bluefin-server-usr.bst @@ -168,6 +168,10 @@ config: # does, once per installed node (projectbluefin/server#367). ln -sf ../bluefin-update-status-migrate.service \ /sysroot/usr/lib/systemd/system/multi-user.target.wants/bluefin-update-status-migrate.service + # Presets apply on first boot only; enable the sysupdate feature prune in + # /usr so nodes updating into this image run it too (#688). + ln -sf ../bluefin-sysupdate-migrate.service \ + /sysroot/usr/lib/systemd/system/multi-user.target.wants/bluefin-sysupdate-migrate.service # Enabled in /usr, not by preset: a node that updated into this image # must still give its FleetLock slot back once an operator configures a # server, or its group stops rebooting. Inert without a server. diff --git a/files/os/systemd/system/bluefin-sysupdate-migrate.service b/files/os/systemd/system/bluefin-sysupdate-migrate.service new file mode 100644 index 00000000..58ee33e5 --- /dev/null +++ b/files/os/systemd/system/bluefin-sysupdate-migrate.service @@ -0,0 +1,17 @@ +[Unit] +Description=Bluefin: prune deprecated systemd-sysupdate features +Documentation=https://github.com/projectbluefin/server/issues/688 +# Run ahead of the OTA update path so a feature that the release no longer +# ships cannot silently stop the next update. This ordering covers the boot +# path; the ExecStartPre drop-in on systemd-sysupdate.service covers updates +# triggered later by the timer or by hand. +Before=systemd-sysupdate.timer +Before=systemd-sysupdate.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/bluefin-sysupdate-migrate +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/files/os/systemd/system/systemd-sysupdate.service.d/05-bluefin-prune-deprecated-features.conf b/files/os/systemd/system/systemd-sysupdate.service.d/05-bluefin-prune-deprecated-features.conf new file mode 100644 index 00000000..a533c112 --- /dev/null +++ b/files/os/systemd/system/systemd-sysupdate.service.d/05-bluefin-prune-deprecated-features.conf @@ -0,0 +1,6 @@ +[Service] +# Prune retired sysupdate features before every update, so an enabled feature +# that the release no longer ships cannot make systemd-sysupdate report +# "No update needed" instead of updating. The helper is idempotent, so running +# it on every update is safe. The "-" keeps a helper failure from blocking updates. +ExecStartPre=-/usr/bin/bluefin-sysupdate-migrate diff --git a/files/os/sysupdate-migrate/bluefin-sysupdate-migrate b/files/os/sysupdate-migrate/bluefin-sysupdate-migrate new file mode 100755 index 00000000..1ceed215 --- /dev/null +++ b/files/os/sysupdate-migrate/bluefin-sysupdate-migrate @@ -0,0 +1,179 @@ +#!/usr/bin/env bash +# +# bluefin-sysupdate-migrate -- prune systemd-sysupdate features the current +# release no longer ships, so a retired feature cannot silently stop updates. +# +# systemd-sysupdate only applies an update set when every feature enabled under +# /etc/sysupdate.d/.feature.d/ is also provided by the release. When a +# feature leaves the release manifest -- for example Homebrew becoming a +# first-boot seed instead of an opt-in extension -- the matching /etc drop-in +# can no longer be satisfied, and systemd-sysupdate quietly reports "No update +# needed" instead of updating. +# +# The node that stalls still ships the retired feature's transfers locally; only +# the remote release dropped them. So a feature is retired when none of the +# local transfers that list it find a file matching their [Source] MatchPattern +# in the remote SHA256SUMS at the newest version. A feature with no local +# transfer at all is also retired. If a manifest cannot be fetched, the feature +# is left alone: an offline node must never lose a working feature. +# +# This one-shot helper runs ahead of the update path, archives each retired +# /etc drop-in, and prints a clear message so an operator is never left +# wondering why an update was skipped. + +set -euo pipefail + +# Paths are overridable so the logic can be exercised by unit tests against a +# scratch tree without touching the real system directories. +etc_feature_dir="${SYSUPDATE_ETC_DIR:-/etc/sysupdate.d}" +lib_transfer_dir="${SYSUPDATE_LIB_DIR:-/usr/lib/sysupdate.d}" +archive_suffix="${SYSUPDATE_ARCHIVE_SUFFIX:-.disabled}" +fetch_timeout="${SYSUPDATE_FETCH_TIMEOUT:-20}" + +# systemd captures ExecStartPre stdout/stderr into the journal, so plain prints +# are enough; the wrapper keeps one message shape for both paths. +info() { + printf 'bluefin-sysupdate-migrate: %s\n' "$*" +} +warn() { + printf 'bluefin-sysupdate-migrate: warning: %s\n' "$*" >&2 +} + +# Per feature: "yes" once a remote manifest lists a match for one of its +# transfers, "unknown" when a manifest could not be read, else absent. +declare -A feature_state=() +declare -A feature_seen=() +declare -A manifest_cache=() + +trim() { + local v="$1" + v="${v#"${v%%[![:space:]]*}"}" + printf '%s' "${v%"${v##*[![:space:]]}"}" +} + +# Fetch (once per URL) the SHA256SUMS next to a transfer's Source Path. +# Sets the caller's "manifest" variable (no subshell, so the cache persists); +# returns 1 when it cannot be read. +fetch_manifest() { + local url="${1%/}/SHA256SUMS" body + if [ -z "${manifest_cache[$url]+x}" ]; then + if body="$(curl -fsSL --max-time "$fetch_timeout" -- "$url" 2>/dev/null)"; then + # `curl -f` only fails on HTTP >= 400, so a captive portal or proxy + # error page can come back 200 with an HTML body and be trusted as a + # manifest. Only trust a real SHA256SUMS: at least one "<64 hex> + # " line. Anything else is treated as unreachable, so a + # non-release response never archives a working feature. + if printf '%s\n' "$body" | grep -qE '^[0-9a-f]{64}([[:space:]]|\*)'; then + manifest_cache[$url]="$body" + else + manifest_cache[$url]="__FETCH_FAILED__" + fi + else + manifest_cache[$url]="__FETCH_FAILED__" + fi + fi + [ "${manifest_cache[$url]}" != "__FETCH_FAILED__" ] || return 1 + manifest="${manifest_cache[$url]}" +} + +# Turn a MatchPattern into an anchored regex; @v is the version wildcard. +pattern_regex() { + local pat="$1" + pat="$(printf '%s' "$pat" | sed -e 's/[][\.^$*+?(){}|\/]/\\&/g')" + printf '^%s$' "${pat//@v/[^[:space:]]+}" +} + +# Record, for every transfer, whether the remote release still ships the files +# its features need. +collect_feature_state() { + local transfer line section key value feature features path pattern manifest regex name found + shopt -s nullglob + for transfer in "$lib_transfer_dir"/*.transfer; do + features="" path="" pattern="" section="" + while IFS= read -r line; do + line="$(trim "$line")" + case "$line" in + "["*"]") section="$line"; continue ;; + ""|"#"*|";"*) continue ;; + esac + key="$(trim "${line%%=*}")" + value="$(trim "${line#*=}")" + case "$section:$key" in + "[Transfer]:Features") features="$features ${value//,/ }" ;; + "[Source]:Path") path="$value" ;; + "[Source]:MatchPattern") pattern="${value%% *}" ;; + esac + done < "$transfer" + + [ -n "$features" ] || continue + found=unknown + if [ -n "$path" ] && [ -n "$pattern" ] && fetch_manifest "$path"; then + found=no + regex="$(pattern_regex "$pattern")" + while IFS= read -r line; do + name="${line##*[[:space:]]}" + name="${name#\*}" + if [[ "$name" =~ $regex ]]; then found=yes; break; fi + done <<< "$manifest" + fi + set -f + for feature in $features; do + feature_seen["$feature"]=1 + case "$found:${feature_state[$feature]:-}" in + yes:*) feature_state["$feature"]=yes ;; + unknown:yes) ;; + unknown:*) feature_state["$feature"]=unknown ;; + no:yes|no:unknown) ;; + no:*) feature_state["$feature"]=no ;; + esac + done + set +f + done +} + +main() { + if [ ! -d "$etc_feature_dir" ]; then + info "no ${etc_feature_dir} directory; nothing to do" + return 0 + fi + + collect_feature_state + + local dir name changed + changed=0 + shopt -s nullglob + for dir in "$etc_feature_dir"/*.feature.d; do + name="$(basename "$dir")" + name="${name%.feature.d}" + if [ -n "${feature_seen[$name]:-}" ] && [ "${feature_state[$name]:-}" != "no" ]; then + continue + fi + if [ -e "${dir}${archive_suffix}" ]; then + warn "feature ${name} already archived as ${name}${archive_suffix}; leaving it in place" + continue + fi + mv -- "$dir" "${dir}${archive_suffix}" + info "archived ${dir} -> ${dir}${archive_suffix}: enabled feature ${name} is not in the release manifest and would otherwise make systemd-sysupdate report 'No update needed'" + changed=$((changed + 1)) + done + + # A release that ships the feature again restores the operator's opt-in. + for dir in "$etc_feature_dir"/*.feature.d"${archive_suffix}"; do + name="$(basename "$dir")" + name="${name%.feature.d"${archive_suffix}"}" + [ "${feature_state[$name]:-}" = "yes" ] || continue + if [ -e "${dir%"${archive_suffix}"}" ]; then + warn "feature ${name} has both an active and an archived drop-in; leaving the archive in place" + continue + fi + mv -- "$dir" "${dir%"${archive_suffix}"}" + info "restored ${dir%"${archive_suffix}"} from ${dir}: feature ${name} is in the release manifest again" + changed=$((changed + 1)) + done + + if [ "$changed" -eq 0 ]; then + info "no deprecated sysupdate features found; the next update is unaffected" + fi +} + +main "$@" diff --git a/tests/unit/test_sysupdate_feature_migrate.py b/tests/unit/test_sysupdate_feature_migrate.py new file mode 100644 index 00000000..ca79cf16 --- /dev/null +++ b/tests/unit/test_sysupdate_feature_migrate.py @@ -0,0 +1,292 @@ +"""Contracts for the systemd-sysupdate deprecated-feature migration. + +Release transitions such as Homebrew becoming a first-boot seed drop a feature's +transfer definitions from the release manifest, but leave the operator's +``/etc/sysupdate.d/.feature.d/`` drop-in behind. Because +systemd-sysupdate requires every enabled feature to be provided by a remote +transfer set, that stale drop-in makes it report "No update needed" and the +node silently stops updating (issue #688). + +These tests pin the shipped fix: + +* the ``bluefin-sysupdate-migrate`` helper exists, is executable, and lives at + ``/usr/bin/bluefin-sysupdate-migrate`` in the image +* the one-shot unit runs ahead of the update path (before the timer and the + update unit itself) and is enabled by a /usr wants symlink +* the ``systemd-sysupdate.service`` drop-in runs the helper as + ``ExecStartPre`` so every update -- timer- or hand-triggered -- is covered +* the helper archives an enabled feature the release no longer ships, keeps a + feature a transfer still provides, is idempotent, and is a no-op when there + is nothing to do +""" + +import os +import subprocess +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +SCRIPT = ROOT / "files" / "os" / "sysupdate-migrate" / "bluefin-sysupdate-migrate" +SERVICE = ( + ROOT / "files" / "os" / "systemd" / "system" / "bluefin-sysupdate-migrate.service" +) +DROPIN = ( + ROOT + / "files" + / "os" + / "systemd" + / "system" + / "systemd-sysupdate.service.d" + / "05-bluefin-prune-deprecated-features.conf" +) +USR = ROOT / "elements" / "oci" / "bluefin-server-usr.bst" +ELEMENT = ROOT / "elements" / "bluefin-server" / "os-sysupdate-feature-migrate.bst" +STACK = ROOT / "elements" / "bluefin-server" / "os-stack.bst" + + +def run_helper(etc_dir: Path, lib_dir: Path) -> subprocess.CompletedProcess: + return subprocess.run( + [str(SCRIPT)], + env={ + **os.environ, + "SYSUPDATE_ETC_DIR": str(etc_dir), + "SYSUPDATE_LIB_DIR": str(lib_dir), + }, + capture_output=True, + text=True, + check=False, + ) + + +# ── Packaging contracts ----------------------------------------------------- + + +def test_helper_is_packaged_and_executable() -> None: + assert SCRIPT.is_file(), "the migration helper is missing" + assert os.access(SCRIPT, os.X_OK), ( + "the helper must be executable so the systemd unit can run it" + ) + element = ELEMENT.read_text(encoding="utf-8") + assert "path: files/os/sysupdate-migrate" in element, ( + "the helper must ship from files/os/sysupdate-migrate" + ) + assert "target: /usr/bin" in element, ( + "the helper must land at /usr/bin/bluefin-sysupdate-migrate" + ) + assert ( + "bluefin-server/os-sysupdate-feature-migrate.bst" in STACK.read_text("utf-8") + ), "the element must be part of the DDI stack" + + +def test_migration_unit_runs_before_the_update_path() -> None: + service = SERVICE.read_text(encoding="utf-8") + assert "[Unit]" in service and "[Service]" in service and "[Install]" in service + assert "Description=Bluefin: prune deprecated systemd-sysupdate features" in service + assert "Type=oneshot" in service, "the migration is a one-shot helper" + assert "ExecStart=/usr/bin/bluefin-sysupdate-migrate" in service + assert "Before=systemd-sysupdate.timer" in service, ( + "the migration must run ahead of the update timer" + ) + assert "Before=systemd-sysupdate.service" in service + assert "WantedBy=multi-user.target" in service, ( + "the unit must be enabled so it runs at boot" + ) + + +def test_update_unit_prunes_features_before_every_update() -> None: + dropin = DROPIN.read_text(encoding="utf-8") + assert "[Service]" in dropin + assert "ExecStartPre=-/usr/bin/bluefin-sysupdate-migrate" in dropin, ( + "the prune must run before systemd-sysupdate itself, so timer- and " + "hand-triggered updates are both covered" + ) + + +def test_migration_unit_is_enabled_in_usr() -> None: + # Presets only apply on first boot; updated nodes need the /usr link. + usr = USR.read_text(encoding="utf-8") + assert "multi-user.target.wants/bluefin-sysupdate-migrate.service" in usr + + +# ── Behavioural contracts --------------------------------------------------- + + +def _make_tree( + tmp_path: Path, remote: list[str], local: dict[str, str], enabled: list[str] +) -> tuple[Path, Path]: + """Local transfers (feature -> file pattern) against a file:// remote.""" + etc = tmp_path / "etc" / "sysupdate.d" + lib = tmp_path / "usr" / "lib" / "sysupdate.d" + rel = tmp_path / "release" + for d in (etc, lib, rel): + d.mkdir(parents=True) + (rel / "SHA256SUMS").write_text( + "".join(f"{'0' * 64} *{name}\n" for name in remote), encoding="utf-8" + ) + for i, (feature, pattern) in enumerate(local.items()): + (lib / f"{10 + i}-{feature}.transfer").write_text( + f"[Transfer]\nFeatures={feature}\n\n[Source]\nType=url-file\n" + f"Path=file://{rel}/\nMatchPattern={pattern}\n", + encoding="utf-8", + ) + for name in enabled: + (etc / f"{name}.feature.d").mkdir() + return etc, lib + + +def test_feature_dropped_from_remote_is_archived_though_local_transfer_exists( + tmp_path: Path, +) -> None: + # The stalled node still ships the homebrew transfer locally; only the + # remote release dropped it. + etc, lib = _make_tree( + tmp_path, + remote=["k0s_1.2.raw.zst", "bluefin_1.2.raw"], + local={"k0s": "k0s_@v.raw.zst", "homebrew": "homebrew_@v.raw.zst"}, + enabled=["k0s", "homebrew"], + ) + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert (etc / "homebrew.feature.d.disabled").is_dir() + assert (etc / "k0s.feature.d").is_dir() + assert "not in the release manifest" in result.stdout + + +def test_feature_without_local_transfer_is_archived(tmp_path: Path) -> None: + etc, lib = _make_tree(tmp_path, remote=[], local={}, enabled=["homebrew"]) + assert run_helper(etc, lib).returncode == 0 + assert (etc / "homebrew.feature.d.disabled").is_dir() + + +def test_unreachable_manifest_leaves_features_alone(tmp_path: Path) -> None: + etc, lib = _make_tree( + tmp_path, remote=[], local={"homebrew": "homebrew_@v.raw.zst"}, enabled=["homebrew"] + ) + for f in (tmp_path / "release").iterdir(): + f.unlink() + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert (etc / "homebrew.feature.d").is_dir(), "offline must never archive" + + +def test_non_manifest_manifest_leaves_features_alone(tmp_path: Path) -> None: + # A 200 response that is not a SHA256SUMS (a captive portal or proxy error + # page) must never archive a working feature: it is treated as + # unreachable. `curl -f` only fails on HTTP >= 400, so a valid-looking + # status with an HTML body would otherwise set found=no for every transfer. + etc, lib = _make_tree( + tmp_path, remote=[], local={"homebrew": "homebrew_@v.raw.zst"}, enabled=["homebrew"] + ) + (tmp_path / "release" / "SHA256SUMS").write_text( + "Captive Login\n", encoding="utf-8" + ) + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert (etc / "homebrew.feature.d").is_dir(), "a non-manifest 200 must never archive" + + +def test_helper_is_idempotent_on_rerun(tmp_path: Path) -> None: + etc, lib = _make_tree(tmp_path, remote=[], local={}, enabled=["homebrew"]) + assert run_helper(etc, lib).returncode == 0 + second = run_helper(etc, lib) + assert second.returncode == 0, second.stderr + assert (etc / "homebrew.feature.d.disabled").is_dir() + assert not (etc / "homebrew.feature.d.disabled.disabled").exists() + assert "no deprecated sysupdate features found" in second.stdout + + +def test_no_orphaned_feature_is_a_noop(tmp_path: Path) -> None: + etc, lib = _make_tree( + tmp_path, + remote=["k0s_1.raw.zst", "homebrew_1.raw.zst"], + local={"k0s": "k0s_@v.raw.zst", "homebrew": "homebrew_@v.raw.zst"}, + enabled=["k0s", "homebrew"], + ) + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert (etc / "k0s.feature.d").is_dir() + assert (etc / "homebrew.feature.d").is_dir() + assert "no deprecated sysupdate features found" in result.stdout + + +def test_missing_etc_directory_is_a_noop(tmp_path: Path) -> None: + lib = tmp_path / "usr" / "lib" / "sysupdate.d" + lib.mkdir(parents=True) + result = run_helper(tmp_path / "does-not-exist", lib) + assert result.returncode == 0, result.stderr + assert "nothing to do" in result.stdout + + +def test_existing_archive_is_not_clobbered(tmp_path: Path) -> None: + etc, lib = _make_tree(tmp_path, remote=[], local={}, enabled=["homebrew"]) + (etc / "homebrew.feature.d.disabled").mkdir() + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert "already archived" in result.stderr + assert not (etc / "homebrew.feature.d.disabled" / "homebrew.feature.d").exists() + + +def test_features_list_accepts_spaces_and_commas(tmp_path: Path) -> None: + etc, lib = _make_tree( + tmp_path, remote=["x_1.raw"], local={}, enabled=["k0s", "homebrew"] + ) + (lib / "10-example.transfer").write_text( + f"[Transfer]\nFeatures=k0s, homebrew\n[Source]\nType=url-file\n" + f"Path=file://{tmp_path}/release/\nMatchPattern=x_@v.raw\n", + encoding="utf-8", + ) + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert (etc / "k0s.feature.d").is_dir() + assert (etc / "homebrew.feature.d").is_dir() + + +def test_archived_feature_is_restored_when_release_ships_it_again( + tmp_path: Path, +) -> None: + etc, lib = _make_tree( + tmp_path, + remote=["zfs_1.3.raw.zst"], + local={"zfs": "zfs_@v.raw.zst"}, + enabled=[], + ) + (etc / "zfs.feature.d.disabled").mkdir() + result = run_helper(etc, lib) + assert result.returncode == 0, result.stderr + assert (etc / "zfs.feature.d").is_dir() + assert not (etc / "zfs.feature.d.disabled").exists() + assert "restored" in result.stdout + + +def test_archived_feature_stays_archived_while_release_lacks_it( + tmp_path: Path, +) -> None: + etc, lib = _make_tree( + tmp_path, remote=[], local={"zfs": "zfs_@v.raw.zst"}, enabled=[] + ) + (etc / "zfs.feature.d.disabled").mkdir() + assert run_helper(etc, lib).returncode == 0 + assert (etc / "zfs.feature.d.disabled").is_dir() + assert not (etc / "zfs.feature.d").exists() + + +def test_manifest_is_fetched_once_per_url(tmp_path: Path) -> None: + etc, lib = _make_tree( + tmp_path, + remote=["a_1.raw"], + local={"a": "a_@v.raw", "b": "b_@v.raw", "c": "c_@v.raw"}, + enabled=["a"], + ) + bindir = tmp_path / "bin" + bindir.mkdir() + log = tmp_path / "curl.log" + curl = bindir / "curl" + curl.write_text(f'#!/bin/sh\necho x >> {log}\nexec /usr/bin/curl "$@"\n') + curl.chmod(0o755) + env = { + **os.environ, + "PATH": f"{bindir}:{os.environ['PATH']}", + "SYSUPDATE_ETC_DIR": str(etc), + "SYSUPDATE_LIB_DIR": str(lib), + } + subprocess.run([str(SCRIPT)], env=env, check=True, capture_output=True) + assert len(log.read_text().splitlines()) == 1