mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Link API should work now need to implement the client
This commit is contained in:
7 files changed
+163
-4
No files matched your search
@@ -36,7 +36,7 @@ def hypervisor():
|
||||
def test_addVM(async_run, project, hypervisor):
|
||||
vm1 = VM(project, hypervisor)
|
||||
|
||||
link = Link()
|
||||
link = Link(project)
|
||||
async_run(link.addVM(vm1, 0, 4))
|
||||
assert link._vms == [
|
||||
{
|
||||
@@ -51,7 +51,7 @@ def test_json(async_run, project, hypervisor):
|
||||
vm1 = VM(project, hypervisor)
|
||||
vm2 = VM(project, hypervisor)
|
||||
|
||||
link = Link()
|
||||
link = Link(project)
|
||||
async_run(link.addVM(vm1, 0, 4))
|
||||
async_run(link.addVM(vm2, 1, 3))
|
||||
assert link.__json__() == {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2016 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import asyncio
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.controller.hypervisor import Hypervisor
|
||||
from gns3server.controller.udp_link import UDPLink
|
||||
from gns3server.controller.vm import VM
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def project():
|
||||
return Project()
|
||||
|
||||
|
||||
def test_create(async_run, project):
|
||||
hypervisor1 = MagicMock()
|
||||
hypervisor2 = MagicMock()
|
||||
|
||||
vm1 = VM(project, hypervisor1, vm_type="vpcs")
|
||||
vm2 = VM(project, hypervisor2, vm_type="vpcs")
|
||||
|
||||
link = UDPLink(project)
|
||||
async_run(link.addVM(vm1, 0, 4))
|
||||
async_run(link.addVM(vm2, 3, 1))
|
||||
|
||||
@asyncio.coroutine
|
||||
def hypervisor1_callback(path, data={}):
|
||||
"""
|
||||
Fake server
|
||||
"""
|
||||
if "/ports/udp" in path:
|
||||
response = MagicMock()
|
||||
response.json = {"udp_port": 1024}
|
||||
return response
|
||||
|
||||
@asyncio.coroutine
|
||||
def hypervisor2_callback(path, data={}):
|
||||
"""
|
||||
Fake server
|
||||
"""
|
||||
if "/ports/udp" in path:
|
||||
response = MagicMock()
|
||||
response.json = {"udp_port": 2048}
|
||||
return response
|
||||
|
||||
hypervisor1.post.side_effect = hypervisor1_callback
|
||||
hypervisor1.host = "example.com"
|
||||
hypervisor2.post.side_effect = hypervisor2_callback
|
||||
hypervisor2.host = "example.org"
|
||||
async_run(link.create())
|
||||
|
||||
hypervisor1.post.assert_any_call("/projects/{}/vpcs/vms/{}/adapters/0/ports/4/nio".format(project.id, vm1.id), data={
|
||||
"lport": 1024,
|
||||
"rhost": hypervisor2.host,
|
||||
"rport": 2048,
|
||||
"type": "nio_udp"
|
||||
})
|
||||
hypervisor2.post.assert_any_call("/projects/{}/vpcs/vms/{}/adapters/3/ports/1/nio".format(project.id, vm2.id), data={
|
||||
"lport": 2048,
|
||||
"rhost": hypervisor1.host,
|
||||
"rport": 1024,
|
||||
"type": "nio_udp"
|
||||
})
|
||||
@@ -73,3 +73,8 @@ def test_create(vm, hypervisor, project, async_run):
|
||||
"name": "demo"
|
||||
}
|
||||
hypervisor.post.assert_called_with("/projects/{}/vpcs/vms".format(vm.project.id), data=data)
|
||||
|
||||
|
||||
def test_post(vm, hypervisor, async_run):
|
||||
async_run(vm.post("/test", {"a": "b"}))
|
||||
hypervisor.post.assert_called_with("/projects/{}/vpcs/vms/{}/test".format(vm.project.id, vm.id), data={"a": "b"})
|
||||
Reference in new issue
Block a user