1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix Qemu VM tests.

This commit is contained in:
grossmj 2018-03-22 14:05:31 +07:00
parent 44f2acffa5
commit 17bfed52f2
2 changed files with 74 additions and 69 deletions

View File

@ -1647,6 +1647,7 @@ class QemuVM(BaseNode):
return ["-nographic"]
return []
@asyncio.coroutine
def _run_with_hardware_acceleration(self, qemu_path, options):
"""
Check if we can run Qemu with hardware acceleration
@ -1717,7 +1718,7 @@ class QemuVM(BaseNode):
command.extend(["-name", self._name])
command.extend(["-m", "{}M".format(self._ram)])
command.extend(["-smp", "cpus={}".format(self._cpus)])
if self._run_with_hardware_acceleration(self.qemu_path, self._options):
if (yield from self._run_with_hardware_acceleration(self.qemu_path, self._options)):
if sys.platform.startswith("linux"):
command.extend(["-enable-kvm"])
version = yield from self.manager.get_qemu_version(self.qemu_path)

View File

@ -73,6 +73,7 @@ def vm(project, manager, fake_qemu_binary, fake_qemu_img_binary):
vm._start_ubridge = AsyncioMagicMock()
vm._ubridge_hypervisor = MagicMock()
vm._ubridge_hypervisor.is_running.return_value = True
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
return vm
@ -513,9 +514,10 @@ def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_mana
"""
Qemu 2.4 introduce an issue with KVM
"""
vm._run_with_kvm = MagicMock(return_value=True)
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.3.2")
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM._run_with_hardware_acceleration", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio = vm._local_udp_tunnels[0][0]
@ -547,9 +549,10 @@ def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_
"""
Qemu 2.4 introduce an issue with KVM
"""
vm._run_with_kvm = MagicMock(return_value=True)
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.4.2")
os.environ["DISPLAY"] = "0:0"
with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM._run_with_hardware_acceleration", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
nio = vm._local_udp_tunnels[0][0]
@ -829,43 +832,44 @@ def test_get_qemu_img_not_exist(vm, tmpdir):
vm._get_qemu_img()
def test_run_with_kvm_darwin(darwin_platform, vm):
def test_run_with_hardware_acceleration_darwin(darwin_platform, vm, loop):
vm.manager.config.set("Qemu", "enable_kvm", False)
assert vm._run_with_kvm("qemu-system-x86_64", "") is False
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
assert loop.run_until_complete(asyncio.ensure_future(vm._run_with_hardware_acceleration("qemu-system-x86_64", ""))) is False
def test_run_with_kvm_windows(windows_platform, vm):
def test_run_with_hardware_acceleration_windows(windows_platform, vm, loop):
vm.manager.config.set("Qemu", "enable_kvm", False)
assert vm._run_with_kvm("qemu-system-x86_64.exe", "") is False
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
assert loop.run_until_complete(asyncio.ensure_future(vm._run_with_hardware_acceleration("qemu-system-x86_64", ""))) is False
def test_run_with_kvm_linux(linux_platform, vm):
def test_run_with_kvm_linux(linux_platform, vm, loop):
with patch("os.path.exists", return_value=True) as os_path:
vm.manager.config.set("Qemu", "enable_kvm", True)
assert vm._run_with_kvm("qemu-system-x86_64", "") is True
assert loop.run_until_complete(asyncio.ensure_future(vm._run_with_hardware_acceleration("qemu-system-x86_64", ""))) is True
os_path.assert_called_with("/dev/kvm")
def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm):
def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm, loop):
with patch("os.path.exists", return_value=True) as os_path:
vm.manager.config.set("Qemu", "enable_kvm", True)
assert vm._run_with_kvm("qemu-system-x86_64", "-no-kvm") is False
assert loop.run_until_complete(asyncio.ensure_future(vm._run_with_hardware_acceleration("qemu-system-x86_64", "-no-kvm"))) is False
def test_run_with_kvm_not_x86(linux_platform, vm):
def test_run_with_kvm_not_x86(linux_platform, vm, loop):
with patch("os.path.exists", return_value=True) as os_path:
vm.manager.config.set("Qemu", "enable_kvm", True)
assert vm._run_with_kvm("qemu-system-arm", "") is False
with pytest.raises(QemuError):
ret = loop.run_until_complete(asyncio.ensure_future(vm._run_with_hardware_acceleration("qemu-system-arm", "")))
def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm):
def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm, loop):
with patch("os.path.exists", return_value=False) as os_path:
vm.manager.config.set("Qemu", "enable_kvm", True)
with pytest.raises(QemuError):
vm._run_with_kvm("qemu-system-x86_64", "")
ret = loop.run_until_complete(asyncio.ensure_future(vm._run_with_hardware_acceleration("qemu-system-x86_64", "")))