mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-02-06 16:23:49 +02:00
Fix uploads of large images
Fix https://github.com/GNS3/gns3-gui/issues/1552
This commit is contained in:
parent
8299ce800d
commit
04aec4619f
@ -424,12 +424,24 @@ class Compute:
|
|||||||
if hasattr(data, '__json__'):
|
if hasattr(data, '__json__'):
|
||||||
data = json.dumps(data.__json__())
|
data = json.dumps(data.__json__())
|
||||||
# Stream the request
|
# Stream the request
|
||||||
elif isinstance(data, aiohttp.streams.StreamReader) or isinstance(data, io.BufferedIOBase) or isinstance(data, bytes):
|
elif isinstance(data, aiohttp.streams.StreamReader) or isinstance(data, bytes):
|
||||||
chunked = True
|
chunked = True
|
||||||
headers['content-type'] = 'application/octet-stream'
|
headers['content-type'] = 'application/octet-stream'
|
||||||
|
# If the data is an open file we will iterate on it
|
||||||
|
elif isinstance(data, io.BufferedIOBase):
|
||||||
|
chunked = True
|
||||||
|
headers['content-type'] = 'application/octet-stream'
|
||||||
|
|
||||||
|
def send_data(f):
|
||||||
|
while True:
|
||||||
|
chunk = f.read(1024)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
data = send_data(data)
|
||||||
else:
|
else:
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
|
|
||||||
response = yield from self._session().request(method, url, headers=headers, data=data, auth=self._auth, chunked=chunked)
|
response = yield from self._session().request(method, url, headers=headers, data=data, auth=self._auth, chunked=chunked)
|
||||||
body = yield from response.read()
|
body = yield from response.read()
|
||||||
if body and not raw:
|
if body and not raw:
|
||||||
|
@ -273,9 +273,9 @@ class Node:
|
|||||||
data = self._node_data()
|
data = self._node_data()
|
||||||
data["node_id"] = self._id
|
data["node_id"] = self._id
|
||||||
if self._node_type == "docker":
|
if self._node_type == "docker":
|
||||||
timeout = 60
|
|
||||||
else:
|
|
||||||
timeout = None
|
timeout = None
|
||||||
|
else:
|
||||||
|
timeout = 120
|
||||||
trial = 0
|
trial = 0
|
||||||
while trial != 6:
|
while trial != 6:
|
||||||
try:
|
try:
|
||||||
|
@ -161,7 +161,7 @@ def test_create(node, compute, project, async_run):
|
|||||||
"startup_script": "echo test",
|
"startup_script": "echo test",
|
||||||
"name": "demo"
|
"name": "demo"
|
||||||
}
|
}
|
||||||
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data)
|
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data, timeout=120)
|
||||||
assert node._console == 2048
|
assert node._console == 2048
|
||||||
assert node._properties == {"startup_script": "echo test"}
|
assert node._properties == {"startup_script": "echo test"}
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ def test_create_without_console(node, compute, project, async_run):
|
|||||||
"startup_script": "echo test",
|
"startup_script": "echo test",
|
||||||
"name": "demo"
|
"name": "demo"
|
||||||
}
|
}
|
||||||
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data)
|
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data, timeout=120)
|
||||||
assert node._console == 2048
|
assert node._console == 2048
|
||||||
assert node._properties == {"test_value": "success", "startup_script": "echo test"}
|
assert node._properties == {"test_value": "success", "startup_script": "echo test"}
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ def test_init_path(tmpdir):
|
|||||||
p = Project(path=str(tmpdir), project_id=str(uuid4()), name="Test")
|
p = Project(path=str(tmpdir), project_id=str(uuid4()), name="Test")
|
||||||
assert p.path == str(tmpdir)
|
assert p.path == str(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||||
def test_changing_path_with_quote_not_allowed(tmpdir):
|
def test_changing_path_with_quote_not_allowed(tmpdir):
|
||||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||||
@ -147,7 +148,8 @@ def test_add_node_local(async_run, controller):
|
|||||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||||
data={'node_id': node.id,
|
data={'node_id': node.id,
|
||||||
'startup_config': 'test.cfg',
|
'startup_config': 'test.cfg',
|
||||||
'name': 'test'})
|
'name': 'test'},
|
||||||
|
timeout=120)
|
||||||
assert compute in project._project_created_on_compute
|
assert compute in project._project_created_on_compute
|
||||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||||
|
|
||||||
@ -174,7 +176,8 @@ def test_add_node_non_local(async_run, controller):
|
|||||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||||
data={'node_id': node.id,
|
data={'node_id': node.id,
|
||||||
'startup_config': 'test.cfg',
|
'startup_config': 'test.cfg',
|
||||||
'name': 'test'})
|
'name': 'test'},
|
||||||
|
timeout=120)
|
||||||
assert compute in project._project_created_on_compute
|
assert compute in project._project_created_on_compute
|
||||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user