mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 15:21:13 +02:00
Merge remote-tracking branch 'origin/2.0' into 2.0
Conflicts: gns3server/controller/project.py tests/compute/test_project.py tests/controller/test_project.py
This commit is contained in:
commit
483431438a
17 files changed
+208
-53
No files matched your search
@@ -69,10 +69,10 @@ def test_clean_tmp_directory(async_run):
|
||||
|
||||
def test_path(tmpdir):
|
||||
|
||||
directory = Config.instance().get_section_config("Server").get("project_directory")
|
||||
directory = Config.instance().get_section_config("Server").get("projects_path")
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.compute.project.Project._get_default_project_directory", return_value=directory):
|
||||
with patch("gns3server.utils.path.get_default_project_directory", return_value=directory):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
assert p.path == os.path.join(directory, p.id)
|
||||
assert os.path.exists(os.path.join(directory, p.id))
|
||||
@@ -123,8 +123,8 @@ def test_json(tmpdir):
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id, "temporary": False}
|
||||
|
||||
|
||||
def test_vm_working_directory(tmpdir, node):
|
||||
directory = Config.instance().get_section_config("Server").get("project_directory")
|
||||
def test_node_working_directory(tmpdir, vm):
|
||||
directory = Config.instance().get_section_config("Server").get("projects_path")
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
@@ -210,16 +210,6 @@ def test_project_close_temporary_project(loop, manager):
|
||||
loop.run_until_complete(asyncio.async(project.close()))
|
||||
assert os.path.exists(directory) is False
|
||||
|
||||
|
||||
def test_get_default_project_directory(monkeypatch):
|
||||
|
||||
monkeypatch.undo()
|
||||
project = Project(project_id=str(uuid4()))
|
||||
path = os.path.normpath(os.path.expanduser("~/GNS3/projects"))
|
||||
assert project._get_default_project_directory() == path
|
||||
assert os.path.exists(path)
|
||||
|
||||
|
||||
def test_clean_project_directory(tmpdir):
|
||||
|
||||
# A non anonymous project with uuid.
|
||||
@@ -237,7 +227,7 @@ def test_clean_project_directory(tmpdir):
|
||||
with open(str(tmp), 'w+') as f:
|
||||
f.write("1")
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
Project.clean_project_directory()
|
||||
|
||||
assert os.path.exists(str(project1))
|
||||
@@ -247,7 +237,7 @@ def test_clean_project_directory(tmpdir):
|
||||
|
||||
def test_list_files(tmpdir, loop):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
project = Project(project_id=str(uuid4()))
|
||||
path = project.path
|
||||
os.makedirs(os.path.join(path, "vm-1", "dynamips"))
|
||||
|
||||
+2
-2
@@ -203,7 +203,7 @@ def run_around_tests(monkeypatch, port_manager, controller, config):
|
||||
|
||||
port_manager._instance = port_manager
|
||||
os.makedirs(os.path.join(tmppath, 'projects'))
|
||||
config.set("Server", "project_directory", os.path.join(tmppath, 'projects'))
|
||||
config.set("Server", "projects_path", os.path.join(tmppath, 'projects'))
|
||||
config.set("Server", "images_path", os.path.join(tmppath, 'images'))
|
||||
config.set("Server", "auth", False)
|
||||
config.set("Server", "controller", True)
|
||||
@@ -216,7 +216,7 @@ def run_around_tests(monkeypatch, port_manager, controller, config):
|
||||
# Force turn off KVM because it's not available on CI
|
||||
config.set("Qemu", "enable_kvm", False)
|
||||
|
||||
monkeypatch.setattr("gns3server.compute.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects'))
|
||||
monkeypatch.setattr("gns3server.utils.path.get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects'))
|
||||
|
||||
# Force sys.platform to the original value. Because it seem not be restore correctly at each tests
|
||||
sys.platform = sys.original_platform
|
||||
|
||||
@@ -86,6 +86,7 @@ def test_compute_httpQueryNotConnected(compute, async_run):
|
||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/version", headers={'content-type': 'application/json'}, data=None, auth=None)
|
||||
mock.assert_any_call("POST", "https://example.com:84/v2/compute/projects", data='{"a": "b"}', headers={'content-type': 'application/json'}, auth=None)
|
||||
assert compute._connected
|
||||
assert compute.version == __version__
|
||||
|
||||
|
||||
def test_compute_httpQueryNotConnectedInvalidVersion(compute, async_run):
|
||||
|
||||
@@ -108,6 +108,15 @@ def test_getCompute(controller, async_run):
|
||||
assert controller.getCompute("dsdssd")
|
||||
|
||||
|
||||
def test_addComputeLocal(controller, controller_config_path, async_run):
|
||||
"""
|
||||
The local node is the controller itself you can not change the informations
|
||||
"""
|
||||
Config.instance().set("Server", "local", True)
|
||||
async_run(controller.addCompute("local", host="example.org"))
|
||||
assert controller.getCompute("local").host == "localhost"
|
||||
|
||||
|
||||
def test_addProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
@@ -138,7 +147,6 @@ def test_addProject_with_compute(controller, async_run):
|
||||
controller._computes = {"test1": compute}
|
||||
|
||||
project1 = async_run(controller.addProject(project_id=uuid1))
|
||||
compute.post.assert_called_with("/projects", project1)
|
||||
|
||||
|
||||
def test_getProject(controller, async_run):
|
||||
|
||||
@@ -43,9 +43,9 @@ def test_json(tmpdir):
|
||||
|
||||
def test_path(tmpdir):
|
||||
|
||||
directory = Config.instance().get_section_config("Server").get("project_directory")
|
||||
directory = Config.instance().get_section_config("Server").get("projects_path")
|
||||
|
||||
with patch("gns3server.compute.project.Project._get_default_project_directory", return_value=directory):
|
||||
with patch("gns3server.utils.path.get_default_project_directory", return_value=directory):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
assert p.path == os.path.join(directory, p.id)
|
||||
assert os.path.exists(os.path.join(directory, p.id))
|
||||
@@ -68,6 +68,12 @@ def test_captures_directory(tmpdir):
|
||||
assert p.captures_directory == str(tmpdir / "project-files" / "captures")
|
||||
assert os.path.exists(p.captures_directory)
|
||||
|
||||
def test_add_compute(async_run):
|
||||
compute = MagicMock()
|
||||
project = Project()
|
||||
async_run(project.addCompute(compute))
|
||||
assert compute in project._computes
|
||||
|
||||
|
||||
def test_addVM(async_run):
|
||||
compute = MagicMock()
|
||||
@@ -79,11 +85,12 @@ def test_addVM(async_run):
|
||||
|
||||
vm = async_run(project.add_node(compute, None, name="test", node_type="vpcs", properties={"startup_config": "test.cfg"}))
|
||||
|
||||
compute.post.assert_called_with('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
data={'node_id': vm.id,
|
||||
'console_type': 'telnet',
|
||||
'startup_config': 'test.cfg',
|
||||
'name': 'test'})
|
||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
data={'node_id': node.id,
|
||||
'console_type': 'telnet',
|
||||
'startup_config': 'test.cfg',
|
||||
'name': 'test'})
|
||||
assert compute in project._project_created_on_compute
|
||||
|
||||
|
||||
def test_getVM(async_run):
|
||||
|
||||
@@ -201,7 +201,7 @@ def test_close_project_invalid_uuid(http_compute):
|
||||
|
||||
def test_get_file(http_compute, tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
project = ProjectManager.instance().create_project(project_id="01010203-0405-0607-0809-0a0b0c0d0e0b")
|
||||
|
||||
with open(os.path.join(project.path, "hello"), "w+") as f:
|
||||
@@ -220,7 +220,7 @@ def test_get_file(http_compute, tmpdir):
|
||||
|
||||
def test_stream_file(http_compute, tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
project = ProjectManager.instance().create_project(project_id="01010203-0405-0607-0809-0a0b0c0d0e0b")
|
||||
|
||||
with open(os.path.join(project.path, "hello"), "w+") as f:
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/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 os
|
||||
import pytest
|
||||
import aiohttp
|
||||
|
||||
from gns3server.utils.path import check_path_allowed, get_default_project_directory
|
||||
|
||||
|
||||
def test_check_path_allowed(config, tmpdir):
|
||||
config.set("Server", "local", False)
|
||||
config.set("Server", "projects_path", str(tmpdir))
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
check_path_allowed("/private")
|
||||
|
||||
config.set("Server", "local", True)
|
||||
check_path_allowed(str(tmpdir / "hello" / "world"))
|
||||
check_path_allowed("/private")
|
||||
|
||||
|
||||
def test_get_default_project_directory(config):
|
||||
|
||||
config.clear()
|
||||
|
||||
path = os.path.normpath(os.path.expanduser("~/GNS3/projects"))
|
||||
assert get_default_project_directory() == path
|
||||
assert os.path.exists(path)
|
||||
Reference in new issue
Block a user