Skip to content

Commit

Permalink
Replace initrd and add kernel config as optional parameter to transfo…
Browse files Browse the repository at this point in the history
…rmer 'dom0_binaries'

Copy kernel config under /boot if passed to the transformer
Copy initrd if passed from runbook else create softlink for existing
initrd image with new kernel version in filename

Signed-off-by: Smit Gardhariya <[email protected]>
  • Loading branch information
smit-gardhariya committed Sep 4, 2024
1 parent d97439f commit 88194b9
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions lisa/transformers/dom0_kernel_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from lisa import schema
from lisa.node import Node
from lisa.tools import Cp, Echo, Ls, Sed, Tar, Uname
from lisa.tools import Cp, Echo, Ln, Ls, Sed, Tar, Uname
from lisa.util import field_metadata

from .kernel_installer import BaseInstaller, BaseInstallerSchema
Expand All @@ -35,6 +35,14 @@ class BinaryInstallerSchema(BaseInstallerSchema):
),
)

# kernel config local absolute path
kernel_config_path: str = field(
default="",
metadata=field_metadata(
required=True,
),
)

# initrd binary local absolute path
initrd_image_path: str = field(
default="",
Expand Down Expand Up @@ -67,7 +75,7 @@ def install(self) -> str:
kernel_image_path: str = runbook.kernel_image_path
initrd_image_path: str = runbook.initrd_image_path
kernel_modules_path: str = runbook.kernel_modules_path
is_initrd: bool = False
kernel_config_path: str = runbook.kernel_config_path

uname = node.tools[Uname]
current_kernel = uname.get_linux_information().kernel_version_raw
Expand Down Expand Up @@ -106,7 +114,6 @@ def install(self) -> str:
if initrd_image_path:
err = f"Can not find initrd image path: {initrd_image_path}"
assert os.path.exists(initrd_image_path), err
is_initrd = True
node.shell.copy(
PurePath(initrd_image_path),
node.get_pure_path(f"/var/tmp/initrd.img-{new_kernel}"),
Expand All @@ -116,10 +123,29 @@ def install(self) -> str:
node.get_pure_path(f"/var/tmp/initrd.img-{new_kernel}"),
node.get_pure_path(f"/boot/initrd.img-{new_kernel}"),
)
else:
ln = node.tools[Ln]
ln.create_link(
target=f"/boot/initrd.img-{current_kernel}",
link=f"/boot/initrd.img-{new_kernel}",
)

if kernel_config_path:
# Copy kernel config
err = f"Can not find kernel config path: {kernel_config_path}"
assert os.path.exists(kernel_config_path), err
node.shell.copy(
PurePath(kernel_config_path),
node.get_pure_path(f"/var/tmp/config-{new_kernel}"),
)
_copy_kernel_binary(
node,
node.get_pure_path(f"/var/tmp/config-{new_kernel}"),
node.get_pure_path(f"/boot/config-{new_kernel}"),
)

_update_mariner_config(
node,
is_initrd,
current_kernel,
new_kernel,
)
Expand Down Expand Up @@ -161,7 +187,6 @@ def install(self) -> str:

_update_mariner_config(
node,
True,
current_kernel,
new_kernel,
)
Expand All @@ -184,7 +209,6 @@ def _copy_kernel_binary(

def _update_mariner_config(
node: Node,
is_initrd: bool,
current_kernel: str,
new_kernel: str,
) -> None:
Expand All @@ -199,11 +223,10 @@ def _update_mariner_config(
sudo=True,
)

if is_initrd:
# Modify the /boot/mariner-mshv.cfg to point new initrd binary
sed.substitute(
regexp=f"mariner_initrd_mshv=initrd.img-{current_kernel}",
replacement=f"mariner_initrd_mshv=initrd.img-{new_kernel}",
file=mariner_config,
sudo=True,
)
# Modify the /boot/mariner-mshv.cfg to point new initrd binary
sed.substitute(
regexp=f"mariner_initrd_mshv=initrd.img-{current_kernel}",
replacement=f"mariner_initrd_mshv=initrd.img-{new_kernel}",
file=mariner_config,
sudo=True,
)

0 comments on commit 88194b9

Please sign in to comment.