From 4e1281bc91f4917e37016602e3cbdeef2edad9f8 Mon Sep 17 00:00:00 2001 From: sebastian Date: Mon, 24 Aug 2020 11:14:29 +0800 Subject: [PATCH] Failed to get machine type in arm cpu,qemu_vm,env_process: Judge machine type in supported machine types. If not, will using default value 'virt'. Current the param of machine type must be in format "xx:xx", otherwise it will cause error "list index out of range". --- virttest/cpu.py | 11 ++++++++++- virttest/env_process.py | 12 +++++++++++- virttest/qemu_vm.py | 12 +++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/virttest/cpu.py b/virttest/cpu.py index 9df28cbe..d08ce7d7 100644 --- a/virttest/cpu.py +++ b/virttest/cpu.py @@ -1234,7 +1234,16 @@ def get_qemu_best_cpu_model(params): qemu_binary = utils_misc.get_qemu_binary(params) # aarch64 use 'qemu_binary -M machine_type -cpu ?' to get supported cpu models. if platform.machine() == 'aarch64': - machine_type = params.get("machine_type").split(':', 1)[1] + machine_type = params.get("machine_type") + if ':' in machine_type: + machine_type = machine_type.split(':', 1)[1] + # Needed to judge if machine_type supported in arm + hvm_or_pv = params.get("hvm_or_pv", "hvm") + from virttest.utils_test import libvirt + support_machine_type = libvirt.get_machine_types('aarch64', hvm_or_pv, ignore_status=False) + if machine_type not in support_machine_type: + logging.warn("Unsupported machine type %s", machine_type) + machine_type = 'virt' extra_params = " -M" + " %s" % machine_type qemu_cpu_models = get_qemu_cpu_models(qemu_binary, extra_params) else: diff --git a/virttest/env_process.py b/virttest/env_process.py index cb17aefc..1a243b1b 100644 --- a/virttest/env_process.py +++ b/virttest/env_process.py @@ -1038,7 +1038,17 @@ def preprocess(test, params, env): qemu_path = utils_misc.get_qemu_binary(params) # aarch64 use "qemu-kvm -M machine_type" instead. if platform.machine() == 'aarch64': - machine_type = params.get("machine_type").split(':', 1)[1] + machine_type = params.get("machine_type") + if ':' in machine_type: + machine_type = machine_type.split(':', 1)[1] + # Needed to judge if machine_type supported in arm + hvm_or_pv = params.get("hvm_or_pv", "hvm") + from virttest.utils_test import libvirt + support_machine_type = libvirt.get_machine_types( + 'aarch64', hvm_or_pv, ignore_status=False) + if machine_type not in support_machine_type: + logging.warn("Unsupported machine type %s", machine_type) + machine_type = 'virt' qemu_path = qemu_path + " -M" + " %s" % machine_type if (utils_qemu.has_device_category(qemu_path, "CPU") and params.get("cpu_driver") is None): diff --git a/virttest/qemu_vm.py b/virttest/qemu_vm.py index 0662ba3b..bb4fcc2d 100644 --- a/virttest/qemu_vm.py +++ b/virttest/qemu_vm.py @@ -1412,7 +1412,17 @@ class VM(virt_vm.BaseVM): shell=True)).split(',')[0] # aarch64 use "qemu-kvm -M machine_type -cpu ?" to get supported cpu models. if platform.machine() == 'aarch64': - machine_type = params.get("machine_type").split(':', 1)[1] + machine_type = params.get("machine_type") + if ':' in machine_type: + machine_type = machine_type.split(':', 1)[1] + # Needed to judge if machine_type supported in arm + hvm_or_pv = params.get("hvm_or_pv", "hvm") + from virttest.utils_test import libvirt + support_machine_type = libvirt.get_machine_types( + 'aarch64', hvm_or_pv, ignore_status=False) + if machine_type not in support_machine_type: + logging.warn("Unsupported machine type %s", machine_type) + machine_type = 'virt' support_cpu_model = decode_to_text(process.system_output("%s -M %s -cpu \\? " % (qemu_binary, machine_type), verbose=False, ignore_status=True, -- GitLab