From ea81548b4deefbdf7dd404411c1dcd644ab173a8 Mon Sep 17 00:00:00 2001 From: Praveen K Paladugu Date: Mon, 25 Nov 2024 21:56:52 +0000 Subject: [PATCH] ch_platform: Fix hypervisor setting Libvirt versions greater than 10.2.0, define domain as 'hyperv' or 'kvm' based on the underlying hypervisor. Set this domain appropriately in domain's XML after checking libvirt version. Signed-off-by: Praveen K Paladugu --- lisa/sut_orchestrator/libvirt/ch_platform.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lisa/sut_orchestrator/libvirt/ch_platform.py b/lisa/sut_orchestrator/libvirt/ch_platform.py index b1c25057dc..e5e2454ef2 100644 --- a/lisa/sut_orchestrator/libvirt/ch_platform.py +++ b/lisa/sut_orchestrator/libvirt/ch_platform.py @@ -6,6 +6,7 @@ import secrets import xml.etree.ElementTree as ET # noqa: N817 from pathlib import Path +from packaging.version import parse from typing import List, Type from lisa import schema @@ -18,8 +19,9 @@ get_node_context, ) from lisa.sut_orchestrator.libvirt.platform import BaseLibvirtPlatform -from lisa.tools import QemuImg +from lisa.tools import QemuImg, Ls from lisa.util.logger import Logger, filter_ansi_escape +from lisa.util import LisaException from .. import CLOUD_HYPERVISOR from .console_logger import QemuConsoleLogger @@ -101,7 +103,19 @@ def _create_node_domain_xml( node_context = get_node_context(node) domain = ET.Element("domain") - domain.attrib["type"] = "ch" + + libvirt_version = self._get_libvirt_version() + if parse(libvirt_version) > parse("10.0.2"): + if self.host_node.tools[Ls].path_exists("/dev/mshv", sudo=True): + domain.attrib["type"] = "hyperv" + elif self.host_node.tools[Ls].path_exists("/dev/kvm", sudo=True): + domain.attrib["type"] = "kvm" + else: + raise LisaException("kvm, mshv are the only supported \ + hypervsiors. Both are missing on the host") + + else: + domain.attrib["type"] = "ch" name = ET.SubElement(domain, "name") name.text = node_context.vm_name