From cd60286ac16849b998b8fb241acdd8ffdc7065eb Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 6 Dec 2026 22:26:05 +0100 Subject: [PATCH] fix: the root-disk step refuses a missing source instead of asserting it bandit (B101): an assert vanishes under python -O. The source check refuses a VM with neither image_url nor image_volume before anything is created; the root-disk step now raises the same ValueError should it ever be reached. --- napalm_proxmox/vm_provision_mixin.py | 3 ++- tests/test_storage_images.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/napalm_proxmox/vm_provision_mixin.py b/napalm_proxmox/vm_provision_mixin.py index 0d45471..4969c6c 100644 --- a/napalm_proxmox/vm_provision_mixin.py +++ b/napalm_proxmox/vm_provision_mixin.py @@ -376,7 +376,8 @@ class ProxmoxVMProvisionMixin: """ image_url, volid = image if volid is None: - assert image_url is not None # _check_image_source + if image_url is None: # _check_image_source refuses this before any VM exists + raise ValueError("a root disk needs image_url or image_volume") import_storage = self._find_import_storage() filename = import_volume_name(image_url) if import_storage else None if not import_storage or not filename: diff --git a/tests/test_storage_images.py b/tests/test_storage_images.py index 39870ec..123158a 100644 --- a/tests/test_storage_images.py +++ b/tests/test_storage_images.py @@ -424,3 +424,9 @@ class TestCreateFromAVolume: with pytest.raises(ValueError, match="not on"): _create(mixin, image_volume="local:import/elsewhere.qcow2") mixin._api.cluster.nextid.get.assert_not_called() + + def test_the_root_disk_without_a_source_is_refused_even_past_the_check(self): + """The check refuses it first; the disk step refuses it too, never assumes it.""" + mixin, _ = _provisioner() + with pytest.raises(ValueError, match="image_url or image_volume"): + mixin._attach_root_disk(101, "local-zfs", (None, None), None, 60, 60)