refactor: implement dynamic storage discovery and add unit tests

This commit is contained in:
Fredrick Amnehagen 2026-02-05 22:31:05 +01:00
parent 4231253dc7
commit 5d61ef8116
2 changed files with 58 additions and 24 deletions

View file

@ -0,0 +1,33 @@
import pytest
from unittest.mock import MagicMock, patch
from infra_cli.proxmox import ProxmoxManager
class MockConfig:
def get_node(self, name):
return {"host": "1.2.3.4", "pass": "secret"}
def get(self, key, default=None):
return default
@patch('infra_cli.proxmox.SSHClient')
def test_template_resolution(mock_ssh):
# Setup mock SSH response
mock_instance = mock_ssh.return_value
mock_instance.run.return_value.returncode = 0
mock_instance.run.return_value.stdout = "local:vztmpl/debian-13-standard_13.1-2_amd64.tar.zst tzst vztmpl 129710398"
mgr = ProxmoxManager(MockConfig())
resolved = mgr.resolve_template("debian-13")
assert resolved == "local:vztmpl/debian-13-standard_13.1-2_amd64.tar.zst"
mock_instance.run.assert_called_with("pvesm list --content vztmpl | grep 'debian-13-standard' | sort -V | tail -n 1")
@patch('infra_cli.proxmox.SSHClient')
def test_storage_discovery(mock_ssh):
mock_instance = mock_ssh.return_value
mock_instance.run.return_value.returncode = 0
mock_instance.run.return_value.stdout = "local-zfs zfspool active 1000 500 500 50%"
mgr = ProxmoxManager(MockConfig())
storage = mgr.discover_storage()
assert storage == "local-zfs"