diff --git a/lib/vdsm/aarch64HardwareInfo.py b/lib/vdsm/aarch64HardwareInfo.py new file mode 100644 index 000000000..ae11a2cac --- /dev/null +++ b/lib/vdsm/aarch64HardwareInfo.py @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: Red Hat, Inc. +# SPDX-License-Identifier: GPL-2.0-or-later + + +import logging +import os.path +import subprocess + +from vdsm import cpuinfo +from vdsm.common import cache + + + +def get_sys_info(): + + cmd = 'dmidecode -t system' + sys_info = {} + try: + output = subprocess.check_output(cmd, shell=True, universal_newlines=True) + for item in output.split("\n"): + if 'Manufacturer' in item or \ + 'Product Name' in item or \ + 'Version' in item or \ + 'Serial Number' in item or \ + 'UUID' in item or \ + 'Family' in item : + item = item.strip() + key = item.split(":")[0].strip() + value = item.split(":")[1].strip() + sys_info[key]=value + + except: + logging.exception('Error while getting system information') + + return sys_info + + + + +@cache.memoized +def getHardwareInfoStructure(): + sys_info_dict=get_sys_info() + + + return { + 'systemSerialNumber': sys_info_dict.get('Serial Number', 'unavailable'), + 'systemFamily': sys_info_dict.get('Family', 'unavailable'), + 'systemVersion': sys_info_dict.get('Version', 'unavailable'), + 'systemUUID': sys_info_dict.get('UUID', 'unavailable'), + 'systemProductName': sys_info_dict.get('Product Name', 'unavailable'), + 'systemManufacturer': sys_info_dict.get('Manufacturer', 'unavailable'), + } + diff --git a/lib/vdsm/machinetype.py b/lib/vdsm/machinetype.py index 107534ac3..341fe75da 100644 --- a/lib/vdsm/machinetype.py +++ b/lib/vdsm/machinetype.py @@ -12,6 +12,7 @@ from vdsm.common import cpuarch from vdsm.common import libvirtconnection from vdsm.common.config import config +from vdsm.validatehost import is_valid_virt_host class _CpuMode: @@ -146,12 +147,15 @@ def compatible_cpu_models(): compatible_models = [model for (model, usable) in all_models.items() if usable == 'yes'] + logging.debug('Compatible CPU models: %s', compatible_models) # Current QEMU doesn't report POWER compatibility modes, so we # must add them ourselves. if cpuarch.is_ppc(arch) and \ 'POWER9' in compatible_models and \ 'POWER8' not in compatible_models: compatible_models.append('POWER8') + if cpuarch.is_arm(arch) and is_valid_virt_host(): + compatible_models.append('virt_aarch64') return list(set(["model_" + model for model in compatible_models])) diff --git a/lib/vdsm/supervdsm_api/hwinfo.py b/lib/vdsm/supervdsm_api/hwinfo.py index c9b4b76aa..cfe768511 100644 --- a/lib/vdsm/supervdsm_api/hwinfo.py +++ b/lib/vdsm/supervdsm_api/hwinfo.py @@ -23,6 +23,9 @@ def getHardwareInfo(*args, **kwargs): elif cpuarch.is_ppc(arch): from vdsm.ppc64HardwareInfo import getHardwareInfoStructure return getHardwareInfoStructure() + elif cpuarch.is_arm(arch): + from vdsm.aarch64HardwareInfo import getHardwareInfoStructure + return getHardwareInfoStructure() else: # not implemented over other architecture return {} diff --git a/lib/vdsm/validatehost.py b/lib/vdsm/validatehost.py new file mode 100644 index 000000000..d51aabf4f --- /dev/null +++ b/lib/vdsm/validatehost.py @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: Red Hat, Inc. +# SPDX-License-Identifier: GPL-2.0-or-later + +import logging +import subprocess + +VIRT_HOST_VALIDATE_CMD = "virt-host-validate" + +def exec_validate_cmd(cmd): + """Execute a command and convert returned values to native string. + + Note that this function should not be used if output data could be + undecodable bytes. + """ + try: + out = subprocess.check_output(cmd).decode("utf-8") + except Exception as err: + logging.exception(f"Unexpected {err}, {type(err)}") + + logging.info(f"output {out}") + return out + +def is_valid_virt_host(): + """ Validate host is valid for virtualization + Below is the command and output + If host is not valid, the failure will be logged + # virt-host-validate + QEMU: Checking if device /dev/kvm exists : PASS + QEMU: Checking if device /dev/kvm is accessible : PASS + QEMU: Checking if device /dev/vhost-net exists : PASS + QEMU: Checking if device /dev/net/tun exists : PASS + QEMU: Checking for cgroup 'cpu' controller support : PASS + QEMU: Checking for cgroup 'cpuacct' controller support : PASS + QEMU: Checking for cgroup 'cpuset' controller support : PASS + QEMU: Checking for cgroup 'memory' controller support : PASS + QEMU: Checking for cgroup 'devices' controller support : PASS + QEMU: Checking for cgroup 'blkio' controller support : PASS + QEMU: Checking for device assignment IOMMU support : WARN + QEMU: Checking for secure guest support : WARN + + """ + + out = exec_validate_cmd(VIRT_HOST_VALIDATE_CMD) + valid_host = False + + if ('fail' not in out.lower()): + valid_host = True + + return valid_host \ No newline at end of file