Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ch libvirt #3562

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lisa/sut_orchestrator/libvirt/ch_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lisa/sut_orchestrator/libvirt/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 23 additions & 17 deletions lisa/sut_orchestrator/libvirt/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
pupacha marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
Loading