async def test_start_and_stop_two_addons(ha: HaSource, time, interceptor: RequestInterceptor, config: Config, supervisor: SimulatedSupervisor, addon_stopper: AddonStopper) -> None: addon_stopper.allowRun() slug1 = "test_slug_1" supervisor.installAddon(slug1, "Test decription") slug2 = "test_slug_2" supervisor.installAddon(slug2, "Test decription") config.override(Setting.STOP_ADDONS, ",".join([slug1, slug2])) config.override(Setting.NEW_SNAPSHOT_TIMEOUT_SECONDS, 0.001) assert supervisor.addon(slug1)["state"] == "started" assert supervisor.addon(slug2)["state"] == "started" async with supervisor._snapshot_inner_lock: await ha.create(CreateOptions(time.now(), "Test Name")) assert supervisor.addon(slug1)["state"] == "stopped" assert supervisor.addon(slug2)["state"] == "stopped" await ha._pending_snapshot_task assert supervisor.addon(slug1)["state"] == "started" assert supervisor.addon(slug2)["state"] == "started"
async def test_read_only_fs(supervisor: SimulatedSupervisor, addon_stopper: AddonStopper, config: Config, interceptor: RequestInterceptor) -> None: # This test can't be run as the root user, since no file is read-only to root. skipForRoot() # Stop an addon slug1 = "test_slug_1" supervisor.installAddon(slug1, "Test decription") config.override(Setting.STOP_ADDONS, ",".join([slug1])) addon_stopper.allowRun() addon_stopper.must_start = set() assert supervisor.addon(slug1)["state"] == "started" await addon_stopper.stopAddons("ignore") assert supervisor.addon(slug1)["state"] == "stopped" await addon_stopper.check() assert getSaved(config) == ({slug1}, set()) # make the state file unmodifiable os.chmod(config.get(Setting.STOP_ADDON_STATE_PATH), S_IREAD) # verify we raise a known error when trying to save. with pytest.raises(SupervisorFileSystemError): await addon_stopper.startAddons()
async def test_load_addons_on_boot(supervisor: SimulatedSupervisor, addon_stopper: AddonStopper, config: Config) -> None: slug1 = "test_slug_1" supervisor.installAddon(slug1, "Test decription") slug2 = "test_slug_2" supervisor.installAddon(slug2, "Test decription") slug3 = "test_slug_3" supervisor.installAddon(slug3, "Test decription") config.override(Setting.STOP_ADDONS, slug1) save(config, {slug3}, {slug2}) await addon_stopper.start(False) assert addon_stopper.must_start == {slug3} assert addon_stopper.must_enable_watchdog == {slug2} addon_stopper.allowRun() assert addon_stopper.must_start == {slug1, slug3} assert addon_stopper.must_enable_watchdog == {slug2}