If we don't have a GNS3 VM on linux don't move file to it

This commit is contained in:
Julien Duponchelle 2016-07-25 18:02:22 +02:00
parent f357879186
commit e50acf811c
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 61 additions and 5 deletions

View File

@ -244,6 +244,12 @@ class Controller:
raise aiohttp.web.HTTPNotFound(text="You try to use a node on the GNS3 VM server but the GNS3 is not configured")
raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id))
def has_compute(self, compute_id):
"""
Return True if the compute exist in the controller
"""
return compute_id in self._computes
@asyncio.coroutine
def add_project(self, project_id=None, name=None, **kwargs):
"""

View File

@ -74,8 +74,9 @@ def import_project(controller, project_id, stream, location=None, name=None, kee
# 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 it's not a Linux host
if not sys.platform.startswith("linux"):
# For some VM type we move them to the GNS3 VM if possible
# 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"):
node["compute_id"] = "vm"

View File

@ -192,6 +192,13 @@ def test_getCompute(controller, async_run):
assert controller.get_compute("dsdssd")
def test_has_compute(controller, async_run):
compute = async_run(controller.add_compute(compute_id="test1"))
assert controller.has_compute("test1")
assert not controller.has_compute("test2")
def test_initControllerLocal(controller, controller_config_path, async_run):
"""
The local node is the controller itself you can not change the informations
@ -344,4 +351,3 @@ def test_get_free_project_name(controller, async_run):
async_run(controller.add_project(project_id=str(uuid.uuid4()), name="Test-1"))
assert controller.get_free_project_name("Test") == "Test-2"
assert controller.get_free_project_name("Hello") == "Hello"

View File

@ -131,9 +131,9 @@ def test_import_with_images(tmpdir, async_run, controller):
assert os.path.exists(path), path
def test_import_iou_linux(linux_platform, async_run, tmpdir, controller):
def test_import_iou_linux_no_vm(linux_platform, async_run, tmpdir, controller):
"""
On non linux host IOU should be local
On non linux host IOU should be local if we don't have a GNS3 VM
"""
project_id = str(uuid.uuid4())
@ -172,6 +172,49 @@ def test_import_iou_linux(linux_platform, async_run, tmpdir, controller):
assert topo["topology"]["nodes"][0]["compute_id"] == "local"
def test_import_iou_linux_with_vm(linux_platform, async_run, tmpdir, controller):
"""
On non linux host IOU should be vm if we have a GNS3 VM configured
"""
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": "iou",
"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