1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 12:29:08 +00:00

Add issues/suggestion to resolution center / start with diskspace (#2125)

Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
This commit is contained in:
Joakim Sørensen
2020-10-14 17:14:25 +02:00
committed by GitHub
parent d599c3ad76
commit 02e72726a5
13 changed files with 375 additions and 27 deletions

View File

@@ -1,13 +1,47 @@
"""Test Resolution API."""
from unittest.mock import MagicMock, patch
import pytest
from supervisor.const import ATTR_UNSUPPORTED, UnsupportedReason
from supervisor.const import ATTR_ISSUES, ATTR_SUGGESTIONS, ATTR_UNSUPPORTED
from supervisor.coresys import CoreSys
from supervisor.resolution.const import IssueType, Suggestion, UnsupportedReason
@pytest.mark.asyncio
async def test_api_resolution_base(coresys, api_client):
async def test_api_resolution_base(coresys: CoreSys, api_client):
"""Test resolution manager api."""
coresys.resolution.unsupported = UnsupportedReason.OS
coresys.resolution.suggestions = Suggestion.CLEAR_FULL_SNAPSHOT
coresys.resolution.issues = IssueType.FREE_SPACE
resp = await api_client.get("/resolution")
result = await resp.json()
assert UnsupportedReason.OS in result["data"][ATTR_UNSUPPORTED]
assert Suggestion.CLEAR_FULL_SNAPSHOT in result["data"][ATTR_SUGGESTIONS]
assert IssueType.FREE_SPACE in result["data"][ATTR_ISSUES]
@pytest.mark.asyncio
async def test_api_resolution_dismiss_suggestion(coresys: CoreSys, api_client):
"""Test resolution manager suggestion apply api."""
coresys.resolution.suggestions = Suggestion.CLEAR_FULL_SNAPSHOT
assert Suggestion.CLEAR_FULL_SNAPSHOT in coresys.resolution.suggestions
await coresys.resolution.dismiss_suggestion(Suggestion.CLEAR_FULL_SNAPSHOT)
assert Suggestion.CLEAR_FULL_SNAPSHOT not in coresys.resolution.suggestions
@pytest.mark.asyncio
async def test_api_resolution_apply_suggestion(coresys: CoreSys, api_client):
"""Test resolution manager suggestion apply api."""
coresys.resolution.suggestions = Suggestion.CLEAR_FULL_SNAPSHOT
coresys.resolution.suggestions = Suggestion.CREATE_FULL_SNAPSHOT
with patch("supervisor.snapshots.SnapshotManager", return_value=MagicMock()):
await coresys.resolution.apply_suggestion(Suggestion.CLEAR_FULL_SNAPSHOT)
await coresys.resolution.apply_suggestion(Suggestion.CREATE_FULL_SNAPSHOT)
assert Suggestion.CLEAR_FULL_SNAPSHOT not in coresys.resolution.suggestions
assert Suggestion.CREATE_FULL_SNAPSHOT not in coresys.resolution.suggestions
await coresys.resolution.apply_suggestion(Suggestion.CLEAR_FULL_SNAPSHOT)

View File

@@ -4,9 +4,10 @@ from unittest.mock import patch
import pytest
from supervisor.const import SUPERVISOR_VERSION, CoreState, UnsupportedReason
from supervisor.const import SUPERVISOR_VERSION, CoreState
from supervisor.exceptions import AddonConfigurationError
from supervisor.misc.filter import filter_data
from supervisor.resolution.const import UnsupportedReason
SAMPLE_EVENT = {"sample": "event", "extra": {"Test": "123"}}

View File

@@ -1,8 +1,18 @@
"""Tests for resolution manager."""
from pathlib import Path
from supervisor.const import UnsupportedReason
from supervisor.const import (
ATTR_DATE,
ATTR_SLUG,
ATTR_TYPE,
SNAPSHOT_FULL,
SNAPSHOT_PARTIAL,
)
from supervisor.coresys import CoreSys
from supervisor.resolution.const import UnsupportedReason
from supervisor.snapshots.snapshot import Snapshot
from supervisor.utils.dt import utcnow
from supervisor.utils.tar import SecureTarFile
def test_properies(coresys: CoreSys):
@@ -12,3 +22,39 @@ def test_properies(coresys: CoreSys):
coresys.resolution.unsupported = UnsupportedReason.OS
assert not coresys.core.supported
async def test_clear_snapshots(coresys: CoreSys, tmp_path):
"""Test snapshot cleanup."""
for slug in ["sn1", "sn2", "sn3", "sn4", "sn5"]:
temp_tar = Path(tmp_path, f"{slug}.tar")
with SecureTarFile(temp_tar, "w"):
pass
snapshot = Snapshot(coresys, temp_tar)
snapshot._data = { # pylint: disable=protected-access
ATTR_SLUG: slug,
ATTR_DATE: utcnow().isoformat(),
ATTR_TYPE: SNAPSHOT_PARTIAL
if "1" in slug or "5" in slug
else SNAPSHOT_FULL,
}
coresys.snapshots.snapshots_obj[snapshot.slug] = snapshot
newest_full_snapshot = coresys.snapshots.snapshots_obj["sn4"]
assert newest_full_snapshot in coresys.snapshots.list_snapshots
assert (
len(
[x for x in coresys.snapshots.list_snapshots if x.sys_type == SNAPSHOT_FULL]
)
== 3
)
coresys.resolution.storage.clean_full_snapshots()
assert newest_full_snapshot in coresys.snapshots.list_snapshots
assert (
len(
[x for x in coresys.snapshots.list_snapshots if x.sys_type == SNAPSHOT_FULL]
)
== 1
)