示例#1
0
async def test_start_on_boot(ha: HaSource, time,
                             interceptor: RequestInterceptor, config: Config,
                             supervisor: SimulatedSupervisor) -> None:
    boot_slug = "boot_slug"
    supervisor.installAddon(boot_slug,
                            "Start on boot",
                            boot=True,
                            started=False)

    no_boot_slug = "no_boot_slug"
    supervisor.installAddon(no_boot_slug,
                            "Don't start on boot",
                            boot=False,
                            started=False)
    config.override(Setting.STOP_ADDONS, ",".join([boot_slug, no_boot_slug]))
    config.override(Setting.NEW_SNAPSHOT_TIMEOUT_SECONDS, 0.001)

    assert supervisor.addon(boot_slug)["state"] == "stopped"
    assert supervisor.addon(no_boot_slug)["state"] == "stopped"
    async with supervisor._snapshot_inner_lock:
        await ha.create(CreateOptions(time.now(), "Test Name"))
        assert supervisor.addon(boot_slug)["state"] == "stopped"
    assert supervisor.addon(no_boot_slug)["state"] == "stopped"
    await ha._pending_snapshot_task
    assert supervisor.addon(boot_slug)["state"] == "started"
    assert supervisor.addon(no_boot_slug)["state"] == "stopped"
    assert len(await ha.get()) == 1
    assert not interceptor.urlWasCalled(URL_MATCH_START_ADDON)
    assert not interceptor.urlWasCalled(URL_MATCH_STOP_ADDON)
示例#2
0
async def test_notification_link(updater: HaUpdater, server, time: FakeTime, global_info, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(supervisor, "binary_sensor.backups_stale",
                 "off", STALE_ATTRIBUTES)
    verifyEntity(supervisor, "sensor.backup_state", "waiting", {
        'friendly_name': 'Backup State',
        'last_backup': 'Never',
        'last_uploaded': 'Never',
        'backups': [],
        'backups_in_google_drive': 0,
        'backups_in_home_assistant': 0,
        'size_in_home_assistant': "0.0 B",
        'size_in_google_drive': "0.0 B"
    })
    assert supervisor.getNotification() is None

    global_info.failed(Exception())
    global_info.url = "http://localhost/test"
    time.advanceDay()
    await updater.update()
    assert supervisor.getNotification() == {
        'message': 'The add-on is having trouble making backups and needs attention.  Please visit the add-on [status page](http://localhost/test) for details.',
        'title': 'Home Assistant Google Drive Backup is Having Trouble',
        'notification_id': 'backup_broken'
    }
async def test_delayed_start(supervisor: SimulatedSupervisor,
                             addon_stopper: AddonStopper, config: Config,
                             interceptor: RequestInterceptor,
                             time: FakeTime) -> None:
    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"
    assert getSaved(config) == ({slug1}, set())

    # start the addon again, which simluates the supervisor's tendency to report an addon as started right after stopping it.
    supervisor.addon(slug1)["state"] = "started"
    await addon_stopper.check()
    await addon_stopper.startAddons()
    assert getSaved(config) == ({slug1}, set())

    time.advance(seconds=30)
    await addon_stopper.check()
    assert getSaved(config) == ({slug1}, set())

    time.advance(seconds=30)
    await addon_stopper.check()
    assert getSaved(config) == ({slug1}, set())

    time.advance(seconds=30)
    supervisor.addon(slug1)["state"] = "stopped"
    await addon_stopper.check()
    assert supervisor.addon(slug1)["state"] == "started"
    assert getSaved(config) == (set(), set())
async def test_pending_snapshot_nowait(ha: HaSource, time,
                                       supervisor: SimulatedSupervisor,
                                       interceptor: RequestInterceptor,
                                       config: Config):
    interceptor.setSleep(URL_MATCH_SNAPSHOT_FULL, sleep=5)
    config.override(Setting.NEW_SNAPSHOT_TIMEOUT_SECONDS, 0.1)
    snapshot_immediate: PendingSnapshot = await ha.create(
        CreateOptions(time.now(), "Test Name"))
    assert isinstance(snapshot_immediate, PendingSnapshot)
    snapshot_pending: HASnapshot = (await ha.get())['pending']

    assert isinstance(snapshot_immediate, PendingSnapshot)
    assert isinstance(snapshot_pending, PendingSnapshot)
    assert snapshot_immediate is snapshot_pending
    assert snapshot_immediate.name() == "Test Name"
    assert snapshot_immediate.slug() == "pending"
    assert not snapshot_immediate.uploadable()
    assert snapshot_immediate.snapshotType() == "Full"
    assert snapshot_immediate.source() == SOURCE_HA
    assert snapshot_immediate.date() == time.now()
    assert not snapshot_immediate.protected()

    # Might be a little flaky but...whatever
    await asyncio.wait({ha._pending_snapshot_task})

    snapshots = await ha.get()
    assert 'pending' not in snapshots
    assert isinstance(next(iter(snapshots.values())), HASnapshot)

    return
    # ignroe events for now
    assert supervisor.getEvents() == [(EVENT_SNAPSHOT_START, {
        'snapshot_name':
        snapshot_immediate.name(),
        'snapshot_time':
        str(snapshot_immediate.date())
    })]
    ha.snapshot_thread.join()
    assert supervisor.getEvents() == [(EVENT_SNAPSHOT_START, {
        'snapshot_name':
        snapshot_immediate.name(),
        'snapshot_time':
        str(snapshot_immediate.date())
    }),
                                      (EVENT_SNAPSHOT_END, {
                                          'completed':
                                          True,
                                          'snapshot_name':
                                          snapshot_immediate.name(),
                                          'snapshot_time':
                                          str(snapshot_immediate.date())
                                      })]
async def test_no_stop_config(supervisor: SimulatedSupervisor,
                              addon_stopper: AddonStopper,
                              config: Config) -> None:
    slug = "test_slug_1"
    supervisor.installAddon(slug, "Test decription")
    addon_stopper.allowRun()
    addon_stopper.isSnapshotting(False)
    assert supervisor.addon(slug)["state"] == "started"
    await addon_stopper.stopAddons("ignore")
    assert supervisor.addon(slug)["state"] == "started"
    await addon_stopper.check()
    await addon_stopper.startAddons()
    assert supervisor.addon(slug)["state"] == "started"
示例#6
0
async def test_notification_clears(updater: HaUpdater, server, time: FakeTime, global_info, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    assert supervisor.getNotification() is None

    global_info.failed(Exception())
    time.advanceDay()
    await updater.update()
    assert supervisor.getNotification() is not None

    global_info.success()
    await updater.update()
    assert supervisor.getNotification() is None
示例#7
0
async def test_start_and_stop_addon(ha: HaSource, time,
                                    interceptor: RequestInterceptor,
                                    config: Config,
                                    supervisor: SimulatedSupervisor) -> None:
    slug = "test_slug"
    supervisor.installAddon(slug, "Test decription")
    config.override(Setting.STOP_ADDONS, slug)
    config.override(Setting.NEW_SNAPSHOT_TIMEOUT_SECONDS, 0.001)

    assert supervisor.addon(slug)["state"] == "started"
    async with supervisor._snapshot_inner_lock:
        await ha.create(CreateOptions(time.now(), "Test Name"))
        assert supervisor.addon(slug)["state"] == "stopped"
    await ha._pending_snapshot_task
    assert supervisor.addon(slug)["state"] == "started"
async def test_upgrade_no_config(ha: HaSource, supervisor: SimulatedSupervisor,
                                 interceptor: RequestInterceptor,
                                 config: Config, server_url):
    """Verifies that config not in need of an upgrade doesn't get upgraded"""

    # overwrite the addon options with old values
    supervisor._options = {
        Setting.MAX_BACKUPS_IN_HA.value: 4,
        Setting.MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 4,
        Setting.DAYS_BETWEEN_BACKUPS.value: 3,
        Setting.BACKUP_TIME_OF_DAY.value: "01:11",
        Setting.EXCLUDE_ADDONS.value: "test"
    }

    await ha.init()

    assert not config.mustSaveUpgradeChanges()
    assert not interceptor.urlWasCalled(URL_MATCH_SELF_OPTIONS)

    # Verify the config was upgraded
    assert supervisor._options == {
        Setting.MAX_BACKUPS_IN_HA.value: 4,
        Setting.MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 4,
        Setting.DAYS_BETWEEN_BACKUPS.value: 3,
        Setting.BACKUP_TIME_OF_DAY.value: "01:11",
        Setting.EXCLUDE_ADDONS.value: "test",
    }
async def test_upgrade_some_config(ha: HaSource,
                                   supervisor: SimulatedSupervisor,
                                   interceptor: RequestInterceptor,
                                   config: Config, server_url):
    """Verify that converting a mix of upgradeable and not upgradeable config works"""

    # overwrite the addon options with old values
    supervisor._options = {
        Setting.DEPRECTAED_MAX_BACKUPS_IN_HA.value: 4,
        Setting.DEPRECTAED_MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 4,
        Setting.DEPRECATED_DAYS_BETWEEN_BACKUPS.value: 3,
        Setting.DEPRECTAED_BACKUP_TIME_OF_DAY.value: "01:11",
        Setting.EXCLUDE_ADDONS.value: "test",
        Setting.USE_SSL.value: False,
    }

    await ha.init()

    assert not config.mustSaveUpgradeChanges()
    assert interceptor.urlWasCalled(URL_MATCH_SELF_OPTIONS)

    # Verify the config was upgraded
    assert supervisor._options == {
        Setting.MAX_BACKUPS_IN_HA.value: 4,
        Setting.MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 4,
        Setting.DAYS_BETWEEN_BACKUPS.value: 3,
        Setting.EXCLUDE_ADDONS.value: "test",
        Setting.BACKUP_TIME_OF_DAY.value: "01:11",
        Setting.CALL_BACKUP_SNAPSHOT.value: True,
    }
async def test_upgrade_default_config(ha: HaSource,
                                      supervisor: SimulatedSupervisor,
                                      interceptor: RequestInterceptor,
                                      config: Config, server_url):
    """Verify that converting the original default config optiosn works as expected"""

    # overwrite the addon options with old values
    supervisor._options = {
        Setting.DEPRECTAED_MAX_BACKUPS_IN_HA.value: 4,
        Setting.DEPRECTAED_MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 4,
        Setting.DEPRECATED_DAYS_BETWEEN_BACKUPS.value: 3,
        Setting.USE_SSL.value: False,
    }

    await ha.init()

    assert not config.mustSaveUpgradeChanges()
    assert interceptor.urlWasCalled(URL_MATCH_SELF_OPTIONS)

    # Verify the config was upgraded
    assert supervisor._options == {
        Setting.MAX_BACKUPS_IN_HA.value: 4,
        Setting.MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 4,
        Setting.DAYS_BETWEEN_BACKUPS.value: 3,
        Setting.CALL_BACKUP_SNAPSHOT.value: True,
    }
async def test_backup_supervisor_path(ha: HaSource,
                                      supervisor: SimulatedSupervisor,
                                      interceptor: RequestInterceptor):
    supervisor._super_version = Version(2021, 7)
    await ha.get()
    assert not interceptor.urlWasCalled(URL_MATCH_BACKUPS)
    assert interceptor.urlWasCalled(URL_MATCH_SNAPSHOT)
async def test_snapshot_to_backup_upgrade_use_old_values(
        reader: ReaderHelper, time: FakeTime, coord: Coordinator,
        config: Config, supervisor: SimulatedSupervisor, ha: HaSource,
        drive: DriveSource, data_cache: DataCache, updater: HaUpdater):
    """ Test the path where a user upgrades from the addon before the backup rename and then chooses to use the old names"""
    status = await reader.getjson("getstatus")
    assert not status["warn_backup_upgrade"]

    # simulate upgrading config
    supervisor._options = {Setting.DEPRECTAED_MAX_BACKUPS_IN_HA.value: 7}
    await coord.sync()
    assert Setting.CALL_BACKUP_SNAPSHOT.value in supervisor._options
    assert config.get(Setting.CALL_BACKUP_SNAPSHOT)

    status = await reader.getjson("getstatus")
    assert status["warn_backup_upgrade"]
    assert not data_cache.checkFlag(UpgradeFlags.NOTIFIED_ABOUT_BACKUP_RENAME)
    assert not updater._trigger_once

    # simulate user clicking the button to use new names
    assert await reader.getjson("callbackupsnapshot?switch=false") == {
        'message': 'Configuration updated'
    }
    assert data_cache.checkFlag(UpgradeFlags.NOTIFIED_ABOUT_BACKUP_RENAME)
    status = await reader.getjson("getstatus")
    assert not status["warn_backup_upgrade"]
    assert config.get(Setting.CALL_BACKUP_SNAPSHOT)
示例#13
0
async def test_ingore_self_when_stopping(
        ha: HaSource, time, interceptor: RequestInterceptor, config: Config,
        supervisor: SimulatedSupervisor) -> None:
    slug = supervisor._addon_slug
    config.override(Setting.STOP_ADDONS, slug)
    config.override(Setting.NEW_SNAPSHOT_TIMEOUT_SECONDS, 0.001)
    interceptor.setError(URL_MATCH_START_ADDON, 400)

    assert supervisor.addon(slug)["state"] == "started"
    async with supervisor._snapshot_inner_lock:
        await ha.create(CreateOptions(time.now(), "Test Name"))
        assert supervisor.addon(slug)["state"] == "started"
    await ha._pending_snapshot_task
    assert supervisor.addon(slug)["state"] == "started"
    assert not interceptor.urlWasCalled(URL_MATCH_START_ADDON)
    assert not interceptor.urlWasCalled(URL_MATCH_STOP_ADDON)
    assert len(await ha.get()) == 1
示例#14
0
async def test_publish_for_failure(updater: HaUpdater, server, time: FakeTime, global_info: GlobalInfo, supervisor: SimulatedSupervisor):
    global_info.success()
    await updater.update()
    assert supervisor.getNotification() is None

    time.advanceDay()
    global_info.failed(Exception())
    await updater.update()
    assert supervisor.getNotification() is not None

    time.advanceDay()
    global_info.failed(Exception())
    await updater.update()
    assert supervisor.getNotification() is not None

    global_info.success()
    await updater.update()
    assert supervisor.getNotification() is None
async def test_enable_watchdog_on_reboot(supervisor: SimulatedSupervisor,
                                         addon_stopper: AddonStopper,
                                         config: Config,
                                         time: FakeTime) -> None:
    slug1 = "test_slug_1"
    supervisor.installAddon(slug1, "Test decription")
    config.override(Setting.STOP_ADDONS, ",".join([slug1]))
    supervisor.addon(slug1)["watchdog"] = False
    save(config, set(), {slug1})

    await addon_stopper.start(False)
    addon_stopper.allowRun()
    assert addon_stopper.must_enable_watchdog == {slug1}

    time.advance(minutes=5)
    await addon_stopper.check()
    assert supervisor.addon(slug1)["watchdog"] is True
    assert getSaved(config) == (set(), set())
async def test_do_nothing_while_snapshotting(
        supervisor: SimulatedSupervisor, addon_stopper: AddonStopper,
        config: Config, interceptor: RequestInterceptor) -> None:
    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]))

    await addon_stopper.start(False)
    addon_stopper.allowRun()
    addon_stopper.isSnapshotting(True)
    assert addon_stopper.must_start == {slug1, slug2}

    await addon_stopper.check()

    assert not interceptor.urlWasCalled(URL_MATCH_START_ADDON)
    assert not interceptor.urlWasCalled(URL_MATCH_STOP_ADDON)
async def test_get_info_failure_on_stop(
        supervisor: SimulatedSupervisor, addon_stopper: AddonStopper,
        config: Config, interceptor: RequestInterceptor) -> None:
    slug1 = "test_slug_1"
    supervisor.installAddon(slug1, "Test decription")
    config.override(Setting.STOP_ADDONS, slug1)
    addon_stopper.allowRun()
    addon_stopper.must_start = set()
    assert supervisor.addon(slug1)["state"] == "started"
    interceptor.setError(URL_MATCH_ADDON_INFO, 400)

    await addon_stopper.stopAddons("ignore")
    assert interceptor.urlWasCalled(URL_MATCH_ADDON_INFO)
    assert getSaved(config) == (set(), set())
    assert supervisor.addon(slug1)["state"] == "started"
    await addon_stopper.check()
    await addon_stopper.startAddons()
    assert supervisor.addon(slug1)["state"] == "started"
    assert getSaved(config) == (set(), set())
async def test_start_addon_failure(ha: HaSource, time,
                                   interceptor: RequestInterceptor,
                                   config: Config,
                                   supervisor: SimulatedSupervisor,
                                   addon_stopper: AddonStopper) -> None:
    addon_stopper.allowRun()
    slug = "test_slug"
    supervisor.installAddon(slug, "Test decription")
    config.override(Setting.STOP_ADDONS, slug)
    config.override(Setting.NEW_SNAPSHOT_TIMEOUT_SECONDS, 0.001)
    interceptor.setError(URL_MATCH_START_ADDON, 400)

    assert supervisor.addon(slug)["state"] == "started"
    async with supervisor._snapshot_inner_lock:
        await ha.create(CreateOptions(time.now(), "Test Name"))
        assert supervisor.addon(slug)["state"] == "stopped"
    await ha._pending_snapshot_task
    assert supervisor.addon(slug)["state"] == "stopped"
    assert len(await ha.get()) == 1
示例#19
0
async def test_init_failure(updater: HaUpdater, global_info: GlobalInfo, time: FakeTime, server, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"

    global_info.failed(Exception())
    assert not updater._stale()
    assert updater._state() == "backed_up"
    assert supervisor.getNotification() is None

    time.advanceDay()
    assert updater._stale()
    assert updater._state() == "error"
    await updater.update()
    assert supervisor.getNotification() == {
        'message': 'The add-on is having trouble making backups and needs attention.  Please visit the add-on status page for details.',
        'title': 'Home Assistant Google Drive Backup is Having Trouble',
        'notification_id': 'backup_broken'
    }
示例#20
0
async def test_ignored_backups(updater: HaUpdater, time: FakeTime, server: SimulationServer, backup: Backup, supervisor: SimulatedSupervisor, coord: Coordinator, config: Config):
    config.override(Setting.IGNORE_OTHER_BACKUPS, True)
    time.advance(hours=1)
    await supervisor.createBackup({'name': "test_backup"}, date=time.now())
    await coord.sync()
    await updater.update()
    state = supervisor.getAttributes("sensor.backup_state")
    assert state["backups_in_google_drive"] == 1
    assert state["backups_in_home_assistant"] == 1
    assert len(state["backups"]) == 1
    assert state['last_backup'] == backup.date().isoformat()
示例#21
0
async def test_publish_retries(updater: HaUpdater, server: SimulationServer, time: FakeTime, backup, drive, supervisor: SimulatedSupervisor):
    await updater.update()
    assert supervisor.getEntity("sensor.backup_state") is not None

    # Shoudlnt update after 59 minutes
    supervisor.clearEntities()
    time.advance(minutes=59)
    await updater.update()
    assert supervisor.getEntity("sensor.backup_state") is None

    # after that it should
    supervisor.clearEntities()
    time.advance(minutes=2)
    await updater.update()
    assert supervisor.getEntity("sensor.backup_state") is not None

    supervisor.clearEntities()
    await drive.delete(backup)
    await updater.update()
    assert supervisor.getEntity("sensor.backup_state") is not None
async def test_read_only_fs(supervisor: SimulatedSupervisor,
                            addon_stopper: AddonStopper, config: Config,
                            interceptor: RequestInterceptor) -> None:
    # 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_old_delete_path(ha: HaSource, supervisor: SimulatedSupervisor,
                               interceptor: RequestInterceptor,
                               time: FakeTime):
    supervisor._super_version = Version(2020, 8)
    await ha.get()
    backup: HABackup = await ha.create(CreateOptions(time.now(), "Test Name"))
    full = DummyBackup(backup.name(), backup.date(), backup.size(),
                       backup.slug(), "dummy")
    full.addSource(backup)
    await ha.delete(full)
    assert interceptor.urlWasCalled("/snapshots/{0}/remove".format(
        backup.slug()))
async def test_ignored_snapshots(updater: HaUpdater, time: Time,
                                 server: SimulationServer, snapshot,
                                 supervisor: SimulatedSupervisor,
                                 coord: Coordinator, config: Config):
    config.override(Setting.IGNORE_OTHER_SNAPSHOTS, True)
    await supervisor.createSnapshot({'name': "test_snapshot"}, date=time.now())
    await coord.sync()
    await updater.update()
    state = supervisor.getAttributes("sensor.snapshot_backup")
    assert state["snapshots_in_google_drive"] == 1
    assert state["snapshots_in_home_assistant"] == 1
    assert len(state["snapshots"]) == 2
async def test_upgrade_all_config(ha: HaSource,
                                  supervisor: SimulatedSupervisor,
                                  interceptor: RequestInterceptor,
                                  config: Config, server_url):
    """Verify that converting all upgradeable config optiosn works as expected"""

    # overwrite the addon options with old values
    supervisor._options = {
        Setting.DEPRECTAED_MAX_BACKUPS_IN_HA.value: 1,
        Setting.DEPRECTAED_MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 2,
        Setting.DEPRECATED_DAYS_BETWEEN_BACKUPS.value: 5,
        Setting.DEPRECTAED_IGNORE_OTHER_BACKUPS.value: True,
        Setting.DEPRECTAED_IGNORE_UPGRADE_BACKUPS.value: True,
        Setting.DEPRECTAED_BACKUP_TIME_OF_DAY.value: "01:11",
        Setting.DEPRECTAED_DELETE_BEFORE_NEW_BACKUP.value: True,
        Setting.DEPRECTAED_BACKUP_NAME.value: "test",
        Setting.DEPRECTAED_SPECIFY_BACKUP_FOLDER.value: True,
        Setting.DEPRECTAED_NOTIFY_FOR_STALE_BACKUPS.value: False,
        Setting.DEPRECTAED_ENABLE_BACKUP_STALE_SENSOR.value: False,
        Setting.DEPRECTAED_ENABLE_BACKUP_STATE_SENSOR.value: False,
        Setting.DEPRECATED_BACKUP_PASSWORD.value: "test password",
    }

    await ha.init()
    assert not config.mustSaveUpgradeChanges()
    assert interceptor.urlWasCalled(URL_MATCH_SELF_OPTIONS)

    # Verify the config was upgraded
    assert supervisor._options == {
        Setting.MAX_BACKUPS_IN_HA.value: 1,
        Setting.MAX_BACKUPS_IN_GOOGLE_DRIVE.value: 2,
        Setting.DAYS_BETWEEN_BACKUPS.value: 5,
        Setting.IGNORE_OTHER_BACKUPS.value: True,
        Setting.IGNORE_UPGRADE_BACKUPS.value: True,
        Setting.BACKUP_TIME_OF_DAY.value: "01:11",
        Setting.DELETE_BEFORE_NEW_BACKUP.value: True,
        Setting.BACKUP_NAME.value: "test",
        Setting.SPECIFY_BACKUP_FOLDER.value: True,
        Setting.NOTIFY_FOR_STALE_BACKUPS.value: False,
        Setting.ENABLE_BACKUP_STALE_SENSOR.value: False,
        Setting.ENABLE_BACKUP_STATE_SENSOR.value: False,
        Setting.BACKUP_PASSWORD.value: "test password",
        Setting.CALL_BACKUP_SNAPSHOT.value: True,
    }

    interceptor.clear()

    await ha.init()
    assert not interceptor.urlWasCalled(URL_MATCH_SELF_OPTIONS)
async def test_snapshot_to_backup_upgrade_avoid_default_overwrite(
        reader: ReaderHelper, time: FakeTime, coord: Coordinator,
        config: Config, supervisor: SimulatedSupervisor, ha: HaSource,
        drive: DriveSource, data_cache: DataCache, updater: HaUpdater):
    """ Test the path where a user upgrades from the addon but a new value with a default value gets overwritten"""
    status = await reader.getjson("getstatus")
    assert not status["warn_backup_upgrade"]

    # simulate upgrading config
    supervisor._options = {
        Setting.DEPRECTAED_MAX_BACKUPS_IN_HA.value: 7,
        Setting.MAX_BACKUPS_IN_HA.value: 4  # defuault, should get overridden
    }
    await coord.sync()
    assert Setting.CALL_BACKUP_SNAPSHOT.value in supervisor._options
    assert config.get(Setting.CALL_BACKUP_SNAPSHOT)
    assert config.get(Setting.MAX_BACKUPS_IN_HA) == 7
async def test_enable_watchdog_waits_for_start(supervisor: SimulatedSupervisor,
                                               addon_stopper: AddonStopper,
                                               config: Config) -> None:
    slug1 = "test_slug_1"
    supervisor.installAddon(slug1, "Test decription")
    config.override(Setting.STOP_ADDONS, ",".join([slug1]))
    supervisor.addon(slug1)["watchdog"] = False
    save(config, {slug1}, {slug1})

    await addon_stopper.start(False)
    addon_stopper.allowRun()
    assert addon_stopper.must_enable_watchdog == {slug1}

    await addon_stopper.check()
    assert getSaved(config) == ({slug1}, {slug1})

    supervisor.addon(slug1)["state"] = "stopped"
    await addon_stopper.check()
    assert supervisor.addon(slug1)["state"] == "started"
    assert supervisor.addon(slug1)["watchdog"] is True
    assert getSaved(config) == (set(), set())
示例#28
0
async def test_init(updater: HaUpdater, global_info, supervisor: SimulatedSupervisor, server):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(supervisor, "binary_sensor.backups_stale",
                 "off", STALE_ATTRIBUTES)
    verifyEntity(supervisor, "sensor.backup_state", "waiting", {
        'friendly_name': 'Backup State',
        'last_backup': 'Never',
        'last_uploaded': 'Never',
        'backups': [],
        'backups_in_google_drive': 0,
        'backups_in_home_assistant': 0,
        'size_in_google_drive': "0.0 B",
        'size_in_home_assistant': '0.0 B'
    })
    assert supervisor.getNotification() is None

    global_info.success()
    assert not updater._stale()
    assert updater._state() == "backed_up"
async def test_start_and_stop(supervisor: SimulatedSupervisor,
                              addon_stopper: AddonStopper,
                              config: Config) -> None:
    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 supervisor.addon(slug1)["state"] == "stopped"
    await addon_stopper.startAddons()
    assert supervisor.addon(slug1)["state"] == "started"
    assert getSaved(config) == (set(), set())
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"