fix: re-download cached import images when checksum is provided
Some checks failed
Deploy to Production / Trigger production update (push) Has been cancelled
Backend Tests / pytest (Python 3.12) (push) Has been cancelled

volume_exists() only checked file presence, not content. A stale image
from a previous download (different URL/version) would be silently reused,
causing templates and VMs to be created from unpatched images even when
the mirror's checksum pointed to a newer patched build.

Add delete_volume() to ProxmoxClient storage mixin, and update both
_do_image_download_sync and _do_image_template_sync to delete the cached
volume and re-download whenever a checksum is provided, letting Proxmox
verify the new download server-side.
This commit is contained in:
2026-08-14 16:19:41 +05:00
parent 3540291c0e
commit 8ff757f8c1
2 changed files with 37 additions and 7 deletions

View File

@@ -170,6 +170,21 @@ class StorageMixin:
logger.debug(f"volume_exists check failed {storage}/{volid}: {e}")
return False
def delete_volume(self, node: str, storage: str, volid: str) -> bool:
"""Удалить том из хранилища. volid вида 'storage:content/filename'.
Возвращает True при успехе, False при ошибке."""
if not self.proxmox:
return False
# proxmoxer принимает volume без префикса хранилища
volume = volid.split(':', 1)[1] if ':' in volid else volid
try:
self.proxmox.nodes(node).storage(storage).content(volume).delete()
logger.info(f"Deleted volume {volid} from {node}:{storage}")
return True
except Exception as e:
logger.warning(f"delete_volume failed {node}:{storage}/{volume}: {e}")
return False
def get_download_target_storages(self, node: str, content: str) -> List[Dict]:
"""
Получить активные хранилища ноды, поддерживающие указанный тип контента