|
|
@ -21,7 +21,7 @@ import json
|
|
|
|
import pytest
|
|
|
|
import pytest
|
|
|
|
import aiohttp
|
|
|
|
import aiohttp
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
from tests.utils import AsyncioMagicMock
|
|
|
|
|
|
|
|
|
|
|
|
from gns3server.controller import Controller
|
|
|
|
from gns3server.controller import Controller
|
|
|
|
from gns3server.controller.compute import Compute
|
|
|
|
from gns3server.controller.compute import Compute
|
|
|
@ -184,3 +184,71 @@ def test_close(controller, async_run):
|
|
|
|
c._connected = True
|
|
|
|
c._connected = True
|
|
|
|
async_run(controller.close())
|
|
|
|
async_run(controller.close())
|
|
|
|
assert c.connected is False
|
|
|
|
assert c.connected is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_load_project(controller, async_run, tmpdir):
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
|
|
|
"name": "Test",
|
|
|
|
|
|
|
|
"project_id": "c8d07a5a-134f-4c3f-8599-e35eac85eb17",
|
|
|
|
|
|
|
|
"revision": 5,
|
|
|
|
|
|
|
|
"type": "topology",
|
|
|
|
|
|
|
|
"version": "2.0.0dev1",
|
|
|
|
|
|
|
|
"topology": {
|
|
|
|
|
|
|
|
"computes": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"compute_id": "my_remote",
|
|
|
|
|
|
|
|
"host": "127.0.0.1",
|
|
|
|
|
|
|
|
"name": "My remote",
|
|
|
|
|
|
|
|
"port": 3080,
|
|
|
|
|
|
|
|
"protocol": "http",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"links": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"capturing": True,
|
|
|
|
|
|
|
|
"link_id": "c44331d2-2da4-490d-9aad-7f5c126ae271",
|
|
|
|
|
|
|
|
"nodes": [
|
|
|
|
|
|
|
|
{"node_id": "c067b922-7f77-4680-ac00-0226c6583598", "adapter_number": 0, "port_number": 0},
|
|
|
|
|
|
|
|
{"node_id": "50d66d7b-0dd7-4e9f-b720-6eb621ae6543", "adapter_number": 0, "port_number": 0},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"nodes": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"compute_id": "my_remote",
|
|
|
|
|
|
|
|
"name": "PC2",
|
|
|
|
|
|
|
|
"node_id": "c067b922-7f77-4680-ac00-0226c6583598",
|
|
|
|
|
|
|
|
"node_type": "vpcs",
|
|
|
|
|
|
|
|
"properties": {
|
|
|
|
|
|
|
|
"startup_script": "set pcname PC2\n",
|
|
|
|
|
|
|
|
"startup_script_path": "startup.vpc"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"compute_id": "my_remote",
|
|
|
|
|
|
|
|
"name": "PC1",
|
|
|
|
|
|
|
|
"node_id": "50d66d7b-0dd7-4e9f-b720-6eb621ae6543",
|
|
|
|
|
|
|
|
"node_type": "vpcs",
|
|
|
|
|
|
|
|
"properties": {
|
|
|
|
|
|
|
|
"startup_script": "set pcname PC1\n",
|
|
|
|
|
|
|
|
"startup_script_path": "startup.vpc"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'})
|
|
|
|
|
|
|
|
|
|
|
|