Add support for apparmor channels (#4408)

This commit is contained in:
Mike Degatano 2023-06-27 13:12:42 -04:00 committed by GitHub
parent 3e0723ec24
commit 9fbeb2a769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -10,7 +10,7 @@ SUPERVISOR_VERSION = "99.9.9dev"
SERVER_SOFTWARE = f"HomeAssistantSupervisor/{SUPERVISOR_VERSION} aiohttp/{aiohttpversion} Python/{systemversion[0]}.{systemversion[1]}" SERVER_SOFTWARE = f"HomeAssistantSupervisor/{SUPERVISOR_VERSION} aiohttp/{aiohttpversion} Python/{systemversion[0]}.{systemversion[1]}"
URL_HASSIO_ADDONS = "https://github.com/home-assistant/addons" URL_HASSIO_ADDONS = "https://github.com/home-assistant/addons"
URL_HASSIO_APPARMOR = "https://version.home-assistant.io/apparmor.txt" URL_HASSIO_APPARMOR = "https://version.home-assistant.io/apparmor_{channel}.txt"
URL_HASSIO_VERSION = "https://version.home-assistant.io/{channel}.json" URL_HASSIO_VERSION = "https://version.home-assistant.io/{channel}.json"
SUPERVISOR_DATA = Path("/data") SUPERVISOR_DATA = Path("/data")

View File

@ -115,7 +115,7 @@ class Supervisor(CoreSysAttributes):
async def update_apparmor(self) -> None: async def update_apparmor(self) -> None:
"""Fetch last version and update profile.""" """Fetch last version and update profile."""
url = URL_HASSIO_APPARMOR url = URL_HASSIO_APPARMOR.format(channel=self.sys_updater.channel.value)
# Fetch # Fetch
try: try:

View File

@ -3,13 +3,16 @@
from datetime import timedelta from datetime import timedelta
from unittest.mock import AsyncMock, Mock, PropertyMock, patch from unittest.mock import AsyncMock, Mock, PropertyMock, patch
from aiohttp import ClientTimeout
from aiohttp.client_exceptions import ClientError from aiohttp.client_exceptions import ClientError
from awesomeversion import AwesomeVersion from awesomeversion import AwesomeVersion
import pytest import pytest
from supervisor.const import UpdateChannel
from supervisor.coresys import CoreSys from supervisor.coresys import CoreSys
from supervisor.docker.supervisor import DockerSupervisor from supervisor.docker.supervisor import DockerSupervisor
from supervisor.exceptions import DockerError, SupervisorUpdateError from supervisor.exceptions import DockerError, SupervisorUpdateError
from supervisor.host.apparmor import AppArmorControl
from supervisor.resolution.const import ContextType, IssueType from supervisor.resolution.const import ContextType, IssueType
from supervisor.resolution.data import Issue from supervisor.resolution.data import Issue
from supervisor.supervisor import Supervisor from supervisor.supervisor import Supervisor
@ -83,3 +86,25 @@ async def test_update_failed(coresys: CoreSys, capture_exception: Mock):
Issue(IssueType.UPDATE_FAILED, ContextType.SUPERVISOR) Issue(IssueType.UPDATE_FAILED, ContextType.SUPERVISOR)
in coresys.resolution.issues in coresys.resolution.issues
) )
@pytest.mark.parametrize(
"channel", [UpdateChannel.STABLE, UpdateChannel.BETA, UpdateChannel.DEV]
)
async def test_update_apparmor(
coresys: CoreSys, channel: UpdateChannel, tmp_supervisor_data
):
"""Test updating apparmor."""
coresys.updater.channel = channel
with patch("supervisor.coresys.aiohttp.ClientSession.get") as get, patch.object(
AppArmorControl, "load_profile"
) as load_profile:
get.return_value.__aenter__.return_value.status = 200
get.return_value.__aenter__.return_value.text = AsyncMock(return_value="")
await coresys.supervisor.update_apparmor()
get.assert_called_once_with(
f"https://version.home-assistant.io/apparmor_{channel.value}.txt",
timeout=ClientTimeout(total=10),
)
load_profile.assert_called_once()