Merge branch 'master' into unstable

Conflicts:
	tests/modules/test_manager.py
This commit is contained in:
Julien Duponchelle committed 2015-04-28 10:46:59 +02:00
commit 5f6d1bfdd6
43 files changed
+608 -677

No files matched your search

+26 -1
View File
@@ -18,10 +18,14 @@
import pytest
import os
import stat
import sys
import uuid
from tests.utils import asyncio_patch
from unittest.mock import patch, MagicMock, PropertyMock
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
@pytest.fixture
def fake_iou_bin(tmpdir):
@@ -91,11 +95,32 @@ def test_iou_create_with_params(server, project, base_params):
assert "initial-config.cfg" in response.json["initial_config"]
with open(initial_config_file(project, response.json)) as f:
assert f.read() == params["initial_config_content"]
assert f.read() == "hostname test"
assert "iourc" in response.json["iourc_path"]
def test_iou_create_initial_config_already_exist(server, project, base_params):
"""We don't erase an initial config if already exist at project creation"""
vm_id = str(uuid.uuid4())
initial_config_file_path = initial_config_file(project, {'vm_id': vm_id})
with open(initial_config_file_path, 'w+') as f:
f.write("echo hello")
params = base_params
params["vm_id"] = vm_id
params["initial_config_content"] = "hostname test"
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), params, example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/vms"
assert "initial-config.cfg" in response.json["initial_config"]
with open(initial_config_file(project, response.json)) as f:
assert f.read() == "echo hello"
def test_iou_get(server, project, vm):
response = server.get("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 200
+1 -4
View File
@@ -170,10 +170,7 @@ def test_qemu_nio_create_ethernet(server, vm):
"ethernet_device": "eth0",
},
example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/qemu/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_generic_ethernet"
assert response.json["ethernet_device"] == "eth0"
assert response.status == 409
def test_qemu_delete_nio(server, vm):
@@ -18,6 +18,7 @@
import pytest
import tempfile
import sys
from gns3server.modules.dynamips import Dynamips
from gns3server.modules.dynamips.dynamips_error import DynamipsError
@@ -37,6 +38,7 @@ def test_vm_invalid_dynamips_path(manager):
manager.find_dynamips()
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported by Windows")
def test_vm_non_executable_dynamips_path(manager):
tmpfile = tempfile.NamedTemporaryFile()
with patch("gns3server.config.Config.get_section_config", return_value={"dynamips_path": tmpfile.name}):
+6 -2
View File
@@ -20,10 +20,14 @@ import pytest
from unittest.mock import patch
import uuid
import os
import sys
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
if not sys.platform.startswith("win"):
from gns3server.modules.iou import IOU
from gns3server.modules.iou.iou_error import IOUError
from gns3server.modules.iou import IOU
from gns3server.modules.iou.iou_error import IOUError
from gns3server.modules.project_manager import ProjectManager
+9 -3
View File
@@ -21,13 +21,19 @@ import asyncio
import os
import stat
import socket
import sys
from tests.utils import asyncio_patch
from unittest.mock import patch, MagicMock, PropertyMock
from gns3server.modules.iou.iou_vm import IOUVM
from gns3server.modules.iou.iou_error import IOUError
from gns3server.modules.iou import IOU
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
if not sys.platform.startswith("win"):
from gns3server.modules.iou.iou_vm import IOUVM
from gns3server.modules.iou.iou_error import IOUError
from gns3server.modules.iou import IOU
from gns3server.config import Config
+15 -6
View File
@@ -18,6 +18,7 @@
import os
import stat
import asyncio
import sys
from gns3server.modules.qemu import Qemu
from tests.utils import asyncio_patch
@@ -27,7 +28,10 @@ def test_get_qemu_version(loop):
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
version = loop.run_until_complete(asyncio.async(Qemu._get_qemu_version("/tmp/qemu-test")))
assert version == "2.2.0"
if sys.platform.startswith("win"):
assert version == ""
else:
assert version == "2.2.0"
def test_binary_list(loop):
@@ -43,12 +47,17 @@ def test_binary_list(loop):
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list()))
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": "2.2.0"} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": "2.2.0"} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": "2.2.0"} in qemus
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": "2.2.0"} not in qemus
if sys.platform.startswith("win"):
version = ""
else:
version = "2.2.0"
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
def test_get_legacy_vm_workdir():
assert Qemu.get_legacy_vm_workdir(42, "bla") == "qemu/vm-42"
assert Qemu.get_legacy_vm_workdir(42, "bla") == os.path.join("qemu", "vm-42")
+15 -4
View File
@@ -19,6 +19,7 @@ import pytest
import aiohttp
import asyncio
import os
import sys
import stat
import re
from tests.utils import asyncio_patch
@@ -51,7 +52,10 @@ def fake_qemu_img_binary():
@pytest.fixture
def fake_qemu_binary():
bin_path = os.path.join(os.environ["PATH"], "qemu_x42")
if sys.platform.startswith("win"):
bin_path = os.path.join(os.environ["PATH"], "qemu_x42.EXE")
else:
bin_path = os.path.join(os.environ["PATH"], "qemu_x42")
with open(bin_path, "w+") as f:
f.write("1")
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -178,8 +182,9 @@ def test_set_qemu_path(vm, tmpdir, fake_qemu_binary):
f.write("1")
# Raise because file is not executable
with pytest.raises(QemuError):
vm.qemu_path = path
if not sys.platform.startswith("win"):
with pytest.raises(QemuError):
vm.qemu_path = path
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -204,6 +209,7 @@ def test_disk_options(vm, loop, fake_qemu_img_binary):
assert args == (fake_qemu_img_binary, "create", "-f", "qcow2", os.path.join(vm.working_dir, "flash.qcow2"), "256M")
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_set_process_priority(vm, loop, fake_qemu_img_binary):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
@@ -274,6 +280,7 @@ def test_build_command(vm, loop, fake_qemu_binary, port_manager):
]
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_build_command_without_display(vm, loop, fake_qemu_binary):
os.environ["DISPLAY"] = ""
@@ -282,7 +289,9 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary):
assert "-nographic" in cmd
def test_build_command_witht_invalid_options(vm, loop, fake_qemu_binary):
# Windows accept this kind of mistake
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
vm.options = "'test"
with pytest.raises(QemuError):
@@ -306,6 +315,7 @@ def test_hdb_disk_image(vm, tmpdir):
vm.hdb_disk_image = "test"
assert vm.hdb_disk_image == str(tmpdir / "QEMU" / "test")
def test_hdc_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
@@ -314,6 +324,7 @@ def test_hdc_disk_image(vm, tmpdir):
vm.hdc_disk_image = "test"
assert vm.hdc_disk_image == str(tmpdir / "QEMU" / "test")
def test_hdd_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
+29 -29
View File
@@ -22,7 +22,7 @@ from unittest.mock import patch
from gns3server.modules.vpcs import VPCS
from gns3server.modules.iou import IOU
from gns3server.modules.qemu import Qemu
@pytest.fixture(scope="function")
@@ -34,11 +34,11 @@ def vpcs(port_manager):
@pytest.fixture(scope="function")
def iou(port_manager):
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
return iou
def qemu(port_manager):
Qemu._instance = None
qemu = Qemu.instance()
qemu.port_manager = port_manager
return qemu
def test_create_vm_new_topology(loop, project, vpcs):
@@ -86,55 +86,55 @@ def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
assert f.read() == "1"
def test_get_abs_image_path(iou, tmpdir):
os.makedirs(str(tmpdir / "IOU"))
def test_get_abs_image_path(qemu, tmpdir):
os.makedirs(str(tmpdir / "QEMU"))
path1 = str(tmpdir / "test1.bin")
open(path1, 'w+').close()
path2 = str(tmpdir / "IOU" / "test2.bin")
path2 = str(tmpdir / "QEMU" / "test2.bin")
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_abs_image_path(path1) == path1
assert iou.get_abs_image_path(path2) == path2
assert iou.get_abs_image_path("test2.bin") == path2
assert iou.get_abs_image_path("../test1.bin") == path1
assert qemu.get_abs_image_path(path1) == path1
assert qemu.get_abs_image_path(path2) == path2
assert qemu.get_abs_image_path("test2.bin") == path2
assert qemu.get_abs_image_path("../test1.bin") == path1
def test_get_relative_image_path(iou, tmpdir):
os.makedirs(str(tmpdir / "IOU"))
def test_get_relative_image_path(qemu, tmpdir):
os.makedirs(str(tmpdir / "Qemu"))
path1 = str(tmpdir / "test1.bin")
open(path1, 'w+').close()
path2 = str(tmpdir / "IOU" / "test2.bin")
path2 = str(tmpdir / "QEMU" / "test2.bin")
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_relative_image_path(path1) == path1
assert iou.get_relative_image_path(path2) == "test2.bin"
assert iou.get_relative_image_path("test2.bin") == "test2.bin"
assert iou.get_relative_image_path("../test1.bin") == path1
assert qemu.get_relative_image_path(path1) == path1
assert qemu.get_relative_image_path(path2) == "test2.bin"
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
assert qemu.get_relative_image_path("../test1.bin") == path1
def test_list_images(loop, iou, tmpdir):
def test_list_images(loop, qemu, tmpdir):
fake_images = ["a.bin", "b.bin", ".blu.bin"]
for image in fake_images:
with open(str(tmpdir / image), "w+") as f:
f.write("1")
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(iou.list_images()) == [
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(qemu.list_images()) == [
{"filename": "a.bin"},
{"filename": "b.bin"}
]
def test_list_images_empty(loop, iou, tmpdir):
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(iou.list_images()) == []
def test_list_images_empty(loop, qemu, tmpdir):
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(qemu.list_images()) == []
def test_list_images_directory_not_exist(loop, iou):
with patch("gns3server.modules.IOU.get_images_directory", return_value="/bla"):
assert loop.run_until_complete(iou.list_images()) == []
def test_list_images_directory_not_exist(loop, qemu):
with patch("gns3server.modules.Qemu.get_images_directory", return_value="/bla"):
assert loop.run_until_complete(qemu.list_images()) == []
+25 -13
View File
@@ -19,6 +19,7 @@ import pytest
import aiohttp
import asyncio
import os
import sys
from tests.utils import asyncio_patch
@@ -97,9 +98,14 @@ def test_stop(loop, vm):
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running()
loop.run_until_complete(asyncio.async(vm.stop()))
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.stop()))
assert vm.is_running() is False
process.terminate.assert_called_with()
if sys.platform.startswith("win"):
process.send_signal.assert_called_with(1)
else:
process.terminate.assert_called_with()
def test_reload(loop, vm):
@@ -117,9 +123,15 @@ def test_reload(loop, vm):
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running()
loop.run_until_complete(asyncio.async(vm.reload()))
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.reload()))
assert vm.is_running() is True
process.terminate.assert_called_with()
if sys.platform.startswith("win"):
process.send_signal.assert_called_with(1)
else:
process.terminate.assert_called_with()
def test_add_nio_binding_udp(vm):
@@ -135,13 +147,13 @@ def test_add_nio_binding_tap(vm):
assert nio.tap_device == "test"
def test_add_nio_binding_tap_no_privileged_access(vm):
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=False):
with pytest.raises(aiohttp.web.HTTPForbidden):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": "test"})
vm.port_add_nio_binding(0, nio)
assert vm._ethernet_adapter.ports[0] is None
# def test_add_nio_binding_tap_no_privileged_access(vm):
# with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=False):
# with pytest.raises(aiohttp.web.HTTPForbidden):
# nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": "test"})
# vm.port_add_nio_binding(0, nio)
# assert vm._ethernet_adapter.ports[0] is None
#
def test_port_remove_nio_binding(vm):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
@@ -190,8 +202,8 @@ def test_get_startup_script_using_default_script(vm):
vm._script_file = None
filepath = os.path.join(vm.working_dir, 'startup.vpc')
with open(filepath, 'w+') as f:
assert f.write(content)
with open(filepath, 'wb+') as f:
assert f.write(content.encode("utf-8"))
assert vm.startup_script == content
assert vm.script_file == filepath
-143
View File
@@ -1,143 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 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 locale
from gns3server import main
from gns3server.config import Config
from gns3server.version import __version__
def test_locale_check():
try:
locale.setlocale(locale.LC_ALL, ("fr_FR"))
except: # Locale is not available on the server
return
main.locale_check()
assert locale.getlocale() == ('fr_FR', 'UTF-8')
def test_parse_arguments(capsys, tmpdir):
Config.reset()
config = Config.instance(str(tmpdir / "test.cfg"))
server_config = config.get_section_config("Server")
with pytest.raises(SystemExit):
main.parse_arguments(["--fail"], server_config)
out, err = capsys.readouterr()
assert "usage" in err
assert "fail" in err
assert "unrecognized arguments" in err
with pytest.raises(SystemExit):
main.parse_arguments(["-v"], server_config)
out, err = capsys.readouterr()
assert __version__ in "{}{}".format(out, err) # Depending of the Python version the location of the version change
with pytest.raises(SystemExit):
main.parse_arguments(["--version"], server_config)
out, err = capsys.readouterr()
assert __version__ in "{}{}".format(out, err) # Depending of the Python version the location of the version change
with pytest.raises(SystemExit):
main.parse_arguments(["-h"], server_config)
out, err = capsys.readouterr()
assert __version__ in out
assert "optional arguments" in out
with pytest.raises(SystemExit):
main.parse_arguments(["--help"], server_config)
out, err = capsys.readouterr()
assert __version__ in out
assert "optional arguments" in out
assert main.parse_arguments(["--host", "192.168.1.1"], server_config).host == "192.168.1.1"
assert main.parse_arguments([], server_config).host == "0.0.0.0"
server_config["host"] = "192.168.1.2"
assert main.parse_arguments(["--host", "192.168.1.1"], server_config).host == "192.168.1.1"
assert main.parse_arguments([], server_config).host == "192.168.1.2"
assert main.parse_arguments(["--port", "8002"], server_config).port == 8002
assert main.parse_arguments([], server_config).port == 8000
server_config["port"] = "8003"
assert main.parse_arguments([], server_config).port == 8003
assert main.parse_arguments(["--ssl"], server_config).ssl
assert main.parse_arguments([], server_config).ssl is False
server_config["ssl"] = "True"
assert main.parse_arguments([], server_config).ssl
assert main.parse_arguments(["--certfile", "bla"], server_config).certfile == "bla"
assert main.parse_arguments([], server_config).certfile == ""
assert main.parse_arguments(["--certkey", "blu"], server_config).certkey == "blu"
assert main.parse_arguments([], server_config).certkey == ""
assert main.parse_arguments(["-L"], server_config).local
assert main.parse_arguments(["--local"], server_config).local
assert main.parse_arguments([], server_config).local is False
server_config["local"] = "True"
assert main.parse_arguments([], server_config).local
assert main.parse_arguments(["-A"], server_config).allow
assert main.parse_arguments(["--allow"], server_config).allow
assert main.parse_arguments([], server_config).allow is False
server_config["allow_remote_console"] = "True"
assert main.parse_arguments([], server_config).allow
assert main.parse_arguments(["-q"], server_config).quiet
assert main.parse_arguments(["--quiet"], server_config).quiet
assert main.parse_arguments([], server_config).quiet is False
assert main.parse_arguments(["-d"], server_config).debug
assert main.parse_arguments([], server_config).debug is False
server_config["debug"] = "True"
assert main.parse_arguments([], server_config).debug
def test_set_config_with_args():
config = Config.instance()
args = main.parse_arguments(["--host",
"192.168.1.1",
"--local",
"--allow",
"--port",
"8001",
"--ssl",
"--certfile",
"bla",
"--certkey",
"blu",
"--debug"],
config.get_section_config("Server"))
main.set_config(args)
server_config = config.get_section_config("Server")
assert server_config.getboolean("local")
assert server_config.getboolean("allow_remote_console")
assert server_config["host"] == "192.168.1.1"
assert server_config["port"] == "8001"
assert server_config.getboolean("ssl")
assert server_config["certfile"] == "bla"
assert server_config["certkey"] == "blu"
assert server_config.getboolean("debug")
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 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 locale
from gns3server import run
from gns3server.config import Config
from gns3server.version import __version__
def test_locale_check():
try:
locale.setlocale(locale.LC_ALL, ("fr_FR"))
except: # Locale is not available on the server
return
run.locale_check()
assert locale.getlocale() == ('fr_FR', 'UTF-8')
def test_parse_arguments(capsys, tmpdir):
Config.reset()
config = Config.instance(str(tmpdir / "test.cfg"))
server_config = config.get_section_config("Server")
with pytest.raises(SystemExit):
run.parse_arguments(["--fail"], server_config)
out, err = capsys.readouterr()
assert "usage" in err
assert "fail" in err
assert "unrecognized arguments" in err
with pytest.raises(SystemExit):
run.parse_arguments(["-v"], server_config)
out, err = capsys.readouterr()
assert __version__ in "{}{}".format(out, err) # Depending of the Python version the location of the version change
with pytest.raises(SystemExit):
run.parse_arguments(["--version"], server_config)
out, err = capsys.readouterr()
assert __version__ in "{}{}".format(out, err) # Depending of the Python version the location of the version change
with pytest.raises(SystemExit):
run.parse_arguments(["-h"], server_config)
out, err = capsys.readouterr()
assert __version__ in out
assert "optional arguments" in out
with pytest.raises(SystemExit):
run.parse_arguments(["--help"], server_config)
out, err = capsys.readouterr()
assert __version__ in out
assert "optional arguments" in out
assert run.parse_arguments(["--host", "192.168.1.1"], server_config).host == "192.168.1.1"
assert run.parse_arguments([], server_config).host == "0.0.0.0"
server_config["host"] = "192.168.1.2"
assert run.parse_arguments(["--host", "192.168.1.1"], server_config).host == "192.168.1.1"
assert run.parse_arguments([], server_config).host == "192.168.1.2"
assert run.parse_arguments(["--port", "8002"], server_config).port == 8002
assert run.parse_arguments([], server_config).port == 8000
server_config["port"] = "8003"
assert run.parse_arguments([], server_config).port == 8003
assert run.parse_arguments(["--ssl"], server_config).ssl
assert run.parse_arguments([], server_config).ssl is False
server_config["ssl"] = "True"
assert run.parse_arguments([], server_config).ssl
assert run.parse_arguments(["--certfile", "bla"], server_config).certfile == "bla"
assert run.parse_arguments([], server_config).certfile == ""
assert run.parse_arguments(["--certkey", "blu"], server_config).certkey == "blu"
assert run.parse_arguments([], server_config).certkey == ""
assert run.parse_arguments(["-L"], server_config).local
assert run.parse_arguments(["--local"], server_config).local
assert run.parse_arguments([], server_config).local is False
server_config["local"] = "True"
assert run.parse_arguments([], server_config).local
assert run.parse_arguments(["-A"], server_config).allow
assert run.parse_arguments(["--allow"], server_config).allow
assert run.parse_arguments([], server_config).allow is False
server_config["allow_remote_console"] = "True"
assert run.parse_arguments([], server_config).allow
assert run.parse_arguments(["-q"], server_config).quiet
assert run.parse_arguments(["--quiet"], server_config).quiet
assert run.parse_arguments([], server_config).quiet is False
assert run.parse_arguments(["-d"], server_config).debug
assert run.parse_arguments([], server_config).debug is False
server_config["debug"] = "True"
assert run.parse_arguments([], server_config).debug
def test_set_config_with_args():
config = Config.instance()
args = run.parse_arguments(["--host",
"192.168.1.1",
"--local",
"--allow",
"--port",
"8001",
"--ssl",
"--certfile",
"bla",
"--certkey",
"blu",
"--debug"],
config.get_section_config("Server"))
run.set_config(args)
server_config = config.get_section_config("Server")
assert server_config.getboolean("local")
assert server_config.getboolean("allow_remote_console")
assert server_config["host"] == "192.168.1.1"
assert server_config["port"] == "8001"
assert server_config.getboolean("ssl")
assert server_config["certfile"] == "bla"
assert server_config["certkey"] == "blu"
assert server_config.getboolean("debug")
+2
View File
@@ -18,6 +18,7 @@
import asyncio
import pytest
import sys
from unittest.mock import MagicMock
from gns3server.utils.asyncio import wait_run_in_executor, subprocess_check_output, wait_for_process_termination
@@ -43,6 +44,7 @@ def test_exception_wait_run_in_executor(loop):
result = loop.run_until_complete(asyncio.async(exec))
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_subprocess_check_output(loop, tmpdir, restore_original_path):
path = str(tmpdir / "test")