mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 23:01:15 +02:00
Merge branch '2.1' into remove_use_ubrige
This commit is contained in:
commit
9e2759a3f2
24 files changed
+502
-59
No files matched your search
@@ -17,10 +17,10 @@
|
||||
|
||||
import pytest
|
||||
import asyncio
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
from gns3server.compute.docker import Docker
|
||||
from gns3server.compute.docker import Docker, DOCKER_PREFERRED_API_VERSION, DOCKER_MINIMUM_API_VERSION
|
||||
from gns3server.compute.docker.docker_error import DockerError, DockerHttp404Error
|
||||
|
||||
|
||||
@@ -162,3 +162,40 @@ def test_pull_image(loop):
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||
images = loop.run_until_complete(asyncio.async(Docker.instance().pull_image("ubuntu")))
|
||||
mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}, timeout=None)
|
||||
|
||||
|
||||
def test_docker_check_connection_docker_minimum_version(vm, loop):
|
||||
response = {
|
||||
'ApiVersion': '1.01',
|
||||
'Version': '1.12'
|
||||
}
|
||||
|
||||
with patch("gns3server.compute.docker.Docker.connector"), \
|
||||
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||
vm._connected = False
|
||||
with pytest.raises(DockerError):
|
||||
loop.run_until_complete(asyncio.async(vm._check_connection()))
|
||||
|
||||
|
||||
def test_docker_check_connection_docker_preferred_version_against_newer(vm, loop):
|
||||
response = {
|
||||
'ApiVersion': '1.31'
|
||||
}
|
||||
|
||||
with patch("gns3server.compute.docker.Docker.connector"), \
|
||||
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||
vm._connected = False
|
||||
loop.run_until_complete(asyncio.async(vm._check_connection()))
|
||||
assert vm._api_version == DOCKER_PREFERRED_API_VERSION
|
||||
|
||||
|
||||
def test_docker_check_connection_docker_preferred_version_against_older(vm, loop):
|
||||
response = {
|
||||
'ApiVersion': '1.27',
|
||||
}
|
||||
|
||||
with patch("gns3server.compute.docker.Docker.connector"), \
|
||||
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||
vm._connected = False
|
||||
loop.run_until_complete(asyncio.async(vm._check_connection()))
|
||||
assert vm._api_version == DOCKER_MINIMUM_API_VERSION
|
||||
@@ -15,6 +15,7 @@
|
||||
# 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 aiohttp
|
||||
import asyncio
|
||||
import pytest
|
||||
import uuid
|
||||
@@ -904,3 +905,27 @@ def test_fix_permission(vm, loop):
|
||||
loop.run_until_complete(vm._fix_permissions())
|
||||
mock_exec.assert_called_with('docker', 'exec', 'e90e34656842', '/gns3/bin/busybox', 'sh', '-c', '(/gns3/bin/busybox find "/etc" -depth -print0 | /gns3/bin/busybox xargs -0 /gns3/bin/busybox stat -c \'%a:%u:%g:%n\' > "/etc/.gns3_perms") && /gns3/bin/busybox chmod -R u+rX "/etc" && /gns3/bin/busybox chown {}:{} -R "/etc"'.format(os.getuid(), os.getgid()))
|
||||
assert process.wait.called
|
||||
|
||||
|
||||
def test_read_console_output_with_binary_mode(vm, loop):
|
||||
class InputStreamMock(object):
|
||||
def __init__(self):
|
||||
self.sent = False
|
||||
|
||||
@asyncio.coroutine
|
||||
def receive(self):
|
||||
if not self.sent:
|
||||
self.sent = True
|
||||
return MagicMock(tp=aiohttp.WSMsgType.BINARY, data=b"test")
|
||||
else:
|
||||
return MagicMock(tp=aiohttp.WSMsgType.CLOSE)
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
input_stream = InputStreamMock()
|
||||
output_stream = MagicMock()
|
||||
|
||||
with asyncio_patch('gns3server.compute.docker.docker_vm.DockerVM.stop'):
|
||||
loop.run_until_complete(asyncio.async(vm._read_console_output(input_stream, output_stream)))
|
||||
output_stream.feed_data.assert_called_once_with(b"test")
|
||||
@@ -133,15 +133,27 @@ def test_update_ubridge_udp_connection(node, async_run):
|
||||
snio = NIOUDP(1245, "localhost", 1246, [])
|
||||
dnio = NIOUDP(1245, "localhost", 1244, filters)
|
||||
with asyncio_patch("gns3server.compute.base_node.BaseNode._ubridge_apply_filters") as mock:
|
||||
async_run(node._update_ubridge_udp_connection('VPCS-10', snio, dnio))
|
||||
async_run(node.update_ubridge_udp_connection('VPCS-10', snio, dnio))
|
||||
mock.assert_called_with("VPCS-10", filters)
|
||||
|
||||
|
||||
def test_ubridge_apply_filters(node, async_run):
|
||||
filters = {
|
||||
"latency": [10]
|
||||
"latency": [10],
|
||||
"bpf": ["icmp[icmptype] == 8\ntcp src port 53"]
|
||||
}
|
||||
node._ubridge_send = AsyncioMagicMock()
|
||||
async_run(node._ubridge_apply_filters("VPCS-10", filters))
|
||||
node._ubridge_send.assert_any_call("bridge reset_packet_filters VPCS-10")
|
||||
node._ubridge_send.assert_any_call("bridge add_packet_filter VPCS-10 filter0 latency 10")
|
||||
|
||||
|
||||
def test_ubridge_apply_bpf_filters(node, async_run):
|
||||
filters = {
|
||||
"bpf": ["icmp[icmptype] == 8\ntcp src port 53"]
|
||||
}
|
||||
node._ubridge_send = AsyncioMagicMock()
|
||||
async_run(node._ubridge_apply_filters("VPCS-10", filters))
|
||||
node._ubridge_send.assert_any_call("bridge reset_packet_filters VPCS-10")
|
||||
node._ubridge_send.assert_any_call("bridge add_packet_filter VPCS-10 filter0 bpf \"icmp[icmptype] == 8\"")
|
||||
node._ubridge_send.assert_any_call("bridge add_packet_filter VPCS-10 filter1 bpf \"tcp src port 53\"")
|
||||
Reference in new issue
Block a user