1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Finish to clean up local setting usage. Ref #1460

This commit is contained in:
grossmj 2022-03-31 12:05:47 +08:00
parent 2cddb2c05a
commit 888c773dc0
7 changed files with 8 additions and 22 deletions

View File

@ -442,14 +442,6 @@ class BaseManager:
return path
raise ImageMissingError(orig_path)
# For local server we allow using absolute path outside image directory
if Config.instance().settings.Server.local is True:
log.debug(f"Searching for '{orig_path}'")
path = force_unix_path(path)
if os.path.exists(path):
return path
raise ImageMissingError(orig_path)
# Check to see if path is an absolute path to a valid directory
path = force_unix_path(path)
for directory in valid_directory_prefices:

View File

@ -30,6 +30,7 @@ pytestmark = pytest.mark.asyncio
async def test_shutdown_local(app: FastAPI, client: AsyncClient, config: Config) -> None:
os.kill = MagicMock()
config.settings.Server.local = True
response = await client.post(app.url_path_for("shutdown"))
assert response.status_code == status.HTTP_204_NO_CONTENT
assert os.kill.called
@ -37,7 +38,6 @@ async def test_shutdown_local(app: FastAPI, client: AsyncClient, config: Config)
async def test_shutdown_non_local(app: FastAPI, client: AsyncClient, config: Config) -> None:
config.settings.Server.local = False
response = await client.post(app.url_path_for("shutdown"))
assert response.status_code == status.HTTP_403_FORBIDDEN

View File

@ -29,7 +29,7 @@ async def test_version_output(app: FastAPI, client: AsyncClient) -> None:
response = await client.get(app.url_path_for("get_version"))
assert response.status_code == status.HTTP_200_OK
assert response.json() == {'controller_host': '127.0.0.1', 'local': True, 'version': __version__}
assert response.json() == {'controller_host': '127.0.0.1', 'local': False, 'version': __version__}
async def test_version_input(app: FastAPI, client: AsyncClient) -> None:

View File

@ -230,6 +230,7 @@ def test_path_relative(vm, fake_iou_bin):
def test_path_invalid_bin(vm, tmpdir, config):
config.settings.Server.images_path = str(tmpdir)
path = str(tmpdir / "test.bin")
with open(path, "w+") as f:

View File

@ -106,16 +106,15 @@ def test_get_abs_image_path_non_local(qemu, tmpdir, config):
# If non local we can't use path outside images directory
config.settings.Server.images_path = str(tmpdir / "images")
config.settings.Server.local = False
assert qemu.get_abs_image_path(path1) == path1
with pytest.raises(NodeError):
qemu.get_abs_image_path(path2)
with pytest.raises(NodeError):
qemu.get_abs_image_path("C:\\test2.bin")
config.settings.Server.images_path = str(tmpdir / "images")
config.settings.Server.local = True
assert qemu.get_abs_image_path(path2) == path2
# config.settings.Server.images_path = str(tmpdir / "images")
# config.settings.Server.local = True
# assert qemu.get_abs_image_path(path2) == path2
def test_get_abs_image_additional_image_paths(qemu, tmpdir, config):
@ -130,7 +129,6 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir, config):
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2")
config.settings.Server.local = False
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
@ -152,7 +150,6 @@ def test_get_abs_image_recursive(qemu, tmpdir, config):
path2 = force_unix_path(str(path2))
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.local = False
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
@ -171,7 +168,6 @@ def test_get_abs_image_recursive_ova(qemu, tmpdir, config):
path2 = force_unix_path(str(path2))
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.local = False
assert qemu.get_abs_image_path("demo/test.ova/test1.bin") == path1
assert qemu.get_abs_image_path("test.ova/test2.bin") == path2
@ -202,7 +198,6 @@ def test_get_relative_image_path(qemu, tmpdir, config):
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.additional_images_paths = str(tmpdir / "images2")
config.settings.Server.local = True
assert qemu.get_relative_image_path(path1) == "test1.bin"
assert qemu.get_relative_image_path("test1.bin") == "test1.bin"
@ -210,7 +205,8 @@ def test_get_relative_image_path(qemu, tmpdir, config):
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
assert qemu.get_relative_image_path(path4) == path4
with pytest.raises(NodeError):
assert qemu.get_relative_image_path(path4) == path4
assert qemu.get_relative_image_path(path5) == path5

View File

@ -392,7 +392,6 @@ def run_around_tests(monkeypatch, config, port_manager):
config.settings.Server.appliances_path = appliances_dir
config.settings.Server.ubridge_path = os.path.join(tmppath, 'bin', 'ubridge')
config.settings.Server.local = True
# Prevent executions of the VM if we forgot to mock something
config.settings.VirtualBox.vboxmanage_path = tmppath

View File

@ -37,7 +37,6 @@ def test_images_directories(tmpdir, config):
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2")
config.settings.Server.local = False
# /tmp/null24564 is ignored because doesn't exists
res = images_directories("qemu")
@ -140,7 +139,6 @@ def test_list_images(tmpdir, config):
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2")
config.settings.Server.local = False
assert list_images("dynamips") == [
{