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:
parent
44f2acffa5
commit
17bfed52f2
@ -1647,6 +1647,7 @@ class QemuVM(BaseNode):
|
|||||||
return ["-nographic"]
|
return ["-nographic"]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
def _run_with_hardware_acceleration(self, qemu_path, options):
|
def _run_with_hardware_acceleration(self, qemu_path, options):
|
||||||
"""
|
"""
|
||||||
Check if we can run Qemu with hardware acceleration
|
Check if we can run Qemu with hardware acceleration
|
||||||
@ -1717,7 +1718,7 @@ class QemuVM(BaseNode):
|
|||||||
command.extend(["-name", self._name])
|
command.extend(["-name", self._name])
|
||||||
command.extend(["-m", "{}M".format(self._ram)])
|
command.extend(["-m", "{}M".format(self._ram)])
|
||||||
command.extend(["-smp", "cpus={}".format(self._cpus)])
|
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"):
|
if sys.platform.startswith("linux"):
|
||||||
command.extend(["-enable-kvm"])
|
command.extend(["-enable-kvm"])
|
||||||
version = yield from self.manager.get_qemu_version(self.qemu_path)
|
version = yield from self.manager.get_qemu_version(self.qemu_path)
|
||||||
|
@ -73,6 +73,7 @@ def vm(project, manager, fake_qemu_binary, fake_qemu_img_binary):
|
|||||||
vm._start_ubridge = AsyncioMagicMock()
|
vm._start_ubridge = AsyncioMagicMock()
|
||||||
vm._ubridge_hypervisor = MagicMock()
|
vm._ubridge_hypervisor = MagicMock()
|
||||||
vm._ubridge_hypervisor.is_running.return_value = True
|
vm._ubridge_hypervisor.is_running.return_value = True
|
||||||
|
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
|
||||||
return vm
|
return vm
|
||||||
|
|
||||||
|
|
||||||
@ -513,70 +514,72 @@ def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_mana
|
|||||||
"""
|
"""
|
||||||
Qemu 2.4 introduce an issue with KVM
|
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")
|
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.3.2")
|
||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM._run_with_hardware_acceleration", return_value=True):
|
||||||
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
nio = vm._local_udp_tunnels[0][0]
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert cmd == [
|
nio = vm._local_udp_tunnels[0][0]
|
||||||
fake_qemu_binary,
|
assert cmd == [
|
||||||
"-name",
|
fake_qemu_binary,
|
||||||
"test",
|
"-name",
|
||||||
"-m",
|
"test",
|
||||||
"256M",
|
"-m",
|
||||||
"-smp",
|
"256M",
|
||||||
"cpus=1",
|
"-smp",
|
||||||
"-enable-kvm",
|
"cpus=1",
|
||||||
"-boot",
|
"-enable-kvm",
|
||||||
"order=c",
|
"-boot",
|
||||||
"-uuid",
|
"order=c",
|
||||||
vm.id,
|
"-uuid",
|
||||||
"-serial",
|
vm.id,
|
||||||
"telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
|
"-serial",
|
||||||
"-net",
|
"telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
|
||||||
"none",
|
"-net",
|
||||||
"-device",
|
"none",
|
||||||
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
|
"-device",
|
||||||
"-netdev",
|
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
|
||||||
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
|
"-netdev",
|
||||||
]
|
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_manager):
|
def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_manager):
|
||||||
"""
|
"""
|
||||||
Qemu 2.4 introduce an issue with KVM
|
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")
|
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.4.2")
|
||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM._run_with_hardware_acceleration", return_value=True):
|
||||||
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
nio = vm._local_udp_tunnels[0][0]
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert cmd == [
|
nio = vm._local_udp_tunnels[0][0]
|
||||||
fake_qemu_binary,
|
assert cmd == [
|
||||||
"-name",
|
fake_qemu_binary,
|
||||||
"test",
|
"-name",
|
||||||
"-m",
|
"test",
|
||||||
"256M",
|
"-m",
|
||||||
"-smp",
|
"256M",
|
||||||
"cpus=1",
|
"-smp",
|
||||||
"-enable-kvm",
|
"cpus=1",
|
||||||
"-machine",
|
"-enable-kvm",
|
||||||
"smm=off",
|
"-machine",
|
||||||
"-boot",
|
"smm=off",
|
||||||
"order=c",
|
"-boot",
|
||||||
"-uuid",
|
"order=c",
|
||||||
vm.id,
|
"-uuid",
|
||||||
"-serial",
|
vm.id,
|
||||||
"telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
|
"-serial",
|
||||||
"-net",
|
"telnet:127.0.0.1:{},server,nowait".format(vm._internal_console_port),
|
||||||
"none",
|
"-net",
|
||||||
"-device",
|
"none",
|
||||||
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
|
"-device",
|
||||||
"-netdev",
|
"e1000,mac={},netdev=gns3-0".format(vm._mac_address),
|
||||||
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
|
"-netdev",
|
||||||
]
|
"socket,id=gns3-0,udp=127.0.0.1:{},localaddr=127.0.0.1:{}".format(nio.rport, nio.lport)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||||
@ -829,43 +832,44 @@ def test_get_qemu_img_not_exist(vm, tmpdir):
|
|||||||
vm._get_qemu_img()
|
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)
|
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
|
||||||
assert vm._run_with_kvm("qemu-system-x86_64", "") is 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)
|
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
|
||||||
assert vm._run_with_kvm("qemu-system-x86_64.exe", "") is 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:
|
with patch("os.path.exists", return_value=True) as os_path:
|
||||||
vm.manager.config.set("Qemu", "enable_kvm", True)
|
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")
|
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:
|
with patch("os.path.exists", return_value=True) as os_path:
|
||||||
vm.manager.config.set("Qemu", "enable_kvm", True)
|
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:
|
with patch("os.path.exists", return_value=True) as os_path:
|
||||||
vm.manager.config.set("Qemu", "enable_kvm", True)
|
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:
|
with patch("os.path.exists", return_value=False) as os_path:
|
||||||
vm.manager.config.set("Qemu", "enable_kvm", True)
|
vm.manager.config.set("Qemu", "enable_kvm", True)
|
||||||
with pytest.raises(QemuError):
|
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", "")))
|
||||||
|
Loading…
Reference in New Issue
Block a user