Use Supervisor arch to determine container arch

For installations with Supervisor, use the architecture from the
Supervisor API instead of reading the architecture from the
container. This is more coherent as we trust the Supervisor data
already, and gets rid of an unnecessary dependency for aiofiles.
This commit is contained in:
Stefan Agner
2025-06-23 17:39:30 +02:00
parent 83aeb572c4
commit f2f98eb4e2
3 changed files with 12 additions and 62 deletions

View File

@@ -12,7 +12,6 @@ import re
import struct import struct
from typing import Any, NamedTuple from typing import Any, NamedTuple
import aiofiles
from aiohasupervisor import SupervisorError from aiohasupervisor import SupervisorError
import voluptuous as vol import voluptuous as vol
@@ -239,12 +238,6 @@ def _is_32_bit() -> bool:
return size * 8 == 32 return size * 8 == 32
async def _get_arch() -> str:
async with aiofiles.open("/etc/apk/arch") as arch_file:
raw_arch = await arch_file.read()
return {"x86": "i386"}.get(raw_arch, raw_arch)
class APIEndpointSettings(NamedTuple): class APIEndpointSettings(NamedTuple):
"""Settings for API endpoint.""" """Settings for API endpoint."""
@@ -566,8 +559,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
hass.data[ADDONS_COORDINATOR] = coordinator hass.data[ADDONS_COORDINATOR] = coordinator
arch = await _get_arch()
def deprecated_setup_issue() -> None: def deprecated_setup_issue() -> None:
os_info = get_os_info(hass) os_info = get_os_info(hass)
info = get_info(hass) info = get_info(hass)
@@ -575,6 +566,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return return
is_haos = info.get("hassos") is not None is_haos = info.get("hassos") is not None
board = os_info.get("board") board = os_info.get("board")
arch = info.get("arch", "unknown")
unsupported_board = board in {"tinker", "odroid-xu4", "rpi2"} unsupported_board = board in {"tinker", "odroid-xu4", "rpi2"}
unsupported_os_on_board = board in {"rpi3", "rpi4"} unsupported_os_on_board = board in {"rpi3", "rpi4"}
if is_haos and (unsupported_board or unsupported_os_on_board): if is_haos and (unsupported_board or unsupported_os_on_board):

View File

@@ -260,16 +260,3 @@ def all_setup_requests(
}, },
}, },
) )
@pytest.fixture
def arch() -> str:
"""Arch found in apk file."""
return "amd64"
@pytest.fixture(autouse=True)
def mock_arch_file(arch: str) -> Generator[None]:
"""Mock arch file."""
with patch("homeassistant.components.hassio._get_arch", return_value=arch):
yield

View File

@@ -1166,17 +1166,11 @@ async def test_deprecated_installation_issue_os_armv7(
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
board: str, board: str,
issue_id: str, issue_id: str,
arch: str,
) -> None: ) -> None:
"""Test deprecated installation issue.""" """Test deprecated installation issue."""
with ( with (
patch.dict(os.environ, MOCK_ENVIRON), patch.dict(os.environ, MOCK_ENVIRON),
patch(
"homeassistant.components.homeassistant.async_get_system_info",
return_value={
"installation_type": "Home Assistant OS",
"arch": "armv7",
},
),
patch( patch(
"homeassistant.components.hassio._is_32_bit", "homeassistant.components.hassio._is_32_bit",
return_value=True, return_value=True,
@@ -1185,7 +1179,8 @@ async def test_deprecated_installation_issue_os_armv7(
"homeassistant.components.hassio.get_os_info", return_value={"board": board} "homeassistant.components.hassio.get_os_info", return_value={"board": board}
), ),
patch( patch(
"homeassistant.components.hassio.get_info", return_value={"hassos": True} "homeassistant.components.hassio.get_info",
return_value={"hassos": True, "arch": "armv7"},
), ),
patch("homeassistant.components.hardware.async_setup", return_value=True), patch("homeassistant.components.hardware.async_setup", return_value=True),
): ):
@@ -1238,13 +1233,6 @@ async def test_deprecated_installation_issue_32bit_os(
"""Test deprecated architecture issue.""" """Test deprecated architecture issue."""
with ( with (
patch.dict(os.environ, MOCK_ENVIRON), patch.dict(os.environ, MOCK_ENVIRON),
patch(
"homeassistant.components.homeassistant.async_get_system_info",
return_value={
"installation_type": "Home Assistant OS",
"arch": arch,
},
),
patch( patch(
"homeassistant.components.hassio._is_32_bit", "homeassistant.components.hassio._is_32_bit",
return_value=True, return_value=True,
@@ -1254,7 +1242,8 @@ async def test_deprecated_installation_issue_32bit_os(
return_value={"board": "rpi3-64"}, return_value={"board": "rpi3-64"},
), ),
patch( patch(
"homeassistant.components.hassio.get_info", return_value={"hassos": True} "homeassistant.components.hassio.get_info",
return_value={"hassos": True, "arch": arch},
), ),
patch("homeassistant.components.hardware.async_setup", return_value=True), patch("homeassistant.components.hardware.async_setup", return_value=True),
): ):
@@ -1305,13 +1294,6 @@ async def test_deprecated_installation_issue_32bit_supervised(
"""Test deprecated architecture issue.""" """Test deprecated architecture issue."""
with ( with (
patch.dict(os.environ, MOCK_ENVIRON), patch.dict(os.environ, MOCK_ENVIRON),
patch(
"homeassistant.components.homeassistant.async_get_system_info",
return_value={
"installation_type": "Home Assistant Supervised",
"arch": arch,
},
),
patch( patch(
"homeassistant.components.hassio._is_32_bit", "homeassistant.components.hassio._is_32_bit",
return_value=True, return_value=True,
@@ -1321,7 +1303,8 @@ async def test_deprecated_installation_issue_32bit_supervised(
return_value={"board": "rpi3-64"}, return_value={"board": "rpi3-64"},
), ),
patch( patch(
"homeassistant.components.hassio.get_info", return_value={"hassos": None} "homeassistant.components.hassio.get_info",
return_value={"hassos": None, "arch": arch},
), ),
patch("homeassistant.components.hardware.async_setup", return_value=True), patch("homeassistant.components.hardware.async_setup", return_value=True),
): ):
@@ -1376,13 +1359,6 @@ async def test_deprecated_installation_issue_64bit_supervised(
"""Test deprecated architecture issue.""" """Test deprecated architecture issue."""
with ( with (
patch.dict(os.environ, MOCK_ENVIRON), patch.dict(os.environ, MOCK_ENVIRON),
patch(
"homeassistant.components.homeassistant.async_get_system_info",
return_value={
"installation_type": "Home Assistant Supervised",
"arch": arch,
},
),
patch( patch(
"homeassistant.components.hassio._is_32_bit", "homeassistant.components.hassio._is_32_bit",
return_value=False, return_value=False,
@@ -1392,7 +1368,8 @@ async def test_deprecated_installation_issue_64bit_supervised(
return_value={"board": "generic-x86-64"}, return_value={"board": "generic-x86-64"},
), ),
patch( patch(
"homeassistant.components.hassio.get_info", return_value={"hassos": None} "homeassistant.components.hassio.get_info",
return_value={"hassos": None, "arch": arch},
), ),
patch("homeassistant.components.hardware.async_setup", return_value=True), patch("homeassistant.components.hardware.async_setup", return_value=True),
): ):
@@ -1445,13 +1422,6 @@ async def test_deprecated_installation_issue_supported_board(
"""Test no deprecated installation issue for a supported board.""" """Test no deprecated installation issue for a supported board."""
with ( with (
patch.dict(os.environ, MOCK_ENVIRON), patch.dict(os.environ, MOCK_ENVIRON),
patch(
"homeassistant.components.homeassistant.async_get_system_info",
return_value={
"installation_type": "Home Assistant OS",
"arch": "aarch64",
},
),
patch( patch(
"homeassistant.components.hassio._is_32_bit", "homeassistant.components.hassio._is_32_bit",
return_value=False, return_value=False,
@@ -1460,7 +1430,8 @@ async def test_deprecated_installation_issue_supported_board(
"homeassistant.components.hassio.get_os_info", return_value={"board": board} "homeassistant.components.hassio.get_os_info", return_value={"board": board}
), ),
patch( patch(
"homeassistant.components.hassio.get_info", return_value={"hassos": True} "homeassistant.components.hassio.get_info",
return_value={"hassos": True, "arch": "aarch64"},
), ),
): ):
assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "homeassistant", {})