Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions app/sep/apps/backup_mongo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from app.core.models import BaseCaseInsensitiveModel
from app.core.utils.fields import EmptyStrToNone, EnumFieldMixin, NonEmptyStr
from app.inventory.models import ServiceTypeEnum
from app.sep.apps.framework import BaseTaskResponse
from app.sep.apps.framework.form_dsl import (
Choices,
FieldWidget,
Expand All @@ -34,6 +33,7 @@
Ui,
)
from app.sep.apps.framework.rules import F
from app.sep.apps.shared.backups.responses import BackupTaskBase
from app.tasks.models import TaskHistoryStatusEnum

OWNER = "BACKUP_MONGO"
Expand Down Expand Up @@ -537,15 +537,6 @@ class BackupDerivedTaskSummary(BaseModel):
status: TaskHistoryStatusEnum | None = None


class BackupTaskBase(BaseTaskResponse):
"""Carry the backup_mongo-specific fields shared across its responses.

:param hostname: The target hostname for the task execution.
"""

hostname: str | None = None


class BackupTaskResponse(BackupTaskBase):
"""Represent a backup task API response.

Expand Down
11 changes: 1 addition & 10 deletions app/sep/apps/backup_pg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
from app.core.utils.fields import EmptyStrToNone, EnumFieldMixin, NonEmptyStr
from app.core.utils.pydantic import blank_str_values_to_none
from app.inventory.models import ServiceTypeEnum
from app.sep.apps.framework import BaseTaskResponse
from app.sep.apps.framework.form_dsl import (
Choices,
ServiceRef,
TaskFormModel,
Ui,
)
from app.sep.apps.shared.backups.responses import BackupTaskBase

OWNER = "BACKUP_PG"

Expand Down Expand Up @@ -221,15 +221,6 @@ def _blank_to_none(cls, data: Any) -> Any:
return blank_str_values_to_none(data)


class BackupTaskBase(BaseTaskResponse):
"""Carry the backup_pg-specific fields shared across its API responses.

:param hostname: The Nomad executor target the task runs on.
"""

hostname: str | None = None


class BackupTaskResponse(BackupTaskBase):
"""Represent a pgBackRest backup task API response.

Expand Down
4 changes: 2 additions & 2 deletions app/sep/apps/mysql_backups/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from app.sep.apps.mysql_backups.deps import build_mysql_backups_api_task_response
from app.sep.apps.mysql_backups.models import (
BackupCreate,
BackupResponse,
BackupTaskResponse,
OWNER,
)
from app.sep.apps.mysql_backups.restore.app import app as restore_app
Expand All @@ -64,7 +64,7 @@
description="Run XtraBackup, Mydumper, and Binlog backups against MySQL hosts.",
owner=OWNER,
create_model=BackupCreate,
response_model=BackupResponse,
response_model=BackupTaskResponse,
views=mysql_backups_views,
task_spec_builder=build_backup_spec,
response_builder=build_mysql_backups_api_task_response,
Expand Down
9 changes: 4 additions & 5 deletions app/sep/apps/mysql_backups/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from app.sep.apps.mysql_backups.models import (
BackupCreate,
BackupResponse,
BackupTaskResponse,
BackupType,
OWNER,
)
Expand Down Expand Up @@ -156,8 +156,8 @@ def build_mysql_backups_api_task_response(
*,
last_executed_at: datetime | None = None,
context: dict[str, str] | None = None,
) -> BackupResponse:
"""Build a ``BackupResponse`` for the JSON API.
) -> BackupTaskResponse:
"""Build a ``BackupTaskResponse`` for the JSON API.

:param task: The backups task retrieved from the Tasks API.
:type task: Task
Expand All @@ -170,15 +170,14 @@ def build_mysql_backups_api_task_response(
usernames; falls back to the raw id when the map lacks an entry.
:type context: dict[str, str] | None
:return: A validated backup task API response object.
:rtype: BackupResponse
"""
mapping = context or {}
hostname = None
if task.data:
meta = task.data.get("meta") or {}
hostname = meta.get("target")
return build_default_task_response(
BackupResponse,
BackupTaskResponse,
task,
status,
last_executed_at=last_executed_at,
Expand Down
15 changes: 3 additions & 12 deletions app/sep/apps/mysql_backups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
NonEmptyStr,
)
from app.inventory.models import ServiceTypeEnum
from app.sep.apps.framework import BaseTaskResponse
from app.sep.apps.framework.form_dsl import (
Choices,
Forbidden,
Expand All @@ -51,6 +50,7 @@
not_,
truthy,
)
from app.sep.apps.shared.backups.responses import BackupTaskBase

OWNER = "BACKUPS"

Expand Down Expand Up @@ -644,19 +644,10 @@ class BackupConfig(BaseCaseInsensitiveModel):
server_list: list[BackupConfigServer]


class BackupTaskBase(BaseTaskResponse):
"""Carry the mysql_backups-specific fields shared across its responses.
class BackupTaskResponse(BackupTaskBase):
"""Represent a backup task API response.

:param backup_type: The backup type recorded in task config.
"""

backup_type: BackupType | None = None


class BackupResponse(BackupTaskBase):
"""Represent a backup task API response.

:param hostname: The executor hostname target.
"""

hostname: str | None = None
3 changes: 2 additions & 1 deletion app/sep/apps/shared/backups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

from app.sep.apps.shared.backups.columns import BACKUP_TYPE_COLUMN
from app.sep.apps.shared.backups.edit_form import parse_server_list_config
from app.sep.apps.shared.backups.responses import BackupTaskBase

__all__ = ["BACKUP_TYPE_COLUMN", "parse_server_list_config"]
__all__ = ["BACKUP_TYPE_COLUMN", "BackupTaskBase", "parse_server_list_config"]
27 changes: 27 additions & 0 deletions app/sep/apps/shared/backups/responses.py
Comment thread
yyyyyyyan marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2026 Percona LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""Define backup-family shared API response bases."""

from app.sep.apps.framework import BaseTaskResponse


class BackupTaskBase(BaseTaskResponse):
"""Carry the backup-family fields shared across its API responses.

:param hostname: The Nomad executor target the task runs on.
"""

hostname: str | None = None
16 changes: 8 additions & 8 deletions frontend/packages/api/specs/sep.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions frontend/packages/api/src/generated/sep.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/app/sep/apps/mysql_backups/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from app.sep.apps.framework import BaseTaskResponse
from app.sep.apps.mysql_backups.models import (
BackupConfigAll,
BackupResponse,
BackupTaskResponse,
BackupType,
)
from app.tasks.models import TaskBackendEnum
Expand Down Expand Up @@ -113,12 +113,12 @@ def test_none_raises_validation_error(self):
BackupConfigAll.model_validate({"UPLOAD_QUIET": None})


class TestBackupResponseModel:
"""Tests for ``BackupResponse`` rebased onto ``BaseTaskResponse``."""
class TestBackupTaskResponseModel:
"""Verify ``BackupTaskResponse`` is rebased onto ``BaseTaskResponse``."""

def test_exposes_inherited_task_response_surface(self) -> None:
"""Carry the shared anonymization and connectivity surface from the base."""
response = BackupResponse(
response = BackupTaskResponse(
name="mysql-backup",
owner="BACKUPS",
backend=TaskBackendEnum.PROXY,
Expand Down
16 changes: 8 additions & 8 deletions tests/app/sep/snapshots/openapi/mysql_backups.json
Original file line number Diff line number Diff line change
Expand Up @@ -4004,8 +4004,8 @@
"title": "BackupCreate",
"type": "object"
},
"mysql_backups__BackupResponse": {
"description": "Represent a backup task API response.\n\n:param hostname: The executor hostname target.",
"mysql_backups__BackupTaskResponse": {
"description": "Represent a backup task API response.\n\n:param backup_type: The backup type recorded in task config.",
"properties": {
"alert_on_fail": {
"title": "Alert On Fail",
Expand Down Expand Up @@ -4180,7 +4180,7 @@
"alert_on_fail",
"anonymized_entities"
],
"title": "BackupResponse",
"title": "BackupTaskResponse",
"type": "object"
},
"mysql_backups__BackupType": {
Expand All @@ -4204,11 +4204,11 @@
"title": "CompressionAlgorithm",
"type": "string"
},
"mysql_backups__PaginatedResponse_BackupResponse_": {
"mysql_backups__PaginatedResponse_BackupTaskResponse_": {
"properties": {
"items": {
"items": {
"$ref": "#/components/schemas/mysql_backups__BackupResponse"
"$ref": "#/components/schemas/mysql_backups__BackupTaskResponse"
},
"title": "Items",
"type": "array"
Expand All @@ -4232,7 +4232,7 @@
"offset",
"limit"
],
"title": "PaginatedResponse[BackupResponse]",
"title": "PaginatedResponse[BackupTaskResponse]",
"type": "object"
},
"mysql_backups__UploadProvider": {
Expand Down Expand Up @@ -4297,7 +4297,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/mysql_backups__PaginatedResponse_BackupResponse_"
"$ref": "#/components/schemas/mysql_backups__PaginatedResponse_BackupTaskResponse_"
}
}
},
Expand Down Expand Up @@ -4445,7 +4445,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/mysql_backups__BackupResponse"
"$ref": "#/components/schemas/mysql_backups__BackupTaskResponse"
}
}
},
Expand Down
Loading