1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00
This commit is contained in:
Julien Duponchelle 2015-01-20 13:04:20 +01:00
parent 0695e75e77
commit 68d0e5f42d
18 changed files with 49 additions and 64 deletions

View File

@ -20,8 +20,3 @@ from .vpcs import VPCS
from .virtualbox import VirtualBox
MODULES = [VPCS, VirtualBox]
#if sys.platform.startswith("linux"):
# # IOU runs only on Linux
# from .iou import IOU
# MODULES.append(IOU)

View File

@ -98,4 +98,3 @@ class BaseVM:
"""
raise NotImplementedError

View File

@ -272,7 +272,6 @@ class VPCSDevice(BaseVM):
if not nio:
raise VPCSError("Requested NIO does not exist or is not supported: {}".format(nio_settings["type"]))
self._ethernet_adapter.add_nio(port_id, nio)
log.info("VPCS {name} {uuid}]: {nio} added to port {port_id}".format(name=self._name,
uuid=self.uuid,

View File

@ -36,4 +36,3 @@ PROJECT_OBJECT_SCHEMA = {
},
"additionalProperties": False
}

View File

@ -78,4 +78,3 @@ VBOX_OBJECT_SCHEMA = {
"additionalProperties": False,
"required": ["name", "uuid"]
}

View File

@ -148,4 +148,3 @@ VPCS_OBJECT_SCHEMA = {
"additionalProperties": False,
"required": ["name", "uuid", "console", "project_uuid"]
}

View File

@ -22,6 +22,7 @@ import logging
log = logging.getLogger(__name__)
class Response(aiohttp.web.Response):
def __init__(self, route=None, output_schema=None, headers={}, **kwargs):

View File

@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Base code use for all API tests"""
import json
@ -143,6 +144,7 @@ def loop(request):
request.addfinalizer(tear_down)
return loop
@pytest.fixture(scope="session")
def server(request, loop):
port = _get_unused_port()
@ -168,4 +170,3 @@ def server(request, loop):
@pytest.fixture(scope="module")
def project():
return ProjectManager.instance().create_project(uuid="a1e920ca-338a-4e9f-b363-aa607b09dd80")

View File

@ -30,12 +30,14 @@ def test_create_project_with_dir(server, tmpdir):
assert response.status == 200
assert response.json['location'] == str(tmpdir)
def test_create_project_without_dir(server):
query = {}
response = server.post('/project', query)
assert response.status == 200
assert response.json['uuid'] is not None
def test_create_project_with_uuid(server):
query = {'uuid': '00010203-0405-0607-0809-0a0b0c0d0e0f'}
response = server.post('/project', query)

View File

@ -38,7 +38,6 @@ def test_vpcs_create(server, project):
assert response.json["project_uuid"] == "61d61bdd-aa7d-4912-817f-65a9eb54d3ab"
#FIXME
def test_vpcs_nio_create_udp(server, vm):
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
"lport": 4242,
@ -59,7 +58,6 @@ def test_vpcs_nio_create_tap(mock, server, vm):
assert response.json["type"] == "nio_tap"
#FIXME
def test_vpcs_delete_nio(server, vm):
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
"lport": 4242,

View File

@ -1,19 +0,0 @@
import sys
import os
import pytest
import subprocess
import time
@pytest.fixture(scope="session", autouse=True)
def server(request):
"""
Starts GNS3 server for all the tests.
"""
cwd = os.path.dirname(os.path.abspath(__file__))
server_script = os.path.join(cwd, "../gns3server/main.py")
process = subprocess.Popen([sys.executable, server_script, "--port=8000"])
#time.sleep(1) # give some time for the process to start
request.addfinalizer(process.terminate)
return process

View File

@ -16,8 +16,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gns3server.modules.project import Project
import os
from gns3server.modules.project import Project
def test_affect_uuid():
p = Project()
@ -26,16 +27,19 @@ def test_affect_uuid():
p = Project(uuid='00010203-0405-0607-0809-0a0b0c0d0e0f')
assert p.uuid == '00010203-0405-0607-0809-0a0b0c0d0e0f'
def test_path(tmpdir):
p = Project(location=str(tmpdir))
assert p.path == os.path.join(str(tmpdir), p.uuid)
assert os.path.exists(os.path.join(str(tmpdir), p.uuid))
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'files'))
def test_temporary_path():
p = Project()
assert os.path.exists(p.path)
def test_json(tmpdir):
p = Project()
assert p.__json__() == {"location": p.location, "uuid": p.uuid}

View File

@ -25,8 +25,8 @@ def test_create_project():
project = pm.create_project(uuid='00010203-0405-0607-0809-0a0b0c0d0e0f')
assert project == pm.get_project('00010203-0405-0607-0809-0a0b0c0d0e0f')
def test_project_not_found():
pm = ProjectManager.instance()
with pytest.raises(aiohttp.web.HTTPNotFound):
pm.get_project('00010203-0405-0607-0809-000000000000')

View File

@ -42,6 +42,7 @@ def test_vm(manager):
assert vm.name == "test"
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
@patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.1".encode("utf-8"))
def test_vm_invalid_vpcs_version(project, manager):
with pytest.raises(VPCSError):
@ -49,6 +50,7 @@ def test_vm_invalid_vpcs_version(project, manager):
assert vm.name == "test"
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
@patch("gns3server.config.Config.get_section_config", return_value={"path": "/bin/test_fake"})
def test_vm_invalid_vpcs_path(project, manager):
with pytest.raises(VPCSError):
@ -56,13 +58,15 @@ def test_vm_invalid_vpcs_path(project, manager):
assert vm.name == "test"
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
def test_start(project, loop, manager):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running() == True
assert vm.is_running()
def test_stop(project, loop, manager):
process = MagicMock()
@ -71,22 +75,25 @@ def test_stop(project, loop, manager):
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running() == True
assert vm.is_running()
loop.run_until_complete(asyncio.async(vm.stop()))
assert vm.is_running() == False
assert vm.is_running() is False
process.terminate.assert_called_with()
def test_add_nio_binding_udp(manager):
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
assert nio.lport == 4242
def test_add_nio_binding_tap(project, manager):
vm = VPCSDevice("test", 42, project, manager)
with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=True):
nio = vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"})
assert nio.tap_device == "test"
def test_add_nio_binding_tap_no_privileged_access(manager):
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=False):
@ -94,6 +101,7 @@ def test_add_nio_binding_tap_no_privileged_access(manager):
vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"})
assert vm._ethernet_adapter.ports[0] is None
def test_port_remove_nio_binding(manager):
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})