mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-21 05:43:12 +00:00
parent
937ffc7b73
commit
431bd789cb
@ -440,11 +440,12 @@ class Project:
|
|||||||
os.remove(snapshot.path)
|
os.remove(snapshot.path)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self):
|
def close(self, ignore_notification=False):
|
||||||
for compute in self._project_created_on_compute:
|
for compute in self._project_created_on_compute:
|
||||||
yield from compute.post("/projects/{}/close".format(self._id))
|
yield from compute.post("/projects/{}/close".format(self._id))
|
||||||
self._cleanPictures()
|
self._cleanPictures()
|
||||||
self._status = "closed"
|
self._status = "closed"
|
||||||
|
if not ignore_notification:
|
||||||
self.controller.notification.emit("project.closed", self.__json__())
|
self.controller.notification.emit("project.closed", self.__json__())
|
||||||
|
|
||||||
def _cleanPictures(self):
|
def _cleanPictures(self):
|
||||||
|
@ -77,7 +77,8 @@ class Snapshot:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
yield from self._project.delete_on_computes()
|
yield from self._project.delete_on_computes()
|
||||||
yield from self._project.close()
|
# We don't send close notif to clients because the close / open dance is purely internal
|
||||||
|
yield from self._project.close(ignore_notification=True)
|
||||||
shutil.rmtree(os.path.join(self._project.path, "project-files"))
|
shutil.rmtree(os.path.join(self._project.path, "project-files"))
|
||||||
with open(self._path, "rb") as f:
|
with open(self._path, "rb") as f:
|
||||||
project = yield from import_project(self._project.controller, self._project.id, f, location=self._project.path)
|
project = yield from import_project(self._project.controller, self._project.id, f, location=self._project.path)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
from gns3server.controller.project import Project
|
from gns3server.controller.project import Project
|
||||||
from gns3server.controller.snapshot import Snapshot
|
from gns3server.controller.snapshot import Snapshot
|
||||||
@ -90,9 +90,14 @@ def test_restore(project, controller, async_run):
|
|||||||
assert os.path.exists(test_file)
|
assert os.path.exists(test_file)
|
||||||
assert len(project.nodes) == 2
|
assert len(project.nodes) == 2
|
||||||
|
|
||||||
|
controller._notification = MagicMock()
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||||
async_run(snapshot.restore())
|
async_run(snapshot.restore())
|
||||||
|
|
||||||
|
# project.closed notification should not be send when restoring snapshots
|
||||||
|
assert "project.closed" not in [c[0][0] for c in controller.notification.emit.call_args_list]
|
||||||
|
|
||||||
|
|
||||||
project = controller.get_project(project.id)
|
project = controller.get_project(project.id)
|
||||||
assert not os.path.exists(test_file)
|
assert not os.path.exists(test_file)
|
||||||
assert len(project.nodes) == 1
|
assert len(project.nodes) == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user