From 2bbdbeaa8278dbb1be6974c1d5c864055812ffc1 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 21 Sep 2016 19:25:15 +0200 Subject: [PATCH] Workaround a bug with KVM, Qemu >= 2.4 and Intel CPU Fix #685 --- gns3server/modules/qemu/qemu_vm.py | 5 +++ tests/modules/qemu/test_qemu_vm.py | 61 +++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index d7d5bba1..2fd91e37 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -1424,6 +1424,11 @@ class QemuVM(BaseVM): command.extend(["-smp", "cpus={}".format(self._cpus)]) if self._run_with_kvm(self.qemu_path, self._options): command.extend(["-enable-kvm"]) + version = yield from self.manager.get_qemu_version(self.qemu_path) + # Issue on some combo Intel CPU + KVM + Qemu 2.4.0 + # https://github.com/GNS3/gns3-server/issues/685 + if version and parse_version(version) >= parse_version("2.4.0"): + command.extend(["-machine smm=off"]) command.extend(["-boot", "order={}".format(self._boot_priority)]) cdrom_option = self._cdrom_option() command.extend(cdrom_option) diff --git a/tests/modules/qemu/test_qemu_vm.py b/tests/modules/qemu/test_qemu_vm.py index 0c0a3f3c..bd772cf0 100644 --- a/tests/modules/qemu/test_qemu_vm.py +++ b/tests/modules/qemu/test_qemu_vm.py @@ -22,7 +22,7 @@ import os import sys import stat import re -from tests.utils import asyncio_patch +from tests.utils import asyncio_patch, AsyncioMagicMock from unittest import mock @@ -434,6 +434,65 @@ def test_build_command(vm, loop, fake_qemu_binary, port_manager): ] +def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_manager): + """ + 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("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: + cmd = loop.run_until_complete(asyncio.async(vm._build_command())) + assert cmd == [ + fake_qemu_binary, + "-name", + "test", + "-m", + "256M", + "-smp", + "cpus=1", + "-enable-kvm", + "-boot", + "order=c", + "-serial", + "telnet:127.0.0.1:{},server,nowait".format(vm.console), + "-net", + "none", + "-device", + "e1000,mac={}".format(vm._mac_address) + ] + + +def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_manager): + """ + 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("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: + cmd = loop.run_until_complete(asyncio.async(vm._build_command())) + assert cmd == [ + fake_qemu_binary, + "-name", + "test", + "-m", + "256M", + "-smp", + "cpus=1", + "-enable-kvm", + "-machine smm=off", + "-boot", + "order=c", + "-serial", + "telnet:127.0.0.1:{},server,nowait".format(vm.console), + "-net", + "none", + "-device", + "e1000,mac={}".format(vm._mac_address) + ] + + @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") def test_build_command_without_display(vm, loop, fake_qemu_binary):