64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
"""Tests for get_environment."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from tests.conftest import _build_mock_api, NODE_STATUS
|
|
from unittest.mock import patch
|
|
|
|
from napalm_proxmox.driver import ProxmoxDriver
|
|
|
|
|
|
class TestGetEnvironment:
|
|
def test_cpu_usage_present(self, driver):
|
|
result = driver.get_environment()
|
|
assert "0" in result["cpu"]
|
|
assert result["cpu"]["0"]["%usage"] == pytest.approx(12.0, abs=0.1)
|
|
|
|
def test_memory_total(self, driver):
|
|
result = driver.get_environment()
|
|
assert result["memory"]["available_ram"] == 137438953472
|
|
assert result["memory"]["used_ram"] == 68719476736
|
|
|
|
def test_fans_empty_when_no_sensors(self, driver):
|
|
result = driver.get_environment()
|
|
assert isinstance(result["fans"], dict)
|
|
|
|
def test_temperature_with_sensors(self):
|
|
from tests.conftest import _build_mock_api, NODE_STATUS
|
|
from unittest.mock import patch
|
|
from napalm_proxmox.driver import ProxmoxDriver
|
|
|
|
sensors_data = [
|
|
{"name": "CPU Package", "value": "55.0"},
|
|
{"name": "GPU Core", "value": "92.0"},
|
|
]
|
|
mock_api = _build_mock_api(sensors=sensors_data)
|
|
drv = ProxmoxDriver("pve1", "root", "secret", optional_args={"verify_ssl": False})
|
|
with patch("napalm_proxmox.driver.ProxmoxAPI", return_value=mock_api):
|
|
drv.open()
|
|
|
|
result = drv.get_environment()
|
|
assert "CPU Package" in result["temperature"]
|
|
assert result["temperature"]["CPU Package"]["temperature"] == 55.0
|
|
assert result["temperature"]["CPU Package"]["is_alert"] is False
|
|
assert result["temperature"]["CPU Package"]["is_critical"] is False
|
|
|
|
assert "GPU Core" in result["temperature"]
|
|
assert result["temperature"]["GPU Core"]["is_alert"] is True
|
|
assert result["temperature"]["GPU Core"]["is_critical"] is False
|
|
|
|
def test_temperature_critical(self):
|
|
from tests.conftest import _build_mock_api
|
|
from unittest.mock import patch
|
|
from napalm_proxmox.driver import ProxmoxDriver
|
|
|
|
sensors_data = [{"name": "NVMe", "value": "98.0"}]
|
|
mock_api = _build_mock_api(sensors=sensors_data)
|
|
drv = ProxmoxDriver("pve1", "root", "secret", optional_args={"verify_ssl": False})
|
|
with patch("napalm_proxmox.driver.ProxmoxAPI", return_value=mock_api):
|
|
drv.open()
|
|
|
|
result = drv.get_environment()
|
|
assert result["temperature"]["NVMe"]["is_critical"] is True
|