mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-30 21:03:49 +02:00
Update tests.
This commit is contained in:
parent
6460e94311
commit
499a8f10ae
@ -22,8 +22,8 @@ from tests.utils import asyncio_patch
|
|||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def vm(server, project):
|
def vm(server, project):
|
||||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
|
||||||
response = server.post("/virtualbox", {"name": "VM1",
|
response = server.post("/virtualbox", {"name": "VMTEST",
|
||||||
"vmname": "VM1",
|
"vmname": "VMTEST",
|
||||||
"linked_clone": False,
|
"linked_clone": False,
|
||||||
"project_uuid": project.uuid})
|
"project_uuid": project.uuid})
|
||||||
assert mock.called
|
assert mock.called
|
||||||
@ -44,6 +44,14 @@ def test_vbox_create(server, project):
|
|||||||
assert response.json["project_uuid"] == project.uuid
|
assert response.json["project_uuid"] == project.uuid
|
||||||
|
|
||||||
|
|
||||||
|
def test_vbox_get(server, project, vm):
|
||||||
|
response = server.get("/virtualbox/{}".format(vm["uuid"]), example=True)
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.route == "/virtualbox/{uuid}"
|
||||||
|
assert response.json["name"] == "VMTEST"
|
||||||
|
assert response.json["project_uuid"] == project.uuid
|
||||||
|
|
||||||
|
|
||||||
def test_vbox_start(server, vm):
|
def test_vbox_start(server, vm):
|
||||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
|
||||||
response = server.post("/virtualbox/{}/start".format(vm["uuid"]))
|
response = server.post("/virtualbox/{}/start".format(vm["uuid"]))
|
||||||
@ -77,3 +85,32 @@ def test_vbox_reload(server, vm):
|
|||||||
response = server.post("/virtualbox/{}/reload".format(vm["uuid"]))
|
response = server.post("/virtualbox/{}/reload".format(vm["uuid"]))
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
|
def test_vbox_nio_create_udp(server, vm):
|
||||||
|
response = server.post("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||||
|
"lport": 4242,
|
||||||
|
"rport": 4343,
|
||||||
|
"rhost": "127.0.0.1"},
|
||||||
|
example=True)
|
||||||
|
assert response.status == 201
|
||||||
|
assert response.route == "/virtualbox/{uuid}/ports/{port_id:\d+}/nio"
|
||||||
|
assert response.json["type"] == "nio_udp"
|
||||||
|
|
||||||
|
|
||||||
|
def test_vbox_delete_nio(server, vm):
|
||||||
|
server.post("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||||
|
"lport": 4242,
|
||||||
|
"rport": 4343,
|
||||||
|
"rhost": "127.0.0.1"})
|
||||||
|
response = server.delete("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
||||||
|
assert response.status == 204
|
||||||
|
assert response.route == "/virtualbox/{uuid}/ports/{port_id:\d+}/nio"
|
||||||
|
|
||||||
|
|
||||||
|
def test_vpcs_update(server, vm, free_console_port):
|
||||||
|
response = server.put("/virtualbox/{}".format(vm["uuid"]), {"name": "test",
|
||||||
|
"console": free_console_port})
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.json["name"] == "test"
|
||||||
|
assert response.json["console"] == free_console_port
|
||||||
|
@ -82,7 +82,7 @@ def test_vpcs_nio_create_udp(server, vm):
|
|||||||
"rhost": "127.0.0.1"},
|
"rhost": "127.0.0.1"},
|
||||||
example=True)
|
example=True)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
|
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
|
||||||
assert response.json["type"] == "nio_udp"
|
assert response.json["type"] == "nio_udp"
|
||||||
|
|
||||||
|
|
||||||
@ -91,18 +91,18 @@ def test_vpcs_nio_create_tap(server, vm):
|
|||||||
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_tap",
|
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_tap",
|
||||||
"tap_device": "test"})
|
"tap_device": "test"})
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
|
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
|
||||||
assert response.json["type"] == "nio_tap"
|
assert response.json["type"] == "nio_tap"
|
||||||
|
|
||||||
|
|
||||||
def test_vpcs_delete_nio(server, vm):
|
def test_vpcs_delete_nio(server, vm):
|
||||||
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||||
"lport": 4242,
|
"lport": 4242,
|
||||||
"rport": 4343,
|
"rport": 4343,
|
||||||
"rhost": "127.0.0.1"})
|
"rhost": "127.0.0.1"})
|
||||||
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
|
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
|
||||||
|
|
||||||
|
|
||||||
def test_vpcs_start(server, vm):
|
def test_vpcs_start(server, vm):
|
||||||
|
@ -91,7 +91,7 @@ def project():
|
|||||||
def port_manager():
|
def port_manager():
|
||||||
"""An instance of port manager"""
|
"""An instance of port manager"""
|
||||||
|
|
||||||
return PortManager("127.0.0.1", False)
|
return PortManager("127.0.0.1")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -45,12 +45,12 @@ def test_affect_uuid():
|
|||||||
assert p.uuid == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
assert p.uuid == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.config.Config.get_section_config", return_value={"local": True})
|
|
||||||
def test_path(tmpdir):
|
def test_path(tmpdir):
|
||||||
p = Project(location=str(tmpdir))
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||||
assert p.path == os.path.join(str(tmpdir), p.uuid)
|
p = Project(location=str(tmpdir))
|
||||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid))
|
assert p.path == os.path.join(str(tmpdir), p.uuid)
|
||||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vms'))
|
assert os.path.exists(os.path.join(str(tmpdir), p.uuid))
|
||||||
|
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vms'))
|
||||||
|
|
||||||
|
|
||||||
def test_temporary_path():
|
def test_temporary_path():
|
||||||
@ -58,10 +58,10 @@ def test_temporary_path():
|
|||||||
assert os.path.exists(p.path)
|
assert os.path.exists(p.path)
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.config.Config.get_section_config", return_value={"local": False})
|
def test_changing_location_not_allowed(tmpdir):
|
||||||
def test_changing_location_not_allowed(mock, tmpdir):
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": False}):
|
||||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||||
p = Project(location=str(tmpdir))
|
p = Project(location=str(tmpdir))
|
||||||
|
|
||||||
|
|
||||||
def test_json(tmpdir):
|
def test_json(tmpdir):
|
||||||
@ -69,11 +69,11 @@ def test_json(tmpdir):
|
|||||||
assert p.__json__() == {"location": p.location, "uuid": p.uuid, "temporary": False}
|
assert p.__json__() == {"location": p.location, "uuid": p.uuid, "temporary": False}
|
||||||
|
|
||||||
|
|
||||||
@patch("gns3server.config.Config.get_section_config", return_value={"local": True})
|
|
||||||
def test_vm_working_directory(tmpdir, vm):
|
def test_vm_working_directory(tmpdir, vm):
|
||||||
p = Project(location=str(tmpdir))
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||||
assert os.path.exists(p.vm_working_directory(vm))
|
p = Project(location=str(tmpdir))
|
||||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, vm.module_name, vm.uuid))
|
assert os.path.exists(p.vm_working_directory(vm))
|
||||||
|
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, vm.module_name, vm.uuid))
|
||||||
|
|
||||||
|
|
||||||
def test_mark_vm_for_destruction(vm):
|
def test_mark_vm_for_destruction(vm):
|
||||||
|
@ -60,7 +60,6 @@ def test_vm_non_executable_vboxmanage_path(project, manager, loop):
|
|||||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager, "test", False)
|
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager, "test", False)
|
||||||
vm._find_vboxmanage()
|
vm._find_vboxmanage()
|
||||||
|
|
||||||
|
|
||||||
def test_vm_valid_virtualbox_api_version(loop, project, manager):
|
def test_vm_valid_virtualbox_api_version(loop, project, manager):
|
||||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM._execute", return_value=["API version: 4_3"]):
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM._execute", return_value=["API version: 4_3"]):
|
||||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||||
@ -72,6 +71,3 @@ def test_vm_invalid_virtualbox_api_version(loop, project, manager):
|
|||||||
with pytest.raises(VirtualBoxError):
|
with pytest.raises(VirtualBoxError):
|
||||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.async(vm.create()))
|
||||||
|
|
||||||
|
|
||||||
# TODO: find a way to test start, stop, suspend, resume and reload
|
|
||||||
|
Loading…
Reference in New Issue
Block a user