From ac085126fc37169409e8a27b8729092e95d554e7 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 16 Aug 2016 16:04:20 +0200 Subject: [PATCH] Support for auto open projects Fix #1418 --- gns3server/controller/__init__.py | 6 +++++- gns3server/web/web_server.py | 5 +++++ tests/controller/test_controller.py | 2 +- tests/controller/test_project.py | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index dfcf2b7c..f01e8832 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -99,7 +99,11 @@ class Controller: for c in data["computes"]: yield from self.add_compute(**c) - # Preload the list of projects from disk + @asyncio.coroutine + def load_projects(self): + """ + Preload the list of projects from disk + """ server_config = Config.instance().get_section_config("Server") projects_path = os.path.expanduser(server_config.get("projects_path", "~/GNS3/projects")) os.makedirs(projects_path, exist_ok=True) diff --git a/gns3server/web/web_server.py b/gns3server/web/web_server.py index 1c29282a..736253d8 100644 --- a/gns3server/web/web_server.py +++ b/gns3server/web/web_server.py @@ -292,10 +292,15 @@ class WebServer: log.info("Starting server on {}:{}".format(self._host, self._port)) self._handler = app.make_handler(handler=RequestHandler) server = self._run_application(self._handler, ssl_context) + self._loop.run_until_complete(server) self._signal_handling() self._exit_handling() + # Now the compute is initialized we can load the projects + if server_config.getboolean("controller"): + asyncio.async(Controller.instance().load_projects()) + if server_config.getboolean("shell"): asyncio.async(self.start_shell()) diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index 91ba9f8b..a846cba1 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -121,7 +121,7 @@ def test_load_projects(controller, projects_dir, async_run): with open(os.path.join(projects_dir, "project1", "project1.gns3"), "w+") as f: f.write("") with asyncio_patch("gns3server.controller.Controller.load_project") as mock_load_project: - async_run(controller.load()) + async_run(controller.load_projects()) mock_load_project.assert_called_with(os.path.join(projects_dir, "project1", "project1.gns3"), load=False) diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index 7f073be8..7747ff36 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -506,4 +506,3 @@ def test_suspend_all(project, async_run): compute.post = AsyncioMagicMock() async_run(project.suspend_all()) assert len(compute.post.call_args_list) == 10 -