77from pathlib import Path
88import stat
99from typing import Any
10- from unittest .mock import MagicMock
10+ from unittest .mock import MagicMock , patch
1111
1212from dbus_fast import DBusError , ErrorType , Variant
1313import pytest
@@ -514,18 +514,16 @@ async def test_unmount_failure(
514514 assert systemd_service .StopUnit .calls == []
515515
516516
517+ @pytest .mark .usefixtures ("tmp_supervisor_data" , "path_extern" , "mock_is_mount" )
517518async def test_reload_failure (
518- coresys : CoreSys ,
519- all_dbus_services : dict [str , DBusServiceMock ],
520- tmp_supervisor_data ,
521- path_extern ,
522- mock_is_mount ,
519+ coresys : CoreSys , all_dbus_services : dict [str , DBusServiceMock ]
523520):
524521 """Test failure to reload."""
525522 systemd_service : SystemdService = all_dbus_services ["systemd" ]
526523 systemd_unit_service : SystemdUnitService = all_dbus_services ["systemd_unit" ]
527524 systemd_service .StartTransientUnit .calls .clear ()
528525 systemd_service .ReloadOrRestartUnit .calls .clear ()
526+ systemd_service .RestartUnit .calls .clear ()
529527 systemd_service .GetUnit .calls .clear ()
530528
531529 mount = Mount .from_dict (
@@ -539,28 +537,46 @@ async def test_reload_failure(
539537 },
540538 )
541539
542- # Raise error on ReloadOrRestartUnit error
540+ # Raise error on ReloadOrRestartUnit and RestartUnit error
543541 systemd_service .response_reload_or_restart_unit = ERROR_FAILURE
542+ systemd_service .response_restart_unit = ERROR_FAILURE
544543 with pytest .raises (MountError ):
545544 await mount .reload ()
546545
547546 assert mount .state is None
548547 assert len (systemd_service .ReloadOrRestartUnit .calls ) == 1
548+ assert len (systemd_service .RestartUnit .calls ) == 1
549549 assert systemd_service .GetUnit .calls == []
550550 assert systemd_service .StartTransientUnit .calls == []
551551
552- # Raise error if state is not "active" after reload
552+ # RestartUnit if ReloadOrRestartUnit does not get it mounted
553553 systemd_service .ReloadOrRestartUnit .calls .clear ()
554+ systemd_service .RestartUnit .calls .clear ()
554555 systemd_service .response_reload_or_restart_unit = (
555556 "/org/freedesktop/systemd1/job/7623"
556557 )
558+ systemd_service .response_restart_unit = "/org/freedesktop/systemd1/job/7623"
559+ with patch ("supervisor.mounts.mount.Path.is_mount" , side_effect = [False , True ]):
560+ await mount .reload ()
561+
562+ assert mount .state == UnitActiveState .ACTIVE
563+ assert len (systemd_service .ReloadOrRestartUnit .calls ) == 1
564+ assert len (systemd_service .RestartUnit .calls ) == 1
565+ assert len (systemd_service .GetUnit .calls ) == 2
566+ assert systemd_service .StartTransientUnit .calls == []
567+
568+ # Raise error if state is not "active" after reload
569+ systemd_service .ReloadOrRestartUnit .calls .clear ()
570+ systemd_service .RestartUnit .calls .clear ()
571+ systemd_service .GetUnit .calls .clear ()
557572 systemd_unit_service .active_state = "failed"
558573 with pytest .raises (MountError ):
559574 await mount .reload ()
560575
561576 assert mount .state == UnitActiveState .FAILED
562577 assert len (systemd_service .ReloadOrRestartUnit .calls ) == 1
563- assert len (systemd_service .GetUnit .calls ) == 1
578+ assert len (systemd_service .RestartUnit .calls ) == 1
579+ assert len (systemd_service .GetUnit .calls ) == 2
564580 assert systemd_service .StartTransientUnit .calls == []
565581
566582 # If error is NoSuchUnit then don't raise just mount instead as its not mounted
0 commit comments