From 851d6e1db8e8e24bd8826e2a6d0a6651ad87743c Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 15 May 2017 10:20:57 +0200 Subject: [PATCH] When importing portable project NAT node is loaded on GNS3 VM Fix #1030 --- gns3server/controller/import_project.py | 2 +- tests/controller/test_import_project.py | 44 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/gns3server/controller/import_project.py b/gns3server/controller/import_project.py index 63dd4507..0bdccc1d 100644 --- a/gns3server/controller/import_project.py +++ b/gns3server/controller/import_project.py @@ -114,7 +114,7 @@ def import_project(controller, project_id, stream, location=None, name=None, kee # unless it's a linux host without GNS3 VM if not sys.platform.startswith("linux") or controller.has_compute("vm"): for node in topology["topology"]["nodes"]: - if node["node_type"] in ("docker", "qemu", "iou"): + if node["node_type"] in ("docker", "qemu", "iou", "nat"): node["compute_id"] = "vm" else: for node in topology["topology"]["nodes"]: diff --git a/tests/controller/test_import_project.py b/tests/controller/test_import_project.py index 23d09457..e61e1ed8 100644 --- a/tests/controller/test_import_project.py +++ b/tests/controller/test_import_project.py @@ -252,6 +252,50 @@ def test_import_iou_linux_with_vm(linux_platform, async_run, tmpdir, controller) assert topo["topology"]["nodes"][0]["compute_id"] == "vm" +def test_import_nat_non_linux(windows_platform, async_run, tmpdir, controller): + """ + On non linux host NAT should be moved to the GNS3 VM + """ + project_id = str(uuid.uuid4()) + controller._computes["vm"] = AsyncioMagicMock() + + topology = { + "project_id": str(uuid.uuid4()), + "name": "test", + "type": "topology", + "topology": { + "nodes": [ + { + "compute_id": "local", + "node_id": "0fd3dd4d-dc93-4a04-a9b9-7396a9e22e8b", + "node_type": "nat", + "name": "test", + "properties": {} + } + ], + "links": [], + "computes": [], + "drawings": [] + }, + "revision": 5, + "version": "2.0.0" + } + + with open(str(tmpdir / "project.gns3"), 'w+') as f: + json.dump(topology, f) + + zip_path = str(tmpdir / "project.zip") + with zipfile.ZipFile(zip_path, 'w') as myzip: + myzip.write(str(tmpdir / "project.gns3"), "project.gns3") + + with open(zip_path, "rb") as f: + project = async_run(import_project(controller, project_id, f)) + + with open(os.path.join(project.path, "test.gns3")) as f: + topo = json.load(f) + assert topo["topology"]["nodes"][0]["compute_id"] == "vm" + + def test_import_iou_non_linux(windows_platform, async_run, tmpdir, controller): """ On non linux host IOU should be moved to the GNS3 VM