From e04eb44a15227cf5901f685ddc010464ae7a8dfa Mon Sep 17 00:00:00 2001
From: Julien Duponchelle <julien@gns3.net>
Date: Tue, 14 Feb 2017 16:41:31 +0100
Subject: [PATCH] Disallow export of project with VirtualBox linked clone

Fix https://github.com/GNS3/gns3-gui/issues/1824
---
 gns3server/controller/export_project.py |  2 ++
 tests/controller/test_export_project.py | 24 +++++++++++++++++++++---
 tests/controller/test_project.py        |  2 +-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/gns3server/controller/export_project.py b/gns3server/controller/export_project.py
index 6fb0dd64..25c167e2 100644
--- a/gns3server/controller/export_project.py
+++ b/gns3server/controller/export_project.py
@@ -136,6 +136,8 @@ def _export_project_file(project, path, z, include_images, keep_compute_id, allo
     if "topology" in topology:
         if "nodes" in topology["topology"]:
             for node in topology["topology"]["nodes"]:
+                if node["node_type"] == "virtualbox" and node.get("properties", {}).get("linked_clone"):
+                    raise aiohttp.web.HTTPConflict(text="Topology with a linked {} clone could not be exported. Use qemu instead.".format(node["node_type"]))
                 if not allow_all_nodes and node["node_type"] in ["virtualbox", "vmware", "cloud"]:
                     raise aiohttp.web.HTTPConflict(text="Topology with a {} could not be exported".format(node["node_type"]))
 
diff --git a/tests/controller/test_export_project.py b/tests/controller/test_export_project.py
index da7c3c1d..2b6b6610 100644
--- a/tests/controller/test_export_project.py
+++ b/tests/controller/test_export_project.py
@@ -190,9 +190,9 @@ def test_export_disallow_some_type(tmpdir, project, async_run):
     topology = {
         "topology": {
             "nodes": [
-                    {
-                        "node_type": "virtualbox"
-                    }
+                {
+                    "node_type": "cloud"
+                }
             ]
         }
     }
@@ -204,6 +204,24 @@ def test_export_disallow_some_type(tmpdir, project, async_run):
         z = async_run(export_project(project, str(tmpdir)))
     z = async_run(export_project(project, str(tmpdir), allow_all_nodes=True))
 
+    # VirtualBox is always disallowed
+    topology = {
+        "topology": {
+            "nodes": [
+                {
+                    "node_type": "virtualbox",
+                    "properties": {
+                        "linked_clone": True
+                    }
+                }
+            ]
+        }
+    }
+    with open(os.path.join(path, "test.gns3"), 'w+') as f:
+        json.dump(topology, f)
+    with pytest.raises(aiohttp.web.HTTPConflict):
+        z = async_run(export_project(project, str(tmpdir), allow_all_nodes=True))
+
 
 def test_export_fix_path(tmpdir, project, async_run):
     """
diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py
index 1fec7320..4422c0d1 100644
--- a/tests/controller/test_project.py
+++ b/tests/controller/test_project.py
@@ -427,7 +427,7 @@ def test_duplicate(project, async_run, controller):
     remote_vpcs = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
 
     # We allow node not allowed for standard import / export
-    remote_virtualbox = async_run(project.add_node(compute, "test", None, node_type="virtualbox", properties={"startup_config": "test.cfg"}))
+    remote_virtualbox = async_run(project.add_node(compute, "test", None, node_type="vmware", properties={"startup_config": "test.cfg"}))
 
     new_project = async_run(project.duplicate(name="Hello"))
     assert new_project.id != project.id