mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Do not reload a project if project is already opened
Ref https://github.com/GNS3/gns3-gui/issues/1251
This commit is contained in:
parent
4783691c87
commit
3132d51694
@ -217,7 +217,10 @@ class Controller:
|
||||
topo_data.pop("revision")
|
||||
topo_data.pop("type")
|
||||
|
||||
project = yield from self.add_project(path=os.path.dirname(path), status="closed", filename=os.path.basename(path), **topo_data)
|
||||
if topo_data["project_id"] in self._projects:
|
||||
project = self._projects[topo_data["project_id"]]
|
||||
else:
|
||||
project = yield from self.add_project(path=os.path.dirname(path), status="closed", filename=os.path.basename(path), **topo_data)
|
||||
if load:
|
||||
yield from project.open()
|
||||
return project
|
||||
|
@ -337,6 +337,9 @@ class Project:
|
||||
"""
|
||||
Load topology elements
|
||||
"""
|
||||
if self._status == "opened":
|
||||
return
|
||||
|
||||
self.reset()
|
||||
path = self._topology_file()
|
||||
if os.path.exists(path):
|
||||
|
@ -242,6 +242,16 @@ def images_dir(config):
|
||||
return path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def projects_dir(config):
|
||||
"""
|
||||
Get the location of images
|
||||
"""
|
||||
path = config.get_section_config("Server").get("projects_path")
|
||||
os.makedirs(path, exist_ok=True)
|
||||
return path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def darwin_platform():
|
||||
"""
|
||||
|
@ -68,6 +68,17 @@ def test_load(controller, controller_config_path, async_run):
|
||||
}
|
||||
|
||||
|
||||
def test_load_projects(controller, projects_dir, async_run):
|
||||
controller.save()
|
||||
|
||||
os.makedirs(os.path.join(projects_dir, "project1"))
|
||||
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())
|
||||
mock_load_project.assert_called_with(os.path.join(projects_dir, "project1", "project1.gns3"), load=False)
|
||||
|
||||
|
||||
def test_isEnabled(controller):
|
||||
Config.instance().set("Server", "controller", False)
|
||||
assert not controller.is_enabled()
|
||||
@ -254,3 +265,9 @@ def test_load_project(controller, async_run, tmpdir):
|
||||
|
||||
node1 = project.get_node("50d66d7b-0dd7-4e9f-b720-6eb621ae6543")
|
||||
assert node1.name == "PC1"
|
||||
|
||||
# Reload the same project should do nothing
|
||||
with asyncio_patch("gns3server.controller.Controller.add_project") as mock_add_project:
|
||||
project = async_run(controller.load_project(str(tmpdir / "test.gns3")))
|
||||
assert not mock_add_project.called
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user