Replace initrd and add kernel config as optional parameter to transformer 'dom0_binaries' (#3405)

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 <sgardhariya@microsoft.com>
This commit is contained in:
Smit Gardhariya 2024-09-04 14:02:10 +05:30 коммит произвёл GitHub
Родитель 8538c62f28
Коммит 225fb52d56
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 37 добавлений и 14 удалений

Просмотреть файл

@ -9,7 +9,7 @@ from dataclasses_json import dataclass_json
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
@ -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="",
@ -67,7 +75,7 @@ class BinaryInstaller(BaseInstaller):
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
@ -106,7 +114,6 @@ class BinaryInstaller(BaseInstaller):
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}"),
@ -116,10 +123,29 @@ class BinaryInstaller(BaseInstaller):
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,
)
@ -161,7 +187,6 @@ class Dom0Installer(SourceInstaller):
_update_mariner_config(
node,
True,
current_kernel,
new_kernel,
)
@ -184,7 +209,6 @@ def _copy_kernel_binary(
def _update_mariner_config(
node: Node,
is_initrd: bool,
current_kernel: str,
new_kernel: str,
) -> None:
@ -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,
)