From 24e5a6d45886365cecce74c2c9aa1cfd8c0da69a Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Thu, 16 Nov 2017 11:01:25 +0100 Subject: Autodetect KVM Autodetect KVM by using the 'kvm-ok' command line tool. This has two benefits: Firstly, it improves the UX of run-qemu-ota when working on machines without KVM (e.g. AWS). Previously, people had to use the --no-kvm option in these cases. Secondary, it makes oe-selftest usable on machines without KVM. Our tests call run-qemu-ota, and we want to able to run them on machines without KVM. --- scripts/qemucommand.py | 11 ++++++++++- scripts/run-qemu-ota | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index a75ffb6..82a9540 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -2,6 +2,7 @@ from os.path import exists, join, realpath, abspath from os import listdir import random import socket +from subprocess import check_output, CalledProcessError EXTENSIONS = { 'intel-corei7-64': 'wic', @@ -67,7 +68,15 @@ class QemuCommand(object): self.mac_address = random_mac() self.serial_port = find_local_port(8990) self.ssh_port = find_local_port(2222) - self.kvm = not args.no_kvm + if args.kvm is None: + # Autodetect KVM using 'kvm-ok' + try: + check_output(['kvm-ok']) + self.kvm = True + except CalledProcessError: + self.kvm = False + else: + self.kvm = args.kvm self.gui = not args.no_gui self.gdb = args.gdb self.pcap = args.pcap diff --git a/scripts/run-qemu-ota b/scripts/run-qemu-ota index 8e25197..56e4fbc 100755 --- a/scripts/run-qemu-ota +++ b/scripts/run-qemu-ota @@ -21,7 +21,11 @@ def main(): 'OSTREE_BOOTLOADER = "grub" and OVMF.fd firmware to be installed (try "apt install ovmf")', action='store_true') parser.add_argument('--machine', default=None, help="Target MACHINE") - parser.add_argument('--no-kvm', help='Disable KVM in QEMU', action='store_true') + kvm_group = parser.add_argument_group() + kvm_group.add_argument('--force-kvm', help='Force use of KVM (default is to autodetect)', + dest='kvm', action='store_true', default=None) + kvm_group.add_argument('--no-kvm', help='Disable KVM in QEMU', + dest='kvm', action='store_false') parser.add_argument('--no-gui', help='Disable GUI', action='store_true') parser.add_argument('--gdb', help='Export gdbserver port 2159 from the image', action='store_true') parser.add_argument('--pcap', default=None, help='Dump all network traffic') -- cgit v1.2.3-54-g00ecf