mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 14:51:13 +02:00
1 parent
fba049767a
commit
d184b65800
5 files changed
+58
-9
No files matched your search
@@ -200,11 +200,24 @@ def test_qemu_list_binaries(server, vm):
|
||||
{"path": "/tmp/2", "version": "2.1.0"}]
|
||||
with asyncio_patch("gns3server.modules.qemu.Qemu.binary_list", return_value=ret) as mock:
|
||||
response = server.get("/qemu/binaries".format(project_id=vm["project_id"]), example=True)
|
||||
assert mock.called
|
||||
assert mock.called_with(None)
|
||||
assert response.status == 200
|
||||
assert response.json == ret
|
||||
|
||||
|
||||
def test_qemu_list_binaries_filter(server, vm):
|
||||
ret = [
|
||||
{"path": "/tmp/x86_64", "version": "2.2.0"},
|
||||
{"path": "/tmp/alpha", "version": "2.1.0"},
|
||||
{"path": "/tmp/i386", "version": "2.1.0"}
|
||||
]
|
||||
with asyncio_patch("gns3server.modules.qemu.Qemu.binary_list", return_value=ret) as mock:
|
||||
response = server.get("/qemu/binaries".format(project_id=vm["project_id"]), body={"archs": ["i386"]}, example=True)
|
||||
assert response.status == 200
|
||||
assert mock.called_with(["i386"])
|
||||
assert response.json == ret
|
||||
|
||||
|
||||
def test_vms(server, tmpdir, fake_qemu_vm):
|
||||
|
||||
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir), example=True):
|
||||
@@ -312,3 +325,9 @@ def test_create_img_absolute_local(server):
|
||||
response = server.post("/qemu/img", body=body, example=True)
|
||||
|
||||
assert response.status == 201
|
||||
|
||||
|
||||
def test_capabilities(server):
|
||||
with asyncio_patch("gns3server.modules.Qemu.get_kvm_archs", return_value=["x86_64"]):
|
||||
response = server.get("/qemu/capabilities", example=True)
|
||||
assert response.json["kvm"] == ["x86_64"]
|
||||
@@ -20,6 +20,7 @@ import stat
|
||||
import asyncio
|
||||
import sys
|
||||
import pytest
|
||||
import platform
|
||||
|
||||
from gns3server.modules.qemu import Qemu
|
||||
from gns3server.modules.qemu.qemu_error import QemuError
|
||||
@@ -174,3 +175,21 @@ def test_create_image_exist(loop, tmpdir, fake_qemu_img_binary):
|
||||
with pytest.raises(QemuError):
|
||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
||||
assert not process.called
|
||||
|
||||
|
||||
def test_get_kvm_archs_no_kvm(loop):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", side_effect=FileNotFoundError('kvm-ok')):
|
||||
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
|
||||
assert archs == []
|
||||
|
||||
|
||||
def test_get_kvm_archs_kvm_ok(loop):
|
||||
|
||||
process = MagicMock()
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
process.returncode = 0
|
||||
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
|
||||
if platform.machine() == 'x86_64':
|
||||
assert archs == ['x86_64', 'i386']
|
||||
else:
|
||||
assert archs == platform.machine()
|
||||
@@ -50,6 +50,11 @@ class _asyncio_patch:
|
||||
future = asyncio.Future()
|
||||
if "return_value" in self.kwargs:
|
||||
future.set_result(self.kwargs["return_value"])
|
||||
elif "side_effect" in self.kwargs:
|
||||
if isinstance(self.kwargs["side_effect"], Exception):
|
||||
future.set_exception(self.kwargs["side_effect"])
|
||||
else:
|
||||
raise NotImplementedError
|
||||
else:
|
||||
future.set_result(True)
|
||||
return future
|
||||
|
||||
Reference in new issue
Block a user