diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 9373aaa5f..56f0efead 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -807,7 +807,7 @@ class Project: with open(self._snapshot_conf_path, encoding="utf-8") as f: self._snapshot_conf = json.load(f) except (OSError, UnicodeDecodeError, ValueError) as e: - raise aiohttp.web.HTTPConflict(text="Could not read snapshot config {}: {}".format(self._snapshot_conf_path, str(e))) + raise ControllerError(f"Could not read snapshot config {e}") # Load all legacy snapshots (.gns3project files) to create an initial snapshot config if it doesn't exist if os.path.exists(snapshot_dir) and not self._snapshot_conf: @@ -843,7 +843,7 @@ class Project: self._snapshot_conf = [] for snapshot in self._snapshots.values(): - self._snapshot_conf.append(snapshot.__json__()) + self._snapshot_conf.append(snapshot.asdict()) try: with open(self._snapshot_conf_path, 'w+') as f: json.dump(self._snapshot_conf, f, indent=4) diff --git a/gns3server/schemas/controller/snapshots.py b/gns3server/schemas/controller/snapshots.py index 90a7667eb..cb6657fba 100644 --- a/gns3server/schemas/controller/snapshots.py +++ b/gns3server/schemas/controller/snapshots.py @@ -16,6 +16,7 @@ from pydantic import BaseModel, Field +from typing import Optional from uuid import UUID @@ -24,8 +25,8 @@ class SnapshotBase(BaseModel): Common properties for snapshot. """ - name: str - + name: str = Field(..., description="Name of the snapshot") + description: Optional[str] = Field(None, description="Description of the snapshot") class SnapshotCreate(SnapshotBase): """ @@ -39,4 +40,7 @@ class Snapshot(SnapshotBase): snapshot_id: UUID project_id: UUID + name: str = Field(..., description="Name of the snapshot") + filename: str = Field(..., description="Filename of the snapshot") + description: str = Field(..., description="Description of the snapshot") created_at: int = Field(..., description="Date of the snapshot (UTC timestamp)") diff --git a/tests/api/routes/controller/test_snapshots.py b/tests/api/routes/controller/test_snapshots.py index 531c3fe2a..5ef2cbe8b 100644 --- a/tests/api/routes/controller/test_snapshots.py +++ b/tests/api/routes/controller/test_snapshots.py @@ -75,4 +75,4 @@ class TestSnapshotRoutes: response = await client.post(app.url_path_for("create_snapshot", project_id=project.id), json={"name": "snap1"}) assert response.status_code == status.HTTP_201_CREATED - assert len(os.listdir(os.path.join(project.path, "snapshots"))) == 1 + assert len(os.listdir(os.path.join(project.path, "snapshots"))) == 2 diff --git a/tests/controller/test_snapshot.py b/tests/controller/test_snapshot.py index b69be9ae8..8881b98f1 100644 --- a/tests/controller/test_snapshot.py +++ b/tests/controller/test_snapshot.py @@ -72,7 +72,7 @@ def test_json(project): # new style snapshot snapshot = Snapshot(project, name="snapshot_test2") - assert snapshot.__json__() == { + assert snapshot.asdict() == { "snapshot_id": snapshot._id, "name": "snapshot_test2", "project_id": project.id,