fix(vm-provision): say why a cloud-image download failed, drop its tmp
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m29s
driver / test (3.13) (pull_request) Successful in 1m26s
driver / test (3.12) (pull_request) Successful in 1m39s
driver / lowest (pull_request) Successful in 37s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m11s
CI / driver (pull_request) Successful in 3m19s
driver / publish (pull_request) Skipped

wget ran with -q, so a failure carried no reason, and a failed
download left its partial .tmp in the cache, taking the same space
again on every retry. wget now runs with -nv and the .tmp is removed
on failure, keeping wget's exit status.

Closes #3
This commit is contained in:
Christian Manivong committed 2026-11-01 21:57:36 +01:00
1 parent 10cf788b86
commit 9c7b64ba64
4 files changed
+68 -7

No files matched your search

+49
View File
@@ -1364,3 +1364,52 @@ def test_create_vm_passes_every_ssh_key_one_per_line():
sshkeys = call[1]["sshkeys"]
assert unquote(sshkeys) == "\n".join(keys)
assert re.fullmatch(r"[-%a-zA-Z0-9_.!~*'()]*", sshkeys)
class _LocalShell:
"""The node's SSH session as a local ``sh``, *prelude* run before each command."""
def __init__(self, prelude: str) -> None:
self.prelude = prelude
def exec_command(self, command: str, timeout: int | None = None):
import subprocess
run = subprocess.run(
["sh", "-c", self.prelude + command], capture_output=True, timeout=timeout
)
return _mock_ssh_exec(run.returncode, run.stdout.decode(), run.stderr.decode())
# wget as it fails on a full disk: part of the file written, the reason on stderr.
_WGET_DISK_FULL = (
"wget() { "
'while [ $# -gt 0 ]; do [ "$1" = -O ] && o=$2; shift; done; '
'echo partial > "$o"; '
'echo "$o: No space left on device" >&2; return 3; }; '
)
def test_download_cloud_image_failure_says_why_and_leaves_no_tmp(tmp_path, monkeypatch):
"""A failed download names wget's reason and removes its .tmp (napalm-proxmox#3)."""
import napalm_proxmox.vm_provision_mixin as module
monkeypatch.setattr(module, "_IMAGE_CACHE_DIR", str(tmp_path))
mixin = ProxmoxVMProvisionMixin()
mixin._node_ssh = MagicMock(return_value=_LocalShell(_WGET_DISK_FULL))
with pytest.raises(RuntimeError, match="No space left on device") as err:
mixin._download_cloud_image("https://example.org/img/debian.qcow2", None, timeout=10)
assert "exit 3" in str(err.value)
assert list(tmp_path.iterdir()) == []
def test_download_cloud_image_does_not_silence_wget():
mixin = ProxmoxVMProvisionMixin()
mixin._run_node_command = MagicMock(side_effect=["MISSING", ""])
mixin._download_cloud_image("https://example.org/img/debian.qcow2", None, timeout=10)
download = mixin._run_node_command.call_args_list[1][0][0]
assert download.startswith("wget -nv ")