Create link when loading topology on controller

This commit is contained in:
Julien Duponchelle committed 2016-06-15 16:26:16 +02:00
1 parent 742243e9df
commit 0569480953
7 files changed
+61 -32

No files matched your search

+11 -10
View File
@@ -21,7 +21,7 @@ import json
import pytest
import aiohttp
from unittest.mock import MagicMock
from tests.utils import AsyncioMagicMock
from tests.utils import AsyncioMagicMock, asyncio_patch
from gns3server.controller import Controller
from gns3server.controller.compute import Compute
@@ -204,8 +204,7 @@ def test_load_project(controller, async_run, tmpdir):
}
],
"links": [
{
"capturing": True,
{
"link_id": "c44331d2-2da4-490d-9aad-7f5c126ae271",
"nodes": [
{"node_id": "c067b922-7f77-4680-ac00-0226c6583598", "adapter_number": 0, "port_number": 0},
@@ -240,15 +239,17 @@ def test_load_project(controller, async_run, tmpdir):
with open(str(tmpdir / "test.gns3"), "w+") as f:
json.dump(data, f)
controller.add_compute = AsyncioMagicMock()
mock_project = MagicMock()
controller.add_project = AsyncioMagicMock(return_value=mock_project)
controller._computes["my_remote"] = MagicMock()
async_run(controller.load_project(str(tmpdir / "test.gns3")))
with asyncio_patch("gns3server.controller.node.Node.create") as mock_node_create:
async_run(controller.load_project(str(tmpdir / "test.gns3")))
controller.add_compute.assert_called_with(compute_id='my_remote', host='127.0.0.1', name='My remote', port=3080, protocol='http')
controller.add_project.assert_called_with(name='Test', project_id='c8d07a5a-134f-4c3f-8599-e35eac85eb17', path=str(tmpdir))
mock_project.add_node.assert_any_call(controller._computes["my_remote"], 'PC1', '50d66d7b-0dd7-4e9f-b720-6eb621ae6543', node_type='vpcs', properties={'startup_script': 'set pcname PC1\n', 'startup_script_path': 'startup.vpc'})
mock_project.add_node.assert_any_call(controller._computes["my_remote"], 'PC2', 'c067b922-7f77-4680-ac00-0226c6583598', node_type='vpcs', properties={'startup_script': 'set pcname PC2\n', 'startup_script_path': 'startup.vpc'})
project = controller.get_project('c8d07a5a-134f-4c3f-8599-e35eac85eb17')
assert project.name == "Test"
assert project.path == str(tmpdir)
link = project.get_link("c44331d2-2da4-490d-9aad-7f5c126ae271")
assert len(link.nodes) == 2
node1 = project.get_node("50d66d7b-0dd7-4e9f-b720-6eb621ae6543")
assert node1.name == "PC1"
+1 -1
View File
@@ -64,7 +64,6 @@ def test_basic_topology(tmpdir, async_run, controller):
assert topo["topology"]["computes"][0] == compute.__json__()
def test_load_topology(tmpdir):
data = {
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
@@ -84,6 +83,7 @@ def test_load_topology(tmpdir):
topo = load_topology(path)
assert topo == data
def test_load_topology_file_error(tmpdir):
path = str(tmpdir / "test.gns3")
with pytest.raises(aiohttp.web.HTTPConflict):