diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 3a823d1d..06ae501c 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -299,7 +299,7 @@ class Compute: response = yield from self._session().request("GET", url, auth=self._auth) if response.status == 404: raise aiohttp.web.HTTPNotFound(text="{} not found on compute".format(path)) - return response.content + return response @asyncio.coroutine def stream_file(self, project, path): diff --git a/gns3server/controller/export_project.py b/gns3server/controller/export_project.py index 2098eb3f..97ad8144 100644 --- a/gns3server/controller/export_project.py +++ b/gns3server/controller/export_project.py @@ -75,12 +75,13 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id if not _filter_files(compute_file["path"]): (fd, temp_path) = tempfile.mkstemp(dir=temporary_dir) f = open(fd, "wb", closefd=True) - stream = yield from compute.download_file(project, compute_file["path"]) + response = yield from compute.download_file(project, compute_file["path"]) while True: - data = yield from stream.read(512) + data = yield from response.content.read(512) if not data: break f.write(data) + response.close() f.close() z.write(temp_path, arcname=compute_file["path"], compress_type=zipfile.ZIP_DEFLATED) return z diff --git a/tests/controller/test_export_project.py b/tests/controller/test_export_project.py index b25fb1d5..76691656 100644 --- a/tests/controller/test_export_project.py +++ b/tests/controller/test_export_project.py @@ -127,10 +127,11 @@ def test_export_vm(tmpdir, project, async_run, controller): compute.list_files = AsyncioMagicMock(return_value=[{"path": "vm-1/dynamips/test"}]) # Fake file that will be download from the vm - file_content = AsyncioBytesIO() - async_run(file_content.write(b"HELLO")) - file_content.seek(0) - compute.download_file = AsyncioMagicMock(return_value=file_content) + mock_response = AsyncioMagicMock() + mock_response.content = AsyncioBytesIO() + async_run(mock_response.content.write(b"HELLO")) + mock_response.content.seek(0) + compute.download_file = AsyncioMagicMock(return_value=mock_response) project._project_created_on_compute.add(compute)