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

Few improvements to source installer #3249

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
68 changes: 61 additions & 7 deletions lisa/transformers/kernel_source_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ class SourceInstallerSchema(BaseInstallerSchema):
),
)

# Additional build dependencies
build_deps: List[str] = field(default_factory=list)

# Kernel local version
kernel_local_version: str = field(
default="",
metadata=field_metadata(
required=False,
),
)

class SourceInstaller(BaseInstaller):
_code_path: PurePath
Expand Down Expand Up @@ -143,7 +153,28 @@ def install(self) -> str:
runbook: SourceInstallerSchema = self.runbook
assert runbook.location, "the repo must be defined."

self._install_build_tools(node)
self._install_build_tools(node, runbook.build_deps)

# Ubuntu sort kernels by version. If installed kernel version is lower than default
# one extra steps needed to ensure boot into correct kernel.
if isinstance(node.os, Ubuntu):
result = node.execute(
"cat > /tmp/grub-lisa.cfg <<EOF\n" \
"GRUB_DEFAULT=saved\n" \
"GRUB_DISABLE_SUBMENU=y\n" \
"EOF\n",
shell=True
)
result.assert_exit_code()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error message to describe what happened.


result = node.execute(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be cat into the /etc/default/grub.d/99-lisa.cfg directly? So it doesn't need an extra command to copy.

f"cp /tmp/grub-lisa.cfg /etc/default/grub.d/99-lisa.cfg",
sudo=True,
)
result.assert_exit_code()

# grub.cfg will be regenerated later during make install, so
# no need to explicitly regenerate it now.

factory = subclasses.Factory[BaseLocation](BaseLocation)
source = factory.create_by_runbook(
Expand All @@ -159,8 +190,10 @@ def install(self) -> str:
self._modify_code(node=node, code_path=self._code_path)

kconfig_file = runbook.kernel_config_file
local_version = runbook.kernel_local_version
self._build_code(
node=node, code_path=self._code_path, kconfig_file=kconfig_file
node=node, code_path=self._code_path, kconfig_file=kconfig_file,
local_version=local_version
)

self._install_build(node=node, code_path=self._code_path)
Expand All @@ -185,6 +218,20 @@ def install(self) -> str:
)
result.assert_exit_code()

if isinstance(node.os, Ubuntu):
result = node.execute("find /boot -name 'grub.cfg'", sudo=True)
result.assert_exit_code()

grub_config = result.stdout
result = node.execute(f"grep 'menuentry ' {grub_config}", sudo=True)
result.assert_exit_code()

for idx, menuentry in enumerate(result.stdout.splitlines()):
if kernel_version in menuentry:
node.execute(f"grub-set-default {idx}", sudo=True)
result.assert_exit_code()
break

return kernel_version

def _install_build(self, node: Node, code_path: PurePath) -> None:
Expand Down Expand Up @@ -227,7 +274,7 @@ def _modify_code(self, node: Node, code_path: PurePath) -> None:
self._log.debug(f"modifying code by {modifier.type_name()}")
modifier.modify()

def _build_code(self, node: Node, code_path: PurePath, kconfig_file: str) -> None:
def _build_code(self, node: Node, code_path: PurePath, kconfig_file: str, local_version: str) -> None:
self._log.info("building code...")

uname = node.tools[Uname]
Expand Down Expand Up @@ -261,6 +308,13 @@ def _build_code(self, node: Node, code_path: PurePath, kconfig_file: str) -> Non
sudo=True,
)

result = node.execute(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it optional, if the local_version is not specified, don't execute it.

f"scripts/config --set-str LOCALVERSION '{local_version}'",
cwd=code_path,
shell=True,
)
result.assert_exit_code()

# workaround failures.
#
# make[1]: *** No rule to make target 'debian/canonical-certs.pem',
Expand Down Expand Up @@ -302,12 +356,12 @@ def _build_code(self, node: Node, code_path: PurePath, kconfig_file: str) -> Non
# set timeout to 2 hours
make.make(arguments="", cwd=code_path, timeout=60 * 60 * 2)

def _install_build_tools(self, node: Node) -> None:
def _install_build_tools(self, node: Node, build_deps: list[str]) -> None:
os = node.os
self._log.info("installing build tools")
if isinstance(os, Redhat):
for package in list(
["elfutils-libelf-devel", "openssl-devel", "dwarves", "bc"]
["elfutils-libelf-devel", "openssl-devel", "dwarves", "bc"] + build_deps
):
if os.is_package_in_repo(package):
os.install_packages(package)
Expand Down Expand Up @@ -336,7 +390,7 @@ def _install_build_tools(self, node: Node) -> None:
"libssl-dev",
"bc",
"ccache",
]
] + build_deps
)
elif isinstance(os, CBLMariner):
os.install_packages(
Expand All @@ -355,7 +409,7 @@ def _install_build_tools(self, node: Node) -> None:
"xz-libs",
"openssl-libs",
"openssl-devel",
]
] + build_deps
)
else:
raise LisaException(
Expand Down