mirror of https://github.com/home-assistant/core
187 lines
5.7 KiB
Python
187 lines
5.7 KiB
Python
"""Test Supervisor diagnostics."""
|
|
|
|
import os
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.hassio import DOMAIN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import MockConfigEntry
|
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
from tests.typing import ClientSessionGenerator
|
|
|
|
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_all(
|
|
aioclient_mock: AiohttpClientMocker,
|
|
addon_installed: AsyncMock,
|
|
store_info: AsyncMock,
|
|
addon_stats: AsyncMock,
|
|
addon_changelog: AsyncMock,
|
|
resolution_info: AsyncMock,
|
|
) -> None:
|
|
"""Mock all setup requests."""
|
|
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
|
|
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/info",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"supervisor": "222",
|
|
"homeassistant": "0.110.0",
|
|
"hassos": "1.2.3",
|
|
},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/host/info",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"result": "ok",
|
|
"data": {
|
|
"chassis": "vm",
|
|
"operating_system": "Debian GNU/Linux 10 (buster)",
|
|
"kernel": "4.19.0-6-amd64",
|
|
},
|
|
},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/core/info",
|
|
json={
|
|
"result": "ok",
|
|
"data": {"version_latest": "1.0.0dev222", "version": "1.0.0dev221"},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/os/info",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"version_latest": "1.0.0dev2222",
|
|
"version": "1.0.0dev2221",
|
|
"update_available": False,
|
|
},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/supervisor/info",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"result": "ok",
|
|
"version": "1.0.0",
|
|
"version_latest": "1.0.1dev222",
|
|
"addons": [
|
|
{
|
|
"name": "test",
|
|
"state": "started",
|
|
"slug": "test",
|
|
"installed": True,
|
|
"update_available": True,
|
|
"icon": False,
|
|
"version": "2.0.0",
|
|
"version_latest": "2.0.1",
|
|
"repository": "core",
|
|
"url": "https://github.com/home-assistant/addons/test",
|
|
},
|
|
{
|
|
"name": "test2",
|
|
"state": "stopped",
|
|
"slug": "test2",
|
|
"installed": True,
|
|
"update_available": False,
|
|
"icon": True,
|
|
"version": "3.1.0",
|
|
"version_latest": "3.1.0",
|
|
"repository": "core",
|
|
"url": "https://github.com",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/core/stats",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"cpu_percent": 0.99,
|
|
"memory_usage": 182611968,
|
|
"memory_limit": 3977146368,
|
|
"memory_percent": 4.59,
|
|
"network_rx": 362570232,
|
|
"network_tx": 82374138,
|
|
"blk_read": 46010945536,
|
|
"blk_write": 15051526144,
|
|
},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/supervisor/stats",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"cpu_percent": 0.99,
|
|
"memory_usage": 182611968,
|
|
"memory_limit": 3977146368,
|
|
"memory_percent": 4.59,
|
|
"network_rx": 362570232,
|
|
"network_tx": 82374138,
|
|
"blk_read": 46010945536,
|
|
"blk_write": 15051526144,
|
|
},
|
|
},
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
|
|
)
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/network/info",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"host_internet": True,
|
|
"supervisor_internet": True,
|
|
},
|
|
},
|
|
)
|
|
|
|
|
|
async def test_diagnostics(
|
|
hass: HomeAssistant,
|
|
hass_client: ClientSessionGenerator,
|
|
) -> None:
|
|
"""Test diagnostic information."""
|
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
|
config_entry.add_to_hass(hass)
|
|
|
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
|
result = await async_setup_component(
|
|
hass,
|
|
"hassio",
|
|
{"http": {"server_port": 9999, "server_host": "127.0.0.1"}, "hassio": {}},
|
|
)
|
|
assert result
|
|
await hass.async_block_till_done()
|
|
|
|
diagnostics = await get_diagnostics_for_config_entry(
|
|
hass, hass_client, config_entry
|
|
)
|
|
|
|
assert "addons" in diagnostics["coordinator_data"]
|
|
assert "core" in diagnostics["coordinator_data"]
|
|
assert "supervisor" in diagnostics["coordinator_data"]
|
|
assert "os" in diagnostics["coordinator_data"]
|
|
assert "host" in diagnostics["coordinator_data"]
|
|
|
|
assert len(diagnostics["devices"]) == 6
|