diff --git a/gns3server/handlers/api/controller/project_handler.py b/gns3server/handlers/api/controller/project_handler.py index 27ffbe2a..46e17661 100644 --- a/gns3server/handlers/api/controller/project_handler.py +++ b/gns3server/handlers/api/controller/project_handler.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import os +import sys import aiohttp import asyncio import tempfile @@ -333,14 +334,25 @@ class ProjectHandler: # We write the content to a temporary location and after we extract it all. # It could be more optimal to stream this but it is not implemented in Python. # Spooled means the file is temporary kept in memory until max_size is reached + # Cannot use tempfile.SpooledTemporaryFile(max_size=10000) in Python 3.7 due + # to a bug https://bugs.python.org/issue26175 try: - with tempfile.SpooledTemporaryFile(max_size=10000) as temp: - while True: - chunk = yield from request.content.read(1024) - if not chunk: - break - temp.write(chunk) - project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name) + if sys.version_info >= (3, 7) and sys.version_info < (3, 8): + with tempfile.TemporaryFile() as temp: + while True: + chunk = yield from request.content.read(1024) + if not chunk: + break + temp.write(chunk) + project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name) + else: + with tempfile.SpooledTemporaryFile(max_size=10000) as temp: + while True: + chunk = yield from request.content.read(1024) + if not chunk: + break + temp.write(chunk) + project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name) except OSError as e: raise aiohttp.web.HTTPInternalServerError(text="Could not import the project: {}".format(e)) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 90347176..07dbed25 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -150,9 +150,9 @@ def test_termination_callback(vm, async_run): async_run(vm._termination_callback(0)) assert vm.status == "stopped" - async_run(queue.get(0)) #  Ping + async_run(queue.get(1)) #  Ping - (action, event, kwargs) = async_run(queue.get(0)) + (action, event, kwargs) = async_run(queue.get(1)) assert action == "node.updated" assert event == vm @@ -170,7 +170,7 @@ def test_termination_callback_error(vm, tmpdir, async_run): async_run(vm._termination_callback(1)) assert vm.status == "stopped" - async_run(queue.get(0)) # Ping + async_run(queue.get(1)) # Ping (action, event, kwargs) = queue.get_nowait() assert action == "node.updated" diff --git a/tests/compute/traceng/test_traceng_vm.py b/tests/compute/traceng/test_traceng_vm.py index 974555fe..2f2133ef 100644 --- a/tests/compute/traceng/test_traceng_vm.py +++ b/tests/compute/traceng/test_traceng_vm.py @@ -66,7 +66,7 @@ def test_start(loop, vm, async_run): process.returncode = None with NotificationManager.instance().queue() as queue: - async_run(queue.get(0)) # Ping + async_run(queue.get(1)) # Ping vm.ip_address = "192.168.1.1" with patch("sys.platform", return_value="win"): @@ -88,7 +88,7 @@ def test_start(loop, vm, async_run): '192.168.1.2') assert vm.is_running() assert vm.command_line == ' '.join(mock_exec.call_args[0]) - (action, event, kwargs) = async_run(queue.get(0)) + (action, event, kwargs) = async_run(queue.get(1)) assert action == "node.updated" assert event == vm @@ -120,10 +120,10 @@ def test_stop(loop, vm, async_run): process.terminate.assert_called_with() - async_run(queue.get(0)) #  Ping - async_run(queue.get(0)) #  Started + async_run(queue.get(1)) #  Ping + async_run(queue.get(1)) #  Started - (action, event, kwargs) = async_run(queue.get(0)) + (action, event, kwargs) = async_run(queue.get(1)) assert action == "node.updated" assert event == vm diff --git a/tests/compute/vpcs/test_vpcs_vm.py b/tests/compute/vpcs/test_vpcs_vm.py index f7862516..238b1d52 100644 --- a/tests/compute/vpcs/test_vpcs_vm.py +++ b/tests/compute/vpcs/test_vpcs_vm.py @@ -91,7 +91,7 @@ def test_start(loop, vm, async_run): process.returncode = None with NotificationManager.instance().queue() as queue: - async_run(queue.get(0)) # Ping + async_run(queue.get(1)) # Ping with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec: @@ -113,7 +113,7 @@ def test_start(loop, vm, async_run): '127.0.0.1') assert vm.is_running() assert vm.command_line == ' '.join(mock_exec.call_args[0]) - (action, event, kwargs) = async_run(queue.get(0)) + (action, event, kwargs) = async_run(queue.get(1)) assert action == "node.updated" assert event == vm @@ -177,10 +177,10 @@ def test_stop(loop, vm, async_run): else: process.terminate.assert_called_with() - async_run(queue.get(0)) #  Ping - async_run(queue.get(0)) #  Started + async_run(queue.get(1)) #  Ping + async_run(queue.get(1)) #  Started - (action, event, kwargs) = async_run(queue.get(0)) + (action, event, kwargs) = async_run(queue.get(1)) assert action == "node.updated" assert event == vm