fix: name the VM a failed create_vm_from_cloud_init leaves behind
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Failing after 1m6s
driver / lowest (pull_request) Failing after 5s
driver / test (3.13) (pull_request) Failing after 58s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Failing after 2m49s
driver / publish (pull_request) Skipped

A failure after the VM shell existed (disk import, NIC or snippet config,
start) raised without the VMID, so the caller could not remove the
half-built VM and it stayed on the node. It now raises napalm-device-types'
VMProvisionIncomplete with vmid and node, the failure as its cause. A
failure before the shell exists raises as before.

The NIC config strings are built by a helper of their own, which keeps
create_vm_from_cloud_init within its quality baseline.

Closes #28
This commit is contained in:
Christian Manivong committed 2026-11-01 22:11:13 +01:00
1 parent cb29a42c31
commit 61821cd607
5 files changed
+179 -32

No files matched your search

+6 -2
View File
@@ -6,6 +6,7 @@ import base64
from unittest.mock import MagicMock, patch
import pytest
from napalm_device_types.provisioning import VMProvisionIncomplete
from napalm_proxmox.vm_provision_mixin import ProxmoxVMProvisionMixin
@@ -220,7 +221,8 @@ def test_create_vm_from_cloud_init_dual_nic_trunk():
def test_create_vm_missing_snippet_storage():
"""create_vm_from_cloud_init raises ValueError if snippet storage unavailable."""
"""No snippet storage fails the creation; the VM shell exists by then, so the
ValueError arrives as the cause of VMProvisionIncomplete naming it (#28)."""
mixin = ProxmoxVMProvisionMixin()
mixin._node_name = "pve1"
@@ -250,7 +252,7 @@ def test_create_vm_missing_snippet_storage():
mock_task.status.get.return_value = {"status": "stopped", "exitstatus": "OK"}
mock_node.tasks.return_value = mock_task
with pytest.raises(ValueError, match="snippet"):
with pytest.raises(VMProvisionIncomplete, match="snippet") as caught:
with patch("napalm_proxmox.vm_provision_mixin.time.sleep"):
mixin.create_vm_from_cloud_init(
name="test-vm",
@@ -260,6 +262,8 @@ def test_create_vm_missing_snippet_storage():
nics=[{"bridge": "vmbr0"}],
cloud_init_config={},
)
assert isinstance(caught.value.__cause__, ValueError)
assert caught.value.vmid == "101"
def test_create_vm_with_disk_resize():