mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Timeout for stream file.
This commit is contained in:
parent
34fcbd68f3
commit
45edc40948
@ -337,12 +337,13 @@ class Compute:
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def stream_file(self, project, path):
|
def stream_file(self, project, path, timeout=None):
|
||||||
"""
|
"""
|
||||||
Read file of a project and stream it
|
Read file of a project and stream it
|
||||||
|
|
||||||
:param project: A project object
|
:param project: A project object
|
||||||
:param path: The path of the file in the project
|
:param path: The path of the file in the project
|
||||||
|
:param timeout: timeout
|
||||||
:returns: A file stream
|
:returns: A file stream
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -361,7 +362,7 @@ class Compute:
|
|||||||
self._response.close()
|
self._response.close()
|
||||||
|
|
||||||
url = self._getUrl("/projects/{}/stream/{}".format(project.id, path))
|
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:
|
if response.status == 404:
|
||||||
raise aiohttp.web.HTTPNotFound(text="{} not found on compute".format(path))
|
raise aiohttp.web.HTTPNotFound(text="{} not found on compute".format(path))
|
||||||
elif response.status == 403:
|
elif response.status == 403:
|
||||||
|
@ -295,8 +295,8 @@ def test_streamFile(project, async_run, compute):
|
|||||||
response = MagicMock()
|
response = MagicMock()
|
||||||
response.status = 200
|
response.status = 200
|
||||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
async_run(compute.stream_file(project, "test/titi"))
|
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=None)
|
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):
|
def test_downloadFile(project, async_run, compute):
|
||||||
|
Loading…
Reference in New Issue
Block a user