From 846041a59c2dab592528eb19b7582d0b56ad43a3 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 8 Dec 2016 16:55:16 +0100 Subject: [PATCH] Fix configuration lost during save as on remote server Fix https://github.com/GNS3/gns3-gui/issues/1704, https://github.com/GNS3/gns3-gui/issues/1705 --- gns3server/controller/import_project.py | 40 ++++++++++++------------- tests/controller/test_import_project.py | 5 ++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gns3server/controller/import_project.py b/gns3server/controller/import_project.py index 0af607a6..a29ff363 100644 --- a/gns3server/controller/import_project.py +++ b/gns3server/controller/import_project.py @@ -85,6 +85,26 @@ def import_project(controller, project_id, stream, location=None, name=None, kee topology["auto_open"] = False topology["auto_close"] = True + # Generate a new node id + node_old_to_new = {} + for node in topology["topology"]["nodes"]: + if "node_id" in node: + node_old_to_new[node["node_id"]] = str(uuid.uuid4()) + _move_node_file(path, node["node_id"], node_old_to_new[node["node_id"]]) + node["node_id"] = node_old_to_new[node["node_id"]] + else: + node["node_id"] = str(uuid.uuid4()) + + # Update link to use new id + for link in topology["topology"]["links"]: + link["link_id"] = str(uuid.uuid4()) + for node in link["nodes"]: + node["node_id"] = node_old_to_new[node["node_id"]] + + # Generate new drawings id + for drawing in topology["topology"]["drawings"]: + drawing["drawing_id"] = str(uuid.uuid4()) + # Modify the compute id of the node depending of compute capacity if not keep_compute_id: # For some VM type we move them to the GNS3 VM if possible @@ -112,26 +132,6 @@ def import_project(controller, project_id, stream, location=None, name=None, kee yield from _move_files_to_compute(compute, project_id, path, os.path.join("project-files", node["node_type"], node["node_id"])) - # Generate a new node id - node_old_to_new = {} - for node in topology["topology"]["nodes"]: - if "node_id" in node: - node_old_to_new[node["node_id"]] = str(uuid.uuid4()) - _move_node_file(path, node["node_id"], node_old_to_new[node["node_id"]]) - node["node_id"] = node_old_to_new[node["node_id"]] - else: - node["node_id"] = str(uuid.uuid4()) - - # Update link to use new id - for link in topology["topology"]["links"]: - link["link_id"] = str(uuid.uuid4()) - for node in link["nodes"]: - node["node_id"] = node_old_to_new[node["node_id"]] - - # Generate new drawings id - for drawing in topology["topology"]["drawings"]: - drawing["drawing_id"] = str(uuid.uuid4()) - # And we dump the updated.gns3 dot_gns3_path = os.path.join(path, project_name + ".gns3") # We change the project_id to avoid erasing the project diff --git a/tests/controller/test_import_project.py b/tests/controller/test_import_project.py index fee3879f..7f8740c3 100644 --- a/tests/controller/test_import_project.py +++ b/tests/controller/test_import_project.py @@ -293,7 +293,6 @@ def test_import_iou_non_linux(windows_platform, async_run, tmpdir, controller): with open(zip_path, "rb") as f: with asyncio_patch("gns3server.controller.import_project._move_files_to_compute") as mock: project = async_run(import_project(controller, project_id, f)) - mock.assert_called_with(controller._computes["vm"], project_id, project.path, os.path.join('project-files', 'iou', '0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b')) controller._computes["vm"].post.assert_called_with('/projects', data={'name': 'test', 'project_id': project_id}) with open(os.path.join(project.path, "test.gns3")) as f: @@ -301,6 +300,8 @@ def test_import_iou_non_linux(windows_platform, async_run, tmpdir, controller): assert topo["topology"]["nodes"][0]["compute_id"] == "vm" assert topo["topology"]["nodes"][1]["compute_id"] == "local" + mock.assert_called_with(controller._computes["vm"], project_id, project.path, os.path.join('project-files', 'iou', topo["topology"]["nodes"][0]['node_id'])) + def test_import_node_id(linux_platform, async_run, tmpdir, controller): """ @@ -445,7 +446,7 @@ def test_move_files_to_compute(tmpdir, async_run): async_run(_move_files_to_compute(None, project_id, str(tmpdir), os.path.join("project-files", "docker"))) mock.assert_any_call(None, project_id, str(tmpdir / "project-files" / "docker" / "test"), os.path.join("project-files", "docker", "test")) - mock.assert_any_call(None, project_id, str(tmpdir / "project-files" / "docker" / "test2"), os.path.join("project-files", "docker", "test2")) + mock.assert_any_call(None, project_id, str(tmpdir / "project-files" / "docker" / "test2"), os.path.join("project-files", "docker", "test2")) assert not os.path.exists(str(tmpdir / "project-files" / "docker"))