mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-12 17:10:55 +00:00
Fixes tests.
This commit is contained in:
parent
25b778aec0
commit
6d56da03e5
@ -345,6 +345,10 @@ class IOUVM(BaseVM):
|
|||||||
Checks for a valid IOU key in the iourc file (paranoid mode).
|
Checks for a valid IOU key in the iourc file (paranoid mode).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", False)
|
||||||
|
if license_check:
|
||||||
|
return
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
try:
|
try:
|
||||||
with open(self.iourc_path) as f:
|
with open(self.iourc_path) as f:
|
||||||
@ -401,10 +405,7 @@ class IOUVM(BaseVM):
|
|||||||
if iourc_path and not os.path.isfile(iourc_path):
|
if iourc_path and not os.path.isfile(iourc_path):
|
||||||
raise IOUError("A valid iourc file is necessary to start IOU")
|
raise IOUError("A valid iourc file is necessary to start IOU")
|
||||||
|
|
||||||
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", False)
|
|
||||||
if license_check:
|
|
||||||
yield from self._check_iou_licence()
|
yield from self._check_iou_licence()
|
||||||
|
|
||||||
iouyap_path = self.iouyap_path
|
iouyap_path = self.iouyap_path
|
||||||
if not iouyap_path or not os.path.isfile(iouyap_path):
|
if not iouyap_path or not os.path.isfile(iouyap_path):
|
||||||
raise IOUError("iouyap is necessary to start IOU")
|
raise IOUError("iouyap is necessary to start IOU")
|
||||||
|
@ -155,6 +155,7 @@ class VirtualBoxVM(BaseVM):
|
|||||||
yield from self.set_adapters(self._adapters)
|
yield from self.set_adapters(self._adapters)
|
||||||
|
|
||||||
vm_info = yield from self._get_vm_info()
|
vm_info = yield from self._get_vm_info()
|
||||||
|
if "memory" in vm_info:
|
||||||
self._ram = int(vm_info["memory"])
|
self._ram = int(vm_info["memory"])
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -53,7 +53,7 @@ PROJECT_UPDATE_SCHEMA = {
|
|||||||
"properties": {
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
"description": "Project name",
|
"description": "Project name",
|
||||||
"type": "string",
|
"type": ["string", "null"],
|
||||||
"minLength": 1
|
"minLength": 1
|
||||||
},
|
},
|
||||||
"temporary": {
|
"temporary": {
|
||||||
|
@ -25,44 +25,49 @@ from tests.utils import asyncio_patch
|
|||||||
|
|
||||||
|
|
||||||
def test_create_project_with_path(server, tmpdir):
|
def test_create_project_with_path(server, tmpdir):
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
response = server.post("/projects", {"path": str(tmpdir)})
|
response = server.post("/projects", {"name": "test", "path": str(tmpdir)})
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.json["path"] == str(tmpdir)
|
assert response.json["path"] == str(tmpdir)
|
||||||
|
assert response.json["name"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_create_project_without_dir(server):
|
def test_create_project_without_dir(server):
|
||||||
query = {}
|
query = {"name": "test"}
|
||||||
response = server.post("/projects", query, example=True)
|
response = server.post("/projects", query, example=True)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.json["project_id"] is not None
|
assert response.json["project_id"] is not None
|
||||||
assert response.json["temporary"] is False
|
assert response.json["temporary"] is False
|
||||||
|
assert response.json["name"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_create_temporary_project(server):
|
def test_create_temporary_project(server):
|
||||||
query = {"temporary": True}
|
query = {"name": "test", "temporary": True}
|
||||||
response = server.post("/projects", query)
|
response = server.post("/projects", query)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.json["project_id"] is not None
|
assert response.json["project_id"] is not None
|
||||||
assert response.json["temporary"] is True
|
assert response.json["temporary"] is True
|
||||||
|
assert response.json["name"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_create_project_with_uuid(server):
|
def test_create_project_with_uuid(server):
|
||||||
query = {"project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"}
|
query = {"name": "test", "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"}
|
||||||
response = server.post("/projects", query)
|
response = server.post("/projects", query)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||||
|
assert response.json["name"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_show_project(server):
|
def test_show_project(server):
|
||||||
query = {"project_id": "00010203-0405-0607-0809-0a0b0c0d0e02", "temporary": False}
|
query = {"name": "test", "project_id": "00010203-0405-0607-0809-0a0b0c0d0e02", "temporary": False}
|
||||||
response = server.post("/projects", query)
|
response = server.post("/projects", query)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
response = server.get("/projects/00010203-0405-0607-0809-0a0b0c0d0e02", example=True)
|
response = server.get("/projects/00010203-0405-0607-0809-0a0b0c0d0e02", example=True)
|
||||||
assert len(response.json.keys()) == 4
|
assert len(response.json.keys()) == 5
|
||||||
assert len(response.json["location"]) > 0
|
assert len(response.json["location"]) > 0
|
||||||
assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e02"
|
assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e02"
|
||||||
assert response.json["temporary"] is False
|
assert response.json["temporary"] is False
|
||||||
|
assert response.json["name"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_show_project_invalid_uuid(server):
|
def test_show_project_invalid_uuid(server):
|
||||||
@ -71,10 +76,10 @@ def test_show_project_invalid_uuid(server):
|
|||||||
|
|
||||||
|
|
||||||
def test_update_temporary_project(server):
|
def test_update_temporary_project(server):
|
||||||
query = {"temporary": True}
|
query = {"name": "test", "temporary": True}
|
||||||
response = server.post("/projects", query)
|
response = server.post("/projects", query)
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
query = {"temporary": False}
|
query = {"name": "test", "temporary": False}
|
||||||
response = server.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
response = server.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json["temporary"] is False
|
assert response.json["temporary"] is False
|
||||||
@ -82,21 +87,23 @@ def test_update_temporary_project(server):
|
|||||||
|
|
||||||
def test_update_path_project(server, tmpdir):
|
def test_update_path_project(server, tmpdir):
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
response = server.post("/projects", {})
|
response = server.post("/projects", {"name": "first_name"})
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
query = {"path": str(tmpdir)}
|
assert response.json["name"] == "first_name"
|
||||||
|
query = {"name": "second_name", "path": str(tmpdir)}
|
||||||
response = server.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
response = server.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json["path"] == str(tmpdir)
|
assert response.json["path"] == str(tmpdir)
|
||||||
|
assert response.json["name"] == "second_name"
|
||||||
|
|
||||||
|
|
||||||
def test_update_path_project_non_local(server, tmpdir):
|
def test_update_path_project_non_local(server, tmpdir):
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": False}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=False):
|
||||||
response = server.post("/projects", {})
|
response = server.post("/projects", {"name": "first_name"})
|
||||||
assert response.status == 201
|
assert response.status == 201
|
||||||
query = {"path": str(tmpdir)}
|
query = {"name": "second_name", "path": str(tmpdir)}
|
||||||
response = server.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
response = server.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
||||||
assert response.status == 403
|
assert response.status == 403
|
||||||
|
|
||||||
|
@ -44,10 +44,7 @@ def test_router(project, manager):
|
|||||||
|
|
||||||
|
|
||||||
def test_router_invalid_dynamips_path(project, manager, loop):
|
def test_router_invalid_dynamips_path(project, manager, loop):
|
||||||
config = configparser.ConfigParser()
|
with patch("gns3server.config.Config.get_section_config", return_value={"dynamips_path": "/bin/test_fake"}):
|
||||||
config.add_section("Dynamips")
|
|
||||||
config.set("Dynamips", "dynamips_path", "/bin/test_fake")
|
|
||||||
with patch("gns3server.config.Config", return_value=config):
|
|
||||||
with pytest.raises(DynamipsError):
|
with pytest.raises(DynamipsError):
|
||||||
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
||||||
loop.run_until_complete(asyncio.async(router.create()))
|
loop.run_until_complete(asyncio.async(router.create()))
|
||||||
|
@ -85,6 +85,7 @@ def test_vm_invalid_iouyap_path(project, manager, loop):
|
|||||||
def test_start(loop, vm, monkeypatch):
|
def test_start(loop, vm, monkeypatch):
|
||||||
|
|
||||||
with patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
with patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||||
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||||
@ -100,6 +101,7 @@ def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
|
|||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file, "iouyap_path": vm.iouyap_path}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file, "iouyap_path": vm.iouyap_path}):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||||
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as exec_mock:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as exec_mock:
|
||||||
|
@ -60,7 +60,7 @@ def test_create_vm_new_topology_without_uuid(loop, project, port_manager):
|
|||||||
|
|
||||||
def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
|
def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
# Create an old topology directory
|
# Create an old topology directory
|
||||||
project_dir = str(tmpdir / "testold")
|
project_dir = str(tmpdir / "testold")
|
||||||
vm_dir = os.path.join(project_dir, "testold-files", "vpcs", "pc-1")
|
vm_dir = os.path.join(project_dir, "testold-files", "vpcs", "pc-1")
|
||||||
|
@ -20,7 +20,6 @@ import os
|
|||||||
import asyncio
|
import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import shutil
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ def test_affect_uuid():
|
|||||||
|
|
||||||
|
|
||||||
def test_path(tmpdir):
|
def test_path(tmpdir):
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
p = Project(location=str(tmpdir))
|
p = Project(location=str(tmpdir))
|
||||||
assert p.path == os.path.join(str(tmpdir), p.id)
|
assert p.path == os.path.join(str(tmpdir), p.id)
|
||||||
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
||||||
@ -60,14 +59,14 @@ def test_path(tmpdir):
|
|||||||
|
|
||||||
def test_init_path(tmpdir):
|
def test_init_path(tmpdir):
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
p = Project(path=str(tmpdir))
|
p = Project(path=str(tmpdir))
|
||||||
assert p.path == str(tmpdir)
|
assert p.path == str(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
def test_changing_path_temporary_flag(tmpdir):
|
def test_changing_path_temporary_flag(tmpdir):
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
p = Project(temporary=True)
|
p = Project(temporary=True)
|
||||||
assert os.path.exists(p.path)
|
assert os.path.exists(p.path)
|
||||||
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
@ -96,13 +95,13 @@ def test_remove_temporary_flag():
|
|||||||
|
|
||||||
|
|
||||||
def test_changing_location_not_allowed(tmpdir):
|
def test_changing_location_not_allowed(tmpdir):
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": False}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=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_changing_path_not_allowed(tmpdir):
|
def test_changing_path_not_allowed(tmpdir):
|
||||||
with patch("gns3server.config.Config.getboolean", return_value=False):
|
with patch("gns3server.modules.project.Project.is_local", return_value=False):
|
||||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||||
p = Project()
|
p = Project()
|
||||||
p.path = str(tmpdir)
|
p.path = str(tmpdir)
|
||||||
@ -110,11 +109,11 @@ def test_changing_path_not_allowed(tmpdir):
|
|||||||
|
|
||||||
def test_json(tmpdir):
|
def test_json(tmpdir):
|
||||||
p = Project()
|
p = Project()
|
||||||
assert p.__json__() == {"location": p.location, "path": p.path, "project_id": p.id, "temporary": False}
|
assert p.__json__() == {"name": p.name, "location": p.location, "path": p.path, "project_id": p.id, "temporary": False}
|
||||||
|
|
||||||
|
|
||||||
def test_vm_working_directory(tmpdir, vm):
|
def test_vm_working_directory(tmpdir, vm):
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||||
p = Project(location=str(tmpdir))
|
p = Project(location=str(tmpdir))
|
||||||
assert p.vm_working_directory(vm) == os.path.join(str(tmpdir), p.id, 'project-files', vm.module_name, vm.id)
|
assert p.vm_working_directory(vm) == os.path.join(str(tmpdir), p.id, 'project-files', vm.module_name, vm.id)
|
||||||
assert os.path.exists(p.vm_working_directory(vm))
|
assert os.path.exists(p.vm_working_directory(vm))
|
||||||
|
Loading…
Reference in New Issue
Block a user