mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-08 02:19:35 +00:00
Use backup mounts (#4289)
* Add support for backup mounts * Fix tests * Allow backups to local when there's a default location
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
"""Test backups API."""
|
||||
|
||||
from pathlib import Path, PurePath
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
import pytest
|
||||
|
||||
from supervisor.backups.backup import Backup
|
||||
from supervisor.const import CoreState
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.mounts.mount import Mount
|
||||
|
||||
|
||||
async def test_info(api_client, coresys: CoreSys, mock_full_backup: Backup):
|
||||
@@ -43,3 +49,79 @@ async def test_options(api_client, coresys: CoreSys):
|
||||
save_data.assert_called_once()
|
||||
|
||||
assert coresys.backups.days_until_stale == 10
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"location,backup_dir",
|
||||
[("backup_test", PurePath("mounts", "backup_test")), (None, PurePath("backup"))],
|
||||
)
|
||||
async def test_backup_to_location(
|
||||
api_client: TestClient,
|
||||
coresys: CoreSys,
|
||||
location: str | None,
|
||||
backup_dir: PurePath,
|
||||
tmp_supervisor_data: Path,
|
||||
path_extern,
|
||||
):
|
||||
"""Test making a backup to a specific location with default mount."""
|
||||
await coresys.mounts.load()
|
||||
(coresys.config.path_mounts / "backup_test").mkdir()
|
||||
mount = Mount.from_dict(
|
||||
coresys,
|
||||
{
|
||||
"name": "backup_test",
|
||||
"type": "cifs",
|
||||
"usage": "backup",
|
||||
"server": "backup.local",
|
||||
"share": "backups",
|
||||
},
|
||||
)
|
||||
await coresys.mounts.create_mount(mount)
|
||||
coresys.mounts.default_backup_mount = mount
|
||||
|
||||
coresys.core.state = CoreState.RUNNING
|
||||
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
|
||||
resp = await api_client.post(
|
||||
"/backups/new/full",
|
||||
json={
|
||||
"name": "Mount test",
|
||||
"location": location,
|
||||
},
|
||||
)
|
||||
result = await resp.json()
|
||||
assert result["result"] == "ok"
|
||||
slug = result["data"]["slug"]
|
||||
|
||||
assert (tmp_supervisor_data / backup_dir / f"{slug}.tar").exists()
|
||||
|
||||
|
||||
async def test_backup_to_default(
|
||||
api_client: TestClient, coresys: CoreSys, tmp_supervisor_data, path_extern
|
||||
):
|
||||
"""Test making backup to default mount."""
|
||||
await coresys.mounts.load()
|
||||
(mount_dir := coresys.config.path_mounts / "backup_test").mkdir()
|
||||
mount = Mount.from_dict(
|
||||
coresys,
|
||||
{
|
||||
"name": "backup_test",
|
||||
"type": "cifs",
|
||||
"usage": "backup",
|
||||
"server": "backup.local",
|
||||
"share": "backups",
|
||||
},
|
||||
)
|
||||
await coresys.mounts.create_mount(mount)
|
||||
coresys.mounts.default_backup_mount = mount
|
||||
|
||||
coresys.core.state = CoreState.RUNNING
|
||||
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
|
||||
resp = await api_client.post(
|
||||
"/backups/new/full",
|
||||
json={"name": "Mount test"},
|
||||
)
|
||||
result = await resp.json()
|
||||
assert result["result"] == "ok"
|
||||
slug = result["data"]["slug"]
|
||||
|
||||
assert (mount_dir / f"{slug}.tar").exists()
|
||||
|
||||
Reference in New Issue
Block a user