Skip to content

Commit

Permalink
Add partial backup reload options
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 committed Nov 21, 2024
1 parent 622970c commit 6eb3195
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions aiohasupervisor/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
NewBackup,
PartialBackupOptions,
PartialRestoreOptions,
ReloadOptions,
)


Expand All @@ -35,9 +36,11 @@ async def set_options(self, options: BackupsOptions) -> None:
"""Set options for backups."""
await self._client.post("backups/options", json=options.to_dict())

async def reload(self) -> None:
async def reload(self, options: ReloadOptions | None = None) -> None:
"""Reload backups cache."""
await self._client.post("backups/reload")
await self._client.post(
"backups/reload", json=options.to_dict() if options else None
)

async def freeze(self, options: FreezeOptions | None = None) -> None:
"""Start a freeze for external snapshot process."""
Expand Down
2 changes: 2 additions & 0 deletions aiohasupervisor/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
NewBackup,
PartialBackupOptions,
PartialRestoreOptions,
ReloadOptions,
)
from aiohasupervisor.models.discovery import (
Discovery,
Expand Down Expand Up @@ -203,6 +204,7 @@
"NewBackup",
"PartialBackupOptions",
"PartialRestoreOptions",
"ReloadOptions",
"Discovery",
"DiscoveryConfig",
"AccessPoint",
Expand Down
9 changes: 9 additions & 0 deletions aiohasupervisor/models/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BackupBaseFields(ABC):
type: BackupType
size: float
location: str | None
locations: list[str | None]
protected: bool
compressed: bool

Expand Down Expand Up @@ -167,3 +168,11 @@ class FullRestoreOptions(Request):
@dataclass(frozen=True, slots=True)
class PartialRestoreOptions(FullRestoreOptions, PartialBackupRestoreOptions):
"""PartialRestoreOptions model."""


@dataclass(frozen=True, slots=True)
class ReloadOptions(Request):
"""ReloadOptions model."""

location: str | None
filename: str
17 changes: 17 additions & 0 deletions tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
FullBackupOptions,
PartialBackupOptions,
PartialRestoreOptions,
ReloadOptions,
)

from . import load_fixture
Expand Down Expand Up @@ -79,6 +80,22 @@ async def test_backups_reload(
}


async def test_backups_partial_reload(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test backups partial reload API."""
responses.post(f"{SUPERVISOR_URL}/backups/reload", status=200)
assert (
await supervisor_client.backups.reload(
ReloadOptions(location=None, filename="test.tar")
)
is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/backups/reload"))
}


@pytest.mark.parametrize("options", [None, FreezeOptions(timeout=1000)])
async def test_backups_freeze(
responses: aioresponses,
Expand Down

0 comments on commit 6eb3195

Please sign in to comment.