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

Merge remote-tracking branch 'origin/3.0' into 3.0

This commit is contained in:
grossmj 2023-08-19 12:29:53 +10:00
commit 74cb3be910
2 changed files with 34 additions and 28 deletions

View File

@ -219,10 +219,10 @@ async def test_install_busybox():
mock_process.returncode = 1 # means that busybox is not dynamically linked mock_process.returncode = 1 # means that busybox is not dynamically linked
mock_process.communicate = AsyncioMagicMock(return_value=(b"", b"not a dynamic executable")) mock_process.communicate = AsyncioMagicMock(return_value=(b"", b"not a dynamic executable"))
with patch("os.path.isfile", return_value=False): with patch("gns3server.compute.docker.os.path.isfile", return_value=False):
with patch("shutil.which", return_value="/usr/bin/busybox"): with patch("gns3server.compute.docker.shutil.which", return_value="/usr/bin/busybox"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as create_subprocess_mock: with asyncio_patch("gns3server.compute.docker.asyncio.create_subprocess_exec", return_value=mock_process) as create_subprocess_mock:
with patch("shutil.copy2") as copy2_mock: with patch("gns3server.compute.docker.shutil.copy2") as copy2_mock:
await Docker.install_busybox() await Docker.install_busybox()
create_subprocess_mock.assert_called_with( create_subprocess_mock.assert_called_with(
"ldd", "ldd",
@ -241,8 +241,8 @@ async def test_install_busybox_dynamic_linked():
mock_process.communicate = AsyncioMagicMock(return_value=(b"Dynamically linked library", b"")) mock_process.communicate = AsyncioMagicMock(return_value=(b"Dynamically linked library", b""))
with patch("os.path.isfile", return_value=False): with patch("os.path.isfile", return_value=False):
with patch("shutil.which", return_value="/usr/bin/busybox"): with patch("gns3server.compute.docker.shutil.which", return_value="/usr/bin/busybox"):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process): with asyncio_patch("gns3server.compute.docker.asyncio.create_subprocess_exec", return_value=mock_process):
with pytest.raises(DockerError) as e: with pytest.raises(DockerError) as e:
await Docker.install_busybox() await Docker.install_busybox()
assert str(e.value) == "No busybox executable could be found" assert str(e.value) == "No busybox executable could be found"
@ -251,8 +251,8 @@ async def test_install_busybox_dynamic_linked():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_install_busybox_no_executables(): async def test_install_busybox_no_executables():
with patch("os.path.isfile", return_value=False): with patch("gns3server.compute.docker.os.path.isfile", return_value=False):
with patch("shutil.which", return_value=None): with patch("gns3server.compute.docker.shutil.which", return_value=None):
with pytest.raises(DockerError) as e: with pytest.raises(DockerError) as e:
await Docker.install_busybox() await Docker.install_busybox()
assert str(e.value) == "No busybox executable could be found" assert str(e.value) == "No busybox executable could be found"

View File

@ -21,6 +21,8 @@ import pytest
import pytest_asyncio import pytest_asyncio
import uuid import uuid
import os import os
from unittest.mock import patch
from tests.utils import asyncio_patch, AsyncioMagicMock from tests.utils import asyncio_patch, AsyncioMagicMock
from gns3server.compute.ubridge.ubridge_error import UbridgeNamespaceError from gns3server.compute.ubridge.ubridge_error import UbridgeNamespaceError
@ -1072,6 +1074,7 @@ async def test_start(vm, manager, free_console_port):
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"}) nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
await vm.adapter_add_nio_binding(0, nio) await vm.adapter_add_nio_binding(0, nio)
with patch("gns3server.compute.docker.Docker.install_busybox"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
await vm.start() await vm.start()
@ -1092,6 +1095,7 @@ async def test_start_namespace_failed(vm, manager, free_console_port):
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"}) nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
await vm.adapter_add_nio_binding(0, nio) await vm.adapter_add_nio_binding(0, nio)
with patch("gns3server.compute.docker.Docker.install_busybox"):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
with asyncio_patch("gns3server.compute.docker.DockerVM._start_ubridge") as mock_start_ubridge: with asyncio_patch("gns3server.compute.docker.DockerVM._start_ubridge") as mock_start_ubridge:
@ -1117,6 +1121,7 @@ async def test_start_without_nio(vm):
assert vm.status != "started" assert vm.status != "started"
vm.adapters = 1 vm.adapters = 1
with patch("gns3server.compute.docker.Docker.install_busybox"):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
with asyncio_patch("gns3server.compute.docker.DockerVM._start_ubridge") as mock_start_ubridge: with asyncio_patch("gns3server.compute.docker.DockerVM._start_ubridge") as mock_start_ubridge:
@ -1135,6 +1140,7 @@ async def test_start_without_nio(vm):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_start_unpause(vm): async def test_start_unpause(vm):
with patch("gns3server.compute.docker.Docker.install_busybox"):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock: with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock:
await vm.start() await vm.start()