From ee2104ba3561ef55c3f9470d2d5bbae9419f3868 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 26 Jan 2016 13:57:55 +0100 Subject: [PATCH] Check for /dev/kvm instead of kvm-ok Fix #411 --- gns3server/modules/qemu/__init__.py | 22 +++++++++------------- tests/modules/qemu/test_qemu_manager.py | 8 +++++--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/gns3server/modules/qemu/__init__.py b/gns3server/modules/qemu/__init__.py index 3ee441b0..7d7ddb58 100644 --- a/gns3server/modules/qemu/__init__.py +++ b/gns3server/modules/qemu/__init__.py @@ -49,21 +49,17 @@ class Qemu(BaseManager): """ kvm = [] - try: - process = yield from asyncio.create_subprocess_exec("kvm-ok") - yield from process.wait() - except OSError: + if not os.path.exists("/dev/kvm"): return kvm - if process.returncode == 0: - arch = platform.machine() - if arch == "x86_64": - kvm.append("x86_64") - kvm.append("i386") - elif arch == "i386": - kvm.append("i386") - else: - kvm.append(platform.machine()) + arch = platform.machine() + if arch == "x86_64": + kvm.append("x86_64") + kvm.append("i386") + elif arch == "i386": + kvm.append("i386") + else: + kvm.append(platform.machine()) return kvm @staticmethod diff --git a/tests/modules/qemu/test_qemu_manager.py b/tests/modules/qemu/test_qemu_manager.py index 38da1cbf..82fc9765 100644 --- a/tests/modules/qemu/test_qemu_manager.py +++ b/tests/modules/qemu/test_qemu_manager.py @@ -185,11 +185,13 @@ def test_get_kvm_archs_no_kvm(loop): def test_get_kvm_archs_kvm_ok(loop): - process = MagicMock() - with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): - process.returncode = 0 + with patch("os.path.exists", return_value=True): 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() + + with patch("os.path.exists", return_value=False): + archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs())) + assert archs == []