diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index c9ee4bd38..d3fa493af 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -24,6 +24,7 @@ import json import logging import math import os +import platform import re import shlex import shutil @@ -2749,8 +2750,9 @@ class QemuVM(KernelDatapathMixin, BaseNode): enable_hardware_accel = self.manager.config.settings.Qemu.enable_hardware_acceleration require_hardware_accel = self.manager.config.settings.Qemu.require_hardware_acceleration if enable_hardware_accel and "-machine accel=tcg" not in options: - # Turn OFF hardware acceleration for non x86 architectures supported_binaries = ["qemu-system-x86_64", "qemu-system-i386", "qemu-kvm"] + if platform.machine() in ("aarch64", "arm64"): + supported_binaries = ["qemu-system-aarch64"] if os.path.basename(qemu_path) not in supported_binaries: if require_hardware_accel: raise QemuError( diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 7022eb039..e1fcd2179 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -1057,12 +1057,27 @@ def test_get_qemu_img(vm, tmpdir): @pytest.mark.asyncio async def test_run_with_kvm(vm): - with patch("os.path.exists", return_value=True) as os_path: + with ( + patch("gns3server.compute.qemu.qemu_vm.platform.machine", return_value="x86_64"), + patch("os.path.exists", return_value=True) as os_path, + ): vm.manager.config.settings.Qemu.enable_hardware_acceleration = True assert await vm._run_with_hardware_acceleration("qemu-system-x86_64", "") is True os_path.assert_called_with("/dev/kvm") +@pytest.mark.asyncio +async def test_run_with_kvm_arm64(vm): + + with ( + patch("gns3server.compute.qemu.qemu_vm.platform.machine", return_value="aarch64"), + patch("os.path.exists", return_value=True) as os_path, + ): + vm.manager.config.settings.Qemu.enable_hardware_acceleration = True + assert await vm._run_with_hardware_acceleration("qemu-system-aarch64", "") is True + os_path.assert_called_with("/dev/kvm") + + @pytest.mark.asyncio async def test_run_with_kvm_options_no_kvm(vm): @@ -1074,7 +1089,10 @@ async def test_run_with_kvm_options_no_kvm(vm): @pytest.mark.asyncio async def test_run_with_kvm_not_x86(vm): - with patch("os.path.exists", return_value=True): + with ( + patch("gns3server.compute.qemu.qemu_vm.platform.machine", return_value="x86_64"), + patch("os.path.exists", return_value=True), + ): vm.manager.config.settings.Qemu.enable_hardware_acceleration = True vm.manager.config.settings.Qemu.require_hardware_acceleration = True with pytest.raises(QemuError): @@ -1084,7 +1102,10 @@ async def test_run_with_kvm_not_x86(vm): @pytest.mark.asyncio async def test_run_with_kvm_dev_kvm_missing(vm): - with patch("os.path.exists", return_value=False): + with ( + patch("gns3server.compute.qemu.qemu_vm.platform.machine", return_value="x86_64"), + patch("os.path.exists", return_value=False), + ): vm.manager.config.settings.Qemu.enable_hardware_acceleration = True vm.manager.config.settings.Qemu.require_hardware_acceleration = True with pytest.raises(QemuError):