1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-04-19 16:08:08 +01:00
Files
supervisor/tests/resolution/fixup/test_system_enable_ntp.py
Jan Čermák 093e98b164 Fix fallback time sync, create repair issue if time is out of sync (#6625)
* Fix fallback time sync, create repair issue if time is out of sync

The "poor man's NTP" using the whois service didn't work because it attempted
to sync the time when the NTP service was enabled, which is rejected by the
timedated service. To fix this, Supervisor now first disables the
systemd-timesyncd service and creates a repair issue before adjusting the time.
The timesyncd service stays disabled until submitting the fixup. Theoretically,
if the time moves backwards from an invalid time in the future,
systemd-timesyncd could otherwise restore the wrong time from a timestamp if we
did that after the time was set.

Also, the sync is now performed if the time is more that 1 hour off and in both
directions (previously it only intervened if it was more than 3 days in the
past).

Fixes #6015, refs #6549

* Update test_adjust_system_datetime_if_time_behind
2026-03-13 16:01:38 +01:00

33 lines
1.2 KiB
Python

"""Test fixup system enable NTP."""
from supervisor.coresys import CoreSys
from supervisor.resolution.const import ContextType, IssueType, SuggestionType
from supervisor.resolution.data import Issue, Suggestion
from supervisor.resolution.fixups.system_enable_ntp import FixupSystemEnableNTP
from tests.dbus_service_mocks.base import DBusServiceMock
from tests.dbus_service_mocks.systemd import Systemd as SystemdService
async def test_fixup(
coresys: CoreSys,
all_dbus_services: dict[str, DBusServiceMock | dict[str, DBusServiceMock]],
):
"""Test fixup."""
systemd_service: SystemdService = all_dbus_services["systemd"]
systemd_service.StartUnit.calls.clear()
system_enable_ntp = FixupSystemEnableNTP(coresys)
assert system_enable_ntp.auto is False
coresys.resolution.add_suggestion(
Suggestion(SuggestionType.ENABLE_NTP, ContextType.SYSTEM)
)
coresys.resolution.add_issue(Issue(IssueType.NTP_SYNC_FAILED, ContextType.SYSTEM))
await system_enable_ntp()
assert systemd_service.StartUnit.calls == [("systemd-timesyncd.service", "replace")]
assert len(coresys.resolution.suggestions) == 0
assert len(coresys.resolution.issues) == 0