mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-20 15:46:29 +00:00
Update supervisor before auto-updating others (#3756)
This commit is contained in:
parent
73778780ef
commit
d097044fa8
@ -20,6 +20,7 @@ class JobCondition(str, Enum):
|
|||||||
HAOS = "haos"
|
HAOS = "haos"
|
||||||
OS_AGENT = "os_agent"
|
OS_AGENT = "os_agent"
|
||||||
HOST_NETWORK = "host_network"
|
HOST_NETWORK = "host_network"
|
||||||
|
SUPERVISOR_UPDATED = "supervisor_updated"
|
||||||
|
|
||||||
|
|
||||||
class JobExecutionLimit(str, Enum):
|
class JobExecutionLimit(str, Enum):
|
||||||
|
@ -189,6 +189,14 @@ class Job(CoreSysAttributes):
|
|||||||
f"'{self._method.__qualname__}' blocked from execution, host Network Manager not available"
|
f"'{self._method.__qualname__}' blocked from execution, host Network Manager not available"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
JobCondition.SUPERVISOR_UPDATED in self.conditions
|
||||||
|
and self.sys_supervisor.need_update
|
||||||
|
):
|
||||||
|
raise JobConditionException(
|
||||||
|
f"'{self._method.__qualname__}' blocked from execution, supervisor needs to be updated first"
|
||||||
|
)
|
||||||
|
|
||||||
async def _acquire_exection_limit(self) -> None:
|
async def _acquire_exection_limit(self) -> None:
|
||||||
"""Process exection limits."""
|
"""Process exection limits."""
|
||||||
if self.limit not in (
|
if self.limit not in (
|
||||||
|
@ -88,6 +88,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
JobCondition.FREE_SPACE,
|
JobCondition.FREE_SPACE,
|
||||||
JobCondition.INTERNET_HOST,
|
JobCondition.INTERNET_HOST,
|
||||||
JobCondition.RUNNING,
|
JobCondition.RUNNING,
|
||||||
|
JobCondition.SUPERVISOR_UPDATED,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
async def _update_addons(self):
|
async def _update_addons(self):
|
||||||
@ -172,7 +173,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
finally:
|
finally:
|
||||||
self._cache[HASS_WATCHDOG_API] = 0
|
self._cache[HASS_WATCHDOG_API] = 0
|
||||||
|
|
||||||
@Job(conditions=JobCondition.RUNNING)
|
@Job(conditions=[JobCondition.RUNNING, JobCondition.SUPERVISOR_UPDATED])
|
||||||
async def _update_cli(self):
|
async def _update_cli(self):
|
||||||
"""Check and run update of cli."""
|
"""Check and run update of cli."""
|
||||||
if not self.sys_plugins.cli.need_update:
|
if not self.sys_plugins.cli.need_update:
|
||||||
@ -183,7 +184,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
await self.sys_plugins.cli.update()
|
await self.sys_plugins.cli.update()
|
||||||
|
|
||||||
@Job(conditions=JobCondition.RUNNING)
|
@Job(conditions=[JobCondition.RUNNING, JobCondition.SUPERVISOR_UPDATED])
|
||||||
async def _update_dns(self):
|
async def _update_dns(self):
|
||||||
"""Check and run update of CoreDNS plugin."""
|
"""Check and run update of CoreDNS plugin."""
|
||||||
if not self.sys_plugins.dns.need_update:
|
if not self.sys_plugins.dns.need_update:
|
||||||
@ -195,7 +196,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
await self.sys_plugins.dns.update()
|
await self.sys_plugins.dns.update()
|
||||||
|
|
||||||
@Job(conditions=JobCondition.RUNNING)
|
@Job(conditions=[JobCondition.RUNNING, JobCondition.SUPERVISOR_UPDATED])
|
||||||
async def _update_audio(self):
|
async def _update_audio(self):
|
||||||
"""Check and run update of PulseAudio plugin."""
|
"""Check and run update of PulseAudio plugin."""
|
||||||
if not self.sys_plugins.audio.need_update:
|
if not self.sys_plugins.audio.need_update:
|
||||||
@ -207,7 +208,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
await self.sys_plugins.audio.update()
|
await self.sys_plugins.audio.update()
|
||||||
|
|
||||||
@Job(conditions=JobCondition.RUNNING)
|
@Job(conditions=[JobCondition.RUNNING, JobCondition.SUPERVISOR_UPDATED])
|
||||||
async def _update_observer(self):
|
async def _update_observer(self):
|
||||||
"""Check and run update of Observer plugin."""
|
"""Check and run update of Observer plugin."""
|
||||||
if not self.sys_plugins.observer.need_update:
|
if not self.sys_plugins.observer.need_update:
|
||||||
@ -219,7 +220,7 @@ class Tasks(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
await self.sys_plugins.observer.update()
|
await self.sys_plugins.observer.update()
|
||||||
|
|
||||||
@Job(conditions=JobCondition.RUNNING)
|
@Job(conditions=[JobCondition.RUNNING, JobCondition.SUPERVISOR_UPDATED])
|
||||||
async def _update_multicast(self):
|
async def _update_multicast(self):
|
||||||
"""Check and run update of multicast."""
|
"""Check and run update of multicast."""
|
||||||
if not self.sys_plugins.multicast.need_update:
|
if not self.sys_plugins.multicast.need_update:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# pylint: disable=protected-access,import-error
|
# pylint: disable=protected-access,import-error
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import PropertyMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -355,3 +355,28 @@ async def test_exectution_limit_once(coresys: CoreSys, loop: asyncio.BaseEventLo
|
|||||||
await test.execute(0.1)
|
await test.execute(0.1)
|
||||||
|
|
||||||
await run_task
|
await run_task
|
||||||
|
|
||||||
|
|
||||||
|
async def test_supervisor_updated(coresys: CoreSys):
|
||||||
|
"""Test the supervisor updated decorator."""
|
||||||
|
|
||||||
|
class TestClass:
|
||||||
|
"""Test class."""
|
||||||
|
|
||||||
|
def __init__(self, coresys: CoreSys):
|
||||||
|
"""Initialize the test class."""
|
||||||
|
self.coresys = coresys
|
||||||
|
|
||||||
|
@Job(conditions=JobCondition.SUPERVISOR_UPDATED)
|
||||||
|
async def execute(self) -> bool:
|
||||||
|
"""Execute the class method."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
test = TestClass(coresys)
|
||||||
|
assert not coresys.supervisor.need_update
|
||||||
|
assert await test.execute()
|
||||||
|
|
||||||
|
with patch.object(
|
||||||
|
type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True)
|
||||||
|
):
|
||||||
|
assert not await test.execute()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user