1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
"""Test OS supervisor client."""
from pathlib import PurePath
from aioresponses import aioresponses
import pytest
from yarl import URL
from aiohasupervisor import SupervisorClient
from aiohasupervisor.models import (
BootSlotName,
GreenOptions,
MigrateDataOptions,
OSUpdate,
SetBootSlotOptions,
YellowOptions,
)
from aiohasupervisor.models.os import SwapOptions
from . import load_fixture
from .const import SUPERVISOR_URL
async def test_os_info(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS info API."""
responses.get(
f"{SUPERVISOR_URL}/os/info",
status=200,
body=load_fixture("os_info.json"),
)
info = await supervisor_client.os.info()
assert info.version == "13.0"
assert info.version_latest == "13.1"
assert info.update_available is True
assert info.boot_slots["A"].state == "inactive"
assert info.boot_slots["B"].state == "booted"
assert info.boot_slots["B"].status == "good"
assert info.boot_slots["B"].version == "13.0"
@pytest.mark.parametrize("options", [None, OSUpdate(version="13.0")])
async def test_os_update(
responses: aioresponses,
supervisor_client: SupervisorClient,
options: OSUpdate | None,
) -> None:
"""Test OS update API."""
responses.post(f"{SUPERVISOR_URL}/os/update", status=200)
assert await supervisor_client.os.update(options) is None
assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/os/update"))}
async def test_os_swap_info(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS config swap API."""
responses.get(
f"{SUPERVISOR_URL}/os/config/swap",
status=200,
body=load_fixture("os_config_swap.json"),
)
info = await supervisor_client.os.swap_info()
assert info.swap_size == "1G"
assert info.swappiness == 1
async def test_os_set_swap_options(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS set swap options API."""
responses.post(f"{SUPERVISOR_URL}/os/config/swap", status=200)
assert (
await supervisor_client.os.set_swap_options(
SwapOptions(swap_size="1G", swappiness=20)
)
is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/config/swap"))
}
async def test_os_config_sync(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS config sync API."""
responses.post(f"{SUPERVISOR_URL}/os/config/sync", status=200)
assert await supervisor_client.os.config_sync() is None
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/config/sync"))
}
async def test_os_migrate_data(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS migrate data API."""
responses.post(f"{SUPERVISOR_URL}/os/datadisk/move", status=200)
assert (
await supervisor_client.os.migrate_data(MigrateDataOptions(device="/dev/test"))
is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/datadisk/move"))
}
async def test_os_list_data_disks(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS datadisk list API."""
responses.get(
f"{SUPERVISOR_URL}/os/datadisk/list",
status=200,
body=load_fixture("os_datadisk_list.json"),
)
datadisks = await supervisor_client.os.list_data_disks()
assert datadisks[0].vendor == "SSK"
assert datadisks[0].model == "SSK Storage"
assert datadisks[0].serial == "DF123"
assert datadisks[0].name == "SSK SSK Storage (DF123)"
assert datadisks[0].dev_path == PurePath("/dev/sda")
async def test_os_wipe_data(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS wipe data API."""
responses.post(f"{SUPERVISOR_URL}/os/datadisk/wipe", status=200)
assert await supervisor_client.os.wipe_data() is None
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/datadisk/wipe"))
}
async def test_os_set_boot_slot(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS set boot slot API."""
responses.post(f"{SUPERVISOR_URL}/os/boot-slot", status=200)
assert (
await supervisor_client.os.set_boot_slot(
SetBootSlotOptions(boot_slot=BootSlotName.B)
)
is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/boot-slot"))
}
async def test_os_green_info(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS green board info API."""
responses.get(
f"{SUPERVISOR_URL}/os/boards/green",
status=200,
body=load_fixture("os_green_info.json"),
)
info = await supervisor_client.os.green_info()
assert info.activity_led is True
assert info.power_led is True
assert info.system_health_led is True
async def test_os_green_options(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS green board options API."""
responses.post(f"{SUPERVISOR_URL}/os/boards/green", status=200)
assert (
await supervisor_client.os.set_green_options(GreenOptions(activity_led=False))
is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/boards/green"))
}
async def test_os_yellow_info(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS yellow board info API."""
responses.get(
f"{SUPERVISOR_URL}/os/boards/yellow",
status=200,
body=load_fixture("os_yellow_info.json"),
)
info = await supervisor_client.os.yellow_info()
assert info.disk_led is True
assert info.heartbeat_led is True
assert info.power_led is True
async def test_os_yellow_options(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test OS yellow board options API."""
responses.post(f"{SUPERVISOR_URL}/os/boards/yellow", status=200)
assert (
await supervisor_client.os.set_yellow_options(
YellowOptions(heartbeat_led=False)
)
is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/os/boards/yellow"))
}
|