mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-10 18:56:30 +00:00
Update OS on intel-nuc to generic-x86-64 image (#2909)
* Add architectures supported by generic-x86-64 board * Follow intel-nuc to generic-x86-64 rename when updating Home Assistant OS renamed the intel-nuc board to generic-x86-64. Make sure to download the generic-x86-64 raucb OS update when updating a intel-nuc machine. * Don't explicit use section, rely on AwesomeVersion's comparision * Remove unecessary global variable TEST_URL * Fix version comparision * Remove rate limiter on updater.fetch_data() * Update tests/test_hassos.py Co-authored-by: Pascal Vizeli <pascal.vizeli@syshack.ch> * Fix black issue Co-authored-by: Pascal Vizeli <pascal.vizeli@syshack.ch>
This commit is contained in:
parent
bb127a614b
commit
a99bfa2926
@ -122,6 +122,7 @@ SCHEMA_ELEMENT = vol.Match(RE_SCHEMA_ELEMENT)
|
|||||||
RE_MACHINE = re.compile(
|
RE_MACHINE = re.compile(
|
||||||
r"^!?(?:"
|
r"^!?(?:"
|
||||||
r"|intel-nuc"
|
r"|intel-nuc"
|
||||||
|
r"|generic-x86-64"
|
||||||
r"|odroid-c2"
|
r"|odroid-c2"
|
||||||
r"|odroid-c4"
|
r"|odroid-c4"
|
||||||
r"|odroid-n2"
|
r"|odroid-n2"
|
||||||
|
@ -14,5 +14,6 @@
|
|||||||
"qemux86-64": ["amd64", "i386"],
|
"qemux86-64": ["amd64", "i386"],
|
||||||
"qemuarm": ["armhf"],
|
"qemuarm": ["armhf"],
|
||||||
"qemuarm-64": ["aarch64"],
|
"qemuarm-64": ["aarch64"],
|
||||||
"intel-nuc": ["amd64", "i386"]
|
"intel-nuc": ["amd64", "i386"],
|
||||||
|
"generic-x86-64": ["amd64", "i386"]
|
||||||
}
|
}
|
||||||
|
@ -55,15 +55,23 @@ class HassOS(CoreSysAttributes):
|
|||||||
"""Return board name."""
|
"""Return board name."""
|
||||||
return self._board
|
return self._board
|
||||||
|
|
||||||
async def _download_raucb(self, version: AwesomeVersion) -> Path:
|
def _get_download_url(self, version: AwesomeVersion) -> str:
|
||||||
"""Download rauc bundle (OTA) from github."""
|
|
||||||
raw_url = self.sys_updater.ota_url
|
raw_url = self.sys_updater.ota_url
|
||||||
if raw_url is None:
|
if raw_url is None:
|
||||||
raise HassOSUpdateError("Don't have an URL for OTA updates!", _LOGGER.error)
|
raise HassOSUpdateError("Don't have an URL for OTA updates!", _LOGGER.error)
|
||||||
url = raw_url.format(version=str(version), board=self.board)
|
|
||||||
|
|
||||||
|
update_board = self.board
|
||||||
|
|
||||||
|
# OS version 6 and later renamed intel-nuc to generic-x86-64...
|
||||||
|
if update_board == "intel-nuc" and version >= 6.0:
|
||||||
|
update_board = "generic-x86-64"
|
||||||
|
|
||||||
|
url = raw_url.format(version=str(version), board=update_board)
|
||||||
|
return url
|
||||||
|
|
||||||
|
async def _download_raucb(self, url: str, raucb: Path) -> None:
|
||||||
|
"""Download rauc bundle (OTA) from URL."""
|
||||||
_LOGGER.info("Fetch OTA update from %s", url)
|
_LOGGER.info("Fetch OTA update from %s", url)
|
||||||
raucb = Path(self.sys_config.path_tmp, f"hassos-{version!s}.raucb")
|
|
||||||
try:
|
try:
|
||||||
timeout = aiohttp.ClientTimeout(total=60 * 60, connect=180)
|
timeout = aiohttp.ClientTimeout(total=60 * 60, connect=180)
|
||||||
async with self.sys_websession.get(url, timeout=timeout) as request:
|
async with self.sys_websession.get(url, timeout=timeout) as request:
|
||||||
@ -82,7 +90,6 @@ class HassOS(CoreSysAttributes):
|
|||||||
ota_file.write(chunk)
|
ota_file.write(chunk)
|
||||||
|
|
||||||
_LOGGER.info("Completed download of OTA update file %s", raucb)
|
_LOGGER.info("Completed download of OTA update file %s", raucb)
|
||||||
return raucb
|
|
||||||
|
|
||||||
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
||||||
self.sys_supervisor.connectivity = False
|
self.sys_supervisor.connectivity = False
|
||||||
@ -154,7 +161,9 @@ class HassOS(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fetch files from internet
|
# Fetch files from internet
|
||||||
int_ota = await self._download_raucb(version)
|
ota_url = self._get_download_url(version)
|
||||||
|
int_ota = Path(self.sys_config.path_tmp, f"hassos-{version!s}.raucb")
|
||||||
|
await self._download_raucb(ota_url, int_ota)
|
||||||
ext_ota = Path(self.sys_config.path_extern_tmp, int_ota.name)
|
ext_ota = Path(self.sys_config.path_extern_tmp, int_ota.name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Common test functions."""
|
"""Common test functions."""
|
||||||
|
from functools import partial
|
||||||
|
from inspect import unwrap
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch
|
from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch
|
||||||
@ -161,6 +163,11 @@ async def coresys(loop, docker, network_manager, aiohttp_client) -> CoreSys:
|
|||||||
ha_version=AwesomeVersion("2021.2.4")
|
ha_version=AwesomeVersion("2021.2.4")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Remove rate limiting decorator from fetch_data
|
||||||
|
coresys_obj.updater.fetch_data = partial(
|
||||||
|
unwrap(coresys_obj.updater.fetch_data), coresys_obj.updater
|
||||||
|
)
|
||||||
|
|
||||||
yield coresys_obj
|
yield coresys_obj
|
||||||
|
|
||||||
await coresys_obj.websession.close()
|
await coresys_obj.websession.close()
|
||||||
|
22
tests/test_hassos.py
Normal file
22
tests/test_hassos.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""Test Home Assistant OS functionality."""
|
||||||
|
|
||||||
|
from awesomeversion import AwesomeVersion
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from supervisor.coresys import CoreSys
|
||||||
|
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_ota_url_generic_x86_64_rename(coresys: CoreSys) -> None:
|
||||||
|
"""Test download URL generated."""
|
||||||
|
|
||||||
|
coresys.hassos._board = "intel-nuc"
|
||||||
|
coresys.hassos._version = AwesomeVersion("5.13")
|
||||||
|
await coresys.updater.fetch_data()
|
||||||
|
|
||||||
|
version6 = AwesomeVersion("6.0")
|
||||||
|
url = coresys.updater.ota_url.format(version=str(version6), board="generic-x86-64")
|
||||||
|
|
||||||
|
assert coresys.hassos._get_download_url(version6) == url
|
Loading…
x
Reference in New Issue
Block a user