diff --git a/supervisor/const.py b/supervisor/const.py index 4a5f1cbba..3b36be2a3 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -10,7 +10,7 @@ SUPERVISOR_VERSION = "99.9.9dev" SERVER_SOFTWARE = f"HomeAssistantSupervisor/{SUPERVISOR_VERSION} aiohttp/{aiohttpversion} Python/{systemversion[0]}.{systemversion[1]}" 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" SUPERVISOR_DATA = Path("/data") diff --git a/supervisor/supervisor.py b/supervisor/supervisor.py index c8c13d127..f17e43e44 100644 --- a/supervisor/supervisor.py +++ b/supervisor/supervisor.py @@ -115,7 +115,7 @@ class Supervisor(CoreSysAttributes): async def update_apparmor(self) -> None: """Fetch last version and update profile.""" - url = URL_HASSIO_APPARMOR + url = URL_HASSIO_APPARMOR.format(channel=self.sys_updater.channel.value) # Fetch try: diff --git a/tests/test_supervisor.py b/tests/test_supervisor.py index 9ff4b222e..68d8017e8 100644 --- a/tests/test_supervisor.py +++ b/tests/test_supervisor.py @@ -3,13 +3,16 @@ from datetime import timedelta from unittest.mock import AsyncMock, Mock, PropertyMock, patch +from aiohttp import ClientTimeout from aiohttp.client_exceptions import ClientError from awesomeversion import AwesomeVersion import pytest +from supervisor.const import UpdateChannel from supervisor.coresys import CoreSys from supervisor.docker.supervisor import DockerSupervisor from supervisor.exceptions import DockerError, SupervisorUpdateError +from supervisor.host.apparmor import AppArmorControl from supervisor.resolution.const import ContextType, IssueType from supervisor.resolution.data import Issue 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) 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()