diff --git a/lisa/sut_orchestrator/libvirt/ch_platform.py b/lisa/sut_orchestrator/libvirt/ch_platform.py index b1c25057dc..7497e5f9b6 100644 --- a/lisa/sut_orchestrator/libvirt/ch_platform.py +++ b/lisa/sut_orchestrator/libvirt/ch_platform.py @@ -8,6 +8,8 @@ from pathlib import Path from typing import List, Type +from packaging.version import parse + from lisa import schema from lisa.environment import Environment from lisa.feature import Feature @@ -18,7 +20,8 @@ get_node_context, ) from lisa.sut_orchestrator.libvirt.platform import BaseLibvirtPlatform -from lisa.tools import QemuImg +from lisa.tools import Ls, QemuImg +from lisa.util import LisaException from lisa.util.logger import Logger, filter_ansi_escape from .. import CLOUD_HYPERVISOR @@ -101,7 +104,21 @@ 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 diff --git a/lisa/sut_orchestrator/libvirt/platform.py b/lisa/sut_orchestrator/libvirt/platform.py index c8d9f807be..2946385686 100644 --- a/lisa/sut_orchestrator/libvirt/platform.py +++ b/lisa/sut_orchestrator/libvirt/platform.py @@ -1369,6 +1369,9 @@ def _get_libvirt_version(self) -> str: if self.host_node: result = self.host_node.execute("libvirtd --version", shell=True).stdout result = filter_ansi_escape(result) + # Libvirtd returns version info as "libvirtd (libvirt) 10.8.0" + # From the return value, only return the version info + result = result.split()[-1] return result def _get_vmm_version(self) -> str: diff --git a/lisa/sut_orchestrator/libvirt/transformers.py b/lisa/sut_orchestrator/libvirt/transformers.py index 7ec21964f9..b0c30e6cdf 100644 --- a/lisa/sut_orchestrator/libvirt/transformers.py +++ b/lisa/sut_orchestrator/libvirt/transformers.py @@ -551,7 +551,6 @@ def _install_libvirt(runbook: schema.TypedSchema, node: Node, log: Logger) -> No if isinstance(node.os, Ubuntu): node.execute("systemctl disable apparmor", shell=True, sudo=True) - node.execute("systemctl enable libvirtd", shell=True, sudo=True) node.reboot(time_out=900) if isinstance(node.os, CBLMariner): # After reboot, libvirtd service is in failed state and needs to @@ -571,7 +570,11 @@ def _install_libvirt(runbook: schema.TypedSchema, node: Node, log: Logger) -> No libvirt_version = libvirt_installer._get_version() log.info(f"Already installed! libvirt version: {libvirt_version}") _fix_mariner_installation(node=node) - node.reboot(time_out=900) + + node.execute("systemctl enable libvirtd", shell=True, sudo=True) + node.execute("systemctl enable virtnetworkd", shell=True, sudo=True) + log.info("Enabled libvirtd and virtnetworkd services") + node.reboot(time_out=900) # Some fixes to the libvirt installation on Mariner.