Skip to content

Commit 27b092a

Browse files
agnerssairon
andauthored
Block OS updates when the system is unhealthy (#6053)
* Block OS updates when the system is unhealthy In #6024 we mark a system as unhealthy when multiple OS installations were found. The idea was to block OS updates in this case. However, it turns out that the OS update job was not checking the system health and thus allowed updates even when the system was marked as unhealthy. This commit adds the `JobCondition.HEALTHY` condition to the OS update job, ensuring that OS updates are only performed when the system is healthy. Users can force an OS update still by using `ha jobs options --ignore-conditions healthy`. * Add test for update of unhealthy system --------- Co-authored-by: Jan Čermák <[email protected]>
1 parent 3af13cb commit 27b092a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

supervisor/os/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ async def config_sync(self) -> None:
272272
name="os_manager_update",
273273
conditions=[
274274
JobCondition.HAOS,
275+
JobCondition.HEALTHY,
275276
JobCondition.INTERNET_SYSTEM,
276277
JobCondition.RUNNING,
277278
JobCondition.SUPERVISOR_UPDATED,

tests/os/test_manager.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from supervisor.const import CoreState
1010
from supervisor.coresys import CoreSys
1111
from supervisor.exceptions import HassOSJobError
12+
from supervisor.resolution.const import UnhealthyReason
1213

1314
from tests.common import MockResponse
1415
from tests.dbus_service_mocks.base import DBusServiceMock
@@ -85,6 +86,21 @@ async def test_update_fails_if_out_of_date(
8586
await coresys.os.update()
8687

8788

89+
async def test_update_fails_if_unhealthy(
90+
coresys: CoreSys,
91+
) -> None:
92+
"""Test update of OS fails if Supervisor is unhealthy."""
93+
await coresys.core.set_state(CoreState.RUNNING)
94+
coresys.resolution.add_unhealthy_reason(UnhealthyReason.DUPLICATE_OS_INSTALLATION)
95+
with (
96+
patch.object(
97+
type(coresys.os), "available", new=PropertyMock(return_value=True)
98+
),
99+
pytest.raises(HassOSJobError),
100+
):
101+
await coresys.os.update()
102+
103+
88104
async def test_board_name_supervised(coresys: CoreSys) -> None:
89105
"""Test board name is supervised when not on haos."""
90106
with patch("supervisor.os.manager.CPE.get_product", return_value=["not-hassos"]):

0 commit comments

Comments
 (0)