From 1ffbf5b57ba0d3a4236a7d2bf04268267d97e653 Mon Sep 17 00:00:00 2001 From: Praveen K Paladugu Date: Wed, 27 Nov 2024 19:30:12 +0000 Subject: [PATCH 1/3] libvirt: fix parsing libvirt version Properly parse libvirt version and return only the version information. Signed-off-by: Praveen K Paladugu --- lisa/sut_orchestrator/libvirt/platform.py | 3 +++ 1 file changed, 3 insertions(+) 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: From dae42e99e3e97757e94d722763d0073d0099161c Mon Sep 17 00:00:00 2001 From: Praveen K Paladugu Date: Mon, 25 Nov 2024 21:56:52 +0000 Subject: [PATCH 2/3] 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 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lisa/sut_orchestrator/libvirt/ch_platform.py b/lisa/sut_orchestrator/libvirt/ch_platform.py index b1c25057dc..a7f2324e8d 100644 --- a/lisa/sut_orchestrator/libvirt/ch_platform.py +++ b/lisa/sut_orchestrator/libvirt/ch_platform.py @@ -18,7 +18,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, parse_version from lisa.util.logger import Logger, filter_ansi_escape from .. import CLOUD_HYPERVISOR @@ -101,7 +102,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_version(libvirt_version) > "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 From 9b780462950cc4f3006601de6f4c3efce48d6a79 Mon Sep 17 00:00:00 2001 From: Praveen K Paladugu Date: Thu, 5 Dec 2024 17:30:36 +0000 Subject: [PATCH 3/3] libvirt: Enable virtnetworkd service Enable virtnetworkd service along with libvritd service. virtnetworkd service will setup the default NAT network for guests to use. Signed-off-by: Praveen K Paladugu --- lisa/sut_orchestrator/libvirt/transformers.py | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/lisa/sut_orchestrator/libvirt/transformers.py b/lisa/sut_orchestrator/libvirt/transformers.py index 7ec21964f9..99cb2cc0a3 100644 --- a/lisa/sut_orchestrator/libvirt/transformers.py +++ b/lisa/sut_orchestrator/libvirt/transformers.py @@ -551,27 +551,33 @@ 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 - # be restarted manually. Doing it immediately after restart - # fails. So wait for a while before restarting libvirtd. - # This is an issue in Mariner and below lines can be removed once - # it has been addressed. - tries = 0 - while tries <= 10: - try: - node.tools[Service].restart_service("libvirtd") - break - except Exception: - time.sleep(1) - tries += 1 else: 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) + _wait_for_libvirtd(node) + + +def _wait_for_libvirtd(node: Node) -> None: + if isinstance(node.os, CBLMariner): + # After reboot, libvirtd service is in failed state and needs to + # be restarted manually. Doing it immediately after restart + # fails. So wait for a while before restarting libvirtd. + # This is an issue in Mariner and below lines can be removed once + # it has been addressed. + tries = 0 + while tries <= 10: + try: + node.tools[Service].restart_service("libvirtd") + break + except Exception: + time.sleep(1) + tries += 1 # Some fixes to the libvirt installation on Mariner.