From caf2e15d2bfc0084c3c54b6a731e12b34c4fa47a Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Sun, 15 Nov 2026 22:36:41 -0600 Subject: [PATCH] fetch: start a stopped podman machine before loading the container `ltvm target fetch` and `target publish` took the podman usage lock but never ran the machine preflight that every build runs. So once the idle stop had stopped the macOS machine, half an hour after the last build, each fetch failed in `podman load` with "Cannot connect to Podman". A build started the machine again; a fetch never did. Both now call `check_podman_machine_macos()`. It starts a stopped machine, repairs a wedged one and holds the usage lock, as for a build. Co-Authored-By: Claude Opus 5.5 --- ltvm_pkg/release_package.py | 22 ++++++++++---- tests/conftest.py | 8 +++-- tests/test_fetch_podman_preflight.py | 45 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 tests/test_fetch_podman_preflight.py diff --git a/ltvm_pkg/release_package.py b/ltvm_pkg/release_package.py index ac90a060..3351e931 100644 --- a/ltvm_pkg/release_package.py +++ b/ltvm_pkg/release_package.py @@ -90,6 +90,20 @@ def _schema_id() -> str: return f"{SCHEMA_NAME}/{SCHEMA_VERSION}" +def _ensure_podman() -> None: + """Make podman usable before a fetch or publish runs it. + + On macOS this starts a stopped machine -- the idle stop leaves it + stopped half an hour after the last build -- and holds the usage + lock, as the build preflight does. Taking only the lock left every + `target fetch` after an idle stop failing `podman load` with "Cannot + connect to Podman". + """ + from ltvm_pkg.host_setup import check_podman_machine_macos + + check_podman_machine_macos() + + def _producer_metadata() -> dict[str, str]: """Descriptive info about which ltvm wrote this manifest. @@ -510,9 +524,7 @@ def export_build_container( container_dir.mkdir(parents=True, exist_ok=True) image_tar = container_dir / "image.tar" - from ltvm_pkg.host_setup import hold_podman_usage - - hold_podman_usage() + _ensure_podman() try: check = subprocess.run( ["podman", "image", "exists", container_tag], @@ -1554,9 +1566,7 @@ def fetch_target( f"fetched asset set missing container image at {container_image}" ) print(f" Loading build container from {container_image}") - from ltvm_pkg.host_setup import hold_podman_usage - - hold_podman_usage() + _ensure_podman() try: load = subprocess.run( ["podman", "load", "-i", str(container_image)], diff --git a/tests/conftest.py b/tests/conftest.py index 44dfd3de..c99c0b3e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -230,8 +230,12 @@ def _neutralize_podman_preflight() -> object: would fail tests that don't mock podman. The tests already stub the actual build functions, so the preflight is orthogonal. """ - with patch( - "ltvm_pkg.cli.build.check_podman_machine_macos", return_value=None + with ( + patch( + "ltvm_pkg.cli.build.check_podman_machine_macos", + return_value=None, + ), + patch("ltvm_pkg.release_package._ensure_podman", return_value=None), ): yield diff --git a/tests/test_fetch_podman_preflight.py b/tests/test_fetch_podman_preflight.py new file mode 100644 index 00000000..93bf762c --- /dev/null +++ b/tests/test_fetch_podman_preflight.py @@ -0,0 +1,45 @@ +"""fetch and publish start a stopped macOS podman machine before using it. + +They took only the usage lock, so once the idle stop had stopped the +machine every `target fetch` failed `podman load` with "Cannot connect to +Podman". +""" + +from __future__ import annotations + +from pathlib import Path +from unittest.mock import MagicMock, patch + +import pytest + +from ltvm_pkg import release_package + +# Taken at import, before conftest's autouse stub replaces it. +real_ensure_podman = release_package._ensure_podman + + +def test_export_build_container_starts_podman_first(tmp_path: Path) -> None: + calls: list[str] = [] + + def run(cmd: list[str], **_kw: object) -> MagicMock: + calls.append(" ".join(cmd[:2])) + return MagicMock(returncode=1, stdout="", stderr="") + + with ( + patch.object( + release_package, + "_ensure_podman", + side_effect=lambda: calls.append("preflight"), + ), + patch.object(release_package.subprocess, "run", side_effect=run), + pytest.raises(RuntimeError, match="not found in podman storage"), + ): + release_package.export_build_container("rocky9", tmp_path) + assert calls[:2] == ["preflight", "podman image"] + + +def test_ensure_podman_runs_the_machine_preflight() -> None: + # The suite stubs _ensure_podman (conftest); this is the real one. + with patch("ltvm_pkg.host_setup.check_podman_machine_macos") as check: + real_ensure_podman() + check.assert_called_once_with()