From 45edc40948b07916803aaa94185b47d98405d4cf Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 10 Jun 2018 21:18:16 +0700 Subject: [PATCH] Timeout for stream file. --- gns3server/controller/compute.py | 5 +++-- tests/controller/test_compute.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 3cb52142..c07eb8f7 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -337,12 +337,13 @@ class Compute: return response @asyncio.coroutine - def stream_file(self, project, path): + def stream_file(self, project, path, timeout=None): """ Read file of a project and stream it :param project: A project object :param path: The path of the file in the project + :param timeout: timeout :returns: A file stream """ @@ -361,7 +362,7 @@ class Compute: self._response.close() url = self._getUrl("/projects/{}/stream/{}".format(project.id, path)) - response = yield from self._session().request("GET", url, auth=self._auth, timeout=None) + response = yield from self._session().request("GET", url, auth=self._auth, timeout=timeout) if response.status == 404: raise aiohttp.web.HTTPNotFound(text="{} not found on compute".format(path)) elif response.status == 403: diff --git a/tests/controller/test_compute.py b/tests/controller/test_compute.py index 2bbd3d9f..47840bc9 100644 --- a/tests/controller/test_compute.py +++ b/tests/controller/test_compute.py @@ -295,8 +295,8 @@ def test_streamFile(project, async_run, compute): response = MagicMock() response.status = 200 with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock: - async_run(compute.stream_file(project, "test/titi")) - mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/stream/test/titi".format(project.id), auth=None, timeout=None) + async_run(compute.stream_file(project, "test/titi", timeout=120)) + mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/stream/test/titi".format(project.id), auth=None, timeout=120) def test_downloadFile(project, async_run, compute):