mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-31 05:13:49 +02:00
Fix test on Windows
Sadly python crash on my Windows and I can't run the full test suite. Fix #377
This commit is contained in:
parent
ad4501838b
commit
480ca037cd
@ -426,6 +426,8 @@ class BaseManager:
|
|||||||
# For non local server we disallow using absolute path outside image directory
|
# For non local server we disallow using absolute path outside image directory
|
||||||
if Config.instance().get_section_config("Server").get("local", False) is False:
|
if Config.instance().get_section_config("Server").get("local", False) is False:
|
||||||
img_directory = self.config.get_section_config("Server").get("images_path", os.path.expanduser("~/GNS3/images"))
|
img_directory = self.config.get_section_config("Server").get("images_path", os.path.expanduser("~/GNS3/images"))
|
||||||
|
img_directory = force_unix_path(img_directory)
|
||||||
|
path = force_unix_path(path)
|
||||||
if len(os.path.commonprefix([img_directory, path])) < len(img_directory):
|
if len(os.path.commonprefix([img_directory, path])) < len(img_directory):
|
||||||
raise VMError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))
|
raise VMError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))
|
||||||
|
|
||||||
@ -443,8 +445,8 @@ class BaseManager:
|
|||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
return ""
|
return ""
|
||||||
img_directory = self.get_images_directory()
|
img_directory = force_unix_path(self.get_images_directory())
|
||||||
path = self.get_abs_image_path(path)
|
path = force_unix_path(self.get_abs_image_path(path))
|
||||||
if os.path.commonprefix([img_directory, path]) == img_directory:
|
if os.path.commonprefix([img_directory, path]) == img_directory:
|
||||||
return os.path.relpath(path, img_directory)
|
return os.path.relpath(path, img_directory)
|
||||||
return path
|
return path
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import stat
|
import stat
|
||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
@ -26,6 +27,9 @@ from gns3server.config import Config
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_qemu_bin():
|
def fake_qemu_bin():
|
||||||
|
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64w.exe")
|
||||||
|
else:
|
||||||
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64")
|
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64")
|
||||||
with open(bin_path, "w+") as f:
|
with open(bin_path, "w+") as f:
|
||||||
f.write("1")
|
f.write("1")
|
||||||
|
@ -24,6 +24,7 @@ from unittest.mock import patch
|
|||||||
from gns3server.modules.vpcs import VPCS
|
from gns3server.modules.vpcs import VPCS
|
||||||
from gns3server.modules.qemu import Qemu
|
from gns3server.modules.qemu import Qemu
|
||||||
from gns3server.modules.vm_error import VMError
|
from gns3server.modules.vm_error import VMError
|
||||||
|
from gns3server.utils import force_unix_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
@ -89,10 +90,10 @@ def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
|
|||||||
|
|
||||||
def test_get_abs_image_path(qemu, tmpdir):
|
def test_get_abs_image_path(qemu, tmpdir):
|
||||||
os.makedirs(str(tmpdir / "QEMU"))
|
os.makedirs(str(tmpdir / "QEMU"))
|
||||||
path1 = str(tmpdir / "test1.bin")
|
path1 = force_unix_path(str(tmpdir / "test1.bin"))
|
||||||
open(path1, 'w+').close()
|
open(path1, 'w+').close()
|
||||||
|
|
||||||
path2 = str(tmpdir / "QEMU" / "test2.bin")
|
path2 = force_unix_path(str(tmpdir / "QEMU" / "test2.bin"))
|
||||||
open(path2, 'w+').close()
|
open(path2, 'w+').close()
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
||||||
@ -106,11 +107,11 @@ def test_get_abs_image_path(qemu, tmpdir):
|
|||||||
def test_get_abs_image_path_non_local(qemu, tmpdir):
|
def test_get_abs_image_path_non_local(qemu, tmpdir):
|
||||||
path1 = tmpdir / "images" / "QEMU" / "test1.bin"
|
path1 = tmpdir / "images" / "QEMU" / "test1.bin"
|
||||||
path1.write("1", ensure=True)
|
path1.write("1", ensure=True)
|
||||||
path1 = str(path1)
|
path1 = force_unix_path(str(path1))
|
||||||
|
|
||||||
path2 = tmpdir / "private" / "QEMU" / "test2.bin"
|
path2 = tmpdir / "private" / "QEMU" / "test2.bin"
|
||||||
path2.write("1", ensure=True)
|
path2.write("1", ensure=True)
|
||||||
path2 = str(path2)
|
path2 = force_unix_path(str(path2))
|
||||||
|
|
||||||
# If non local we can't use path outside images directory
|
# If non local we can't use path outside images directory
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": False}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": False}):
|
||||||
@ -126,10 +127,10 @@ def test_get_abs_image_path_non_local(qemu, tmpdir):
|
|||||||
|
|
||||||
def test_get_relative_image_path(qemu, tmpdir):
|
def test_get_relative_image_path(qemu, tmpdir):
|
||||||
os.makedirs(str(tmpdir / "QEMU"))
|
os.makedirs(str(tmpdir / "QEMU"))
|
||||||
path1 = str(tmpdir / "test1.bin")
|
path1 = force_unix_path(str(tmpdir / "test1.bin"))
|
||||||
open(path1, 'w+').close()
|
open(path1, 'w+').close()
|
||||||
|
|
||||||
path2 = str(tmpdir / "QEMU" / "test2.bin")
|
path2 = force_unix_path(str(tmpdir / "QEMU" / "test2.bin"))
|
||||||
open(path2, 'w+').close()
|
open(path2, 'w+').close()
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
||||||
|
Loading…
Reference in New Issue
Block a user