Merge branch 'master' into 1.5

This commit is contained in:
Julien Duponchelle committed 2016-02-08 13:14:30 +01:00
commit f6fb0623be
29 files changed
+167 -85

No files matched your search

+4 -4
View File
@@ -61,20 +61,20 @@ class Query:
body = json.dumps(body)
@asyncio.coroutine
def go(future):
def go_request(future):
response = yield from aiohttp.request(method, self.get_url(path, api_version), data=body)
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future))
asyncio.async(go_request(future))
self._loop.run_until_complete(future)
response = future.result()
@asyncio.coroutine
def go(future, response):
def go_read(future, response):
response = yield from response.read()
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future, response))
asyncio.async(go_read(future, response))
self._loop.run_until_complete(future)
response.body = future.result()
x_route = response.headers.get('X-Route', None)
+3 -2
View File
@@ -139,7 +139,8 @@ def test_iou_start(server, vm):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 204
assert response.status == 200
assert response.json["name"] == "PC TEST 1"
def test_iou_start_with_iourc(server, vm, tmpdir):
@@ -148,7 +149,7 @@ def test_iou_start_with_iourc(server, vm, tmpdir):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=body, example=True)
assert mock.called
assert response.status == 204
assert response.status == 200
response = server.get("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert response.status == 200
+2 -1
View File
@@ -114,7 +114,8 @@ def test_qemu_start(server, vm):
with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.start", return_value=True) as mock:
response = server.post("/projects/{project_id}/qemu/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
assert response.status == 200
assert response.json["name"] == "PC TEST 1"
def test_qemu_stop(server, vm):
+2 -1
View File
@@ -102,7 +102,8 @@ def test_vpcs_start(server, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
assert response.status == 200
assert response.json["name"] == "PC TEST 1"
def test_vpcs_stop(server, vm):
+2 -2
View File
@@ -112,11 +112,11 @@ def test_start(loop, vm, monkeypatch):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as mock_exec:
mock_process.returncode = None
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
+2 -1
View File
@@ -50,7 +50,7 @@ def test_get_qemu_version(loop):
def test_binary_list(loop):
files_to_create = ["qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"]
files_to_create = ["qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello", "qemu-system-x86_64-spice"]
for file_to_create in files_to_create:
path = os.path.join(os.environ["PATH"], file_to_create)
@@ -70,6 +70,7 @@ def test_binary_list(loop):
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} in qemus
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86_64-spice"), "version": version} not in qemus
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list(["x86"])))
+2 -1
View File
@@ -112,9 +112,10 @@ def test_is_running(vm, running_subprocess_mock):
def test_start(loop, vm, running_subprocess_mock):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock) as mock:
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running()
assert vm.command_line == ' '.join(mock.call_args[0])
def test_stop(loop, vm, running_subprocess_mock):
+2 -1
View File
@@ -42,7 +42,7 @@ def test_reserve_tcp_port_outside_range():
assert mock_emit.call_args[0][0] == "log.warning"
def test_reserve_tcp_port_already_used():
def test_reserve_tcp_port_already_used_by_another_program():
"""
This test simulate a scenario where the port is already taken
by another programm on the server
@@ -65,6 +65,7 @@ def test_reserve_tcp_port_already_used():
assert port != 2001
assert mock_emit.call_args[0][0] == "log.warning"
def test_reserve_tcp_port_already_used():
"""
This test simulate a scenario where the port is already taken
+7
View File
@@ -102,6 +102,13 @@ def test_changing_path_not_allowed(tmpdir):
p.path = str(tmpdir)
def test_changing_path_with_quote_not_allowed(tmpdir):
with patch("gns3server.modules.project.Project.is_local", return_value=True):
with pytest.raises(aiohttp.web.HTTPForbidden):
p = Project()
p.path = str(tmpdir / "project\"53")
def test_json(tmpdir):
p = Project()
assert p.__json__() == {"name": p.name, "location": p.location, "path": p.path, "project_id": p.id, "temporary": False}
+1
View File
@@ -107,6 +107,7 @@ def test_start(loop, vm):
'-t',
'127.0.0.1')
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
(action, event) = queue.get_nowait()
assert action == "vm.started"
assert event == vm