From b26411604cccca1eb6a77bbe3cd09ed0f1a7870b Mon Sep 17 00:00:00 2001 From: Konstantin Olshanov Date: Sun, 12 Nov 2023 07:34:45 +0400 Subject: [PATCH 1/4] source installer: add build_deps field Signed-off-by: Konstantin Olshanov --- lisa/transformers/kernel_source_installer.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lisa/transformers/kernel_source_installer.py b/lisa/transformers/kernel_source_installer.py index 577e3975e3..6674695d5f 100644 --- a/lisa/transformers/kernel_source_installer.py +++ b/lisa/transformers/kernel_source_installer.py @@ -93,6 +93,9 @@ class SourceInstallerSchema(BaseInstallerSchema): ), ) + # Additional build dependencies + build_deps: List[str] = field(default_factory=list) + class SourceInstaller(BaseInstaller): _code_path: PurePath @@ -143,7 +146,7 @@ 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) factory = subclasses.Factory[BaseLocation](BaseLocation) source = factory.create_by_runbook( @@ -302,12 +305,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) @@ -336,7 +339,7 @@ def _install_build_tools(self, node: Node) -> None: "libssl-dev", "bc", "ccache", - ] + ] + build_deps ) elif isinstance(os, CBLMariner): os.install_packages( @@ -355,7 +358,7 @@ def _install_build_tools(self, node: Node) -> None: "xz-libs", "openssl-libs", "openssl-devel", - ] + ] + build_deps ) else: raise LisaException( From eeb77dbb02caefe5f84fa67cccc368977d15adca Mon Sep 17 00:00:00 2001 From: Konstantin Olshanov Date: Sun, 12 Nov 2023 08:04:41 +0400 Subject: [PATCH 2/4] source installer: add local version Signed-off-by: Konstantin Olshanov --- lisa/transformers/kernel_source_installer.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lisa/transformers/kernel_source_installer.py b/lisa/transformers/kernel_source_installer.py index 6674695d5f..9cbbd20b14 100644 --- a/lisa/transformers/kernel_source_installer.py +++ b/lisa/transformers/kernel_source_installer.py @@ -96,6 +96,13 @@ 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 @@ -162,8 +169,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) @@ -230,7 +239,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] @@ -264,6 +273,13 @@ def _build_code(self, node: Node, code_path: PurePath, kconfig_file: str) -> Non sudo=True, ) + result = node.execute( + 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', From 7f016344be3092c40292a4e9617b4d8a18300406 Mon Sep 17 00:00:00 2001 From: Konstantin Olshanov Date: Sun, 12 Nov 2023 09:44:01 +0400 Subject: [PATCH 3/4] source installed: force boot into new kernel on Ubuntu Signed-off-by: Konstantin Olshanov --- lisa/transformers/kernel_source_installer.py | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lisa/transformers/kernel_source_installer.py b/lisa/transformers/kernel_source_installer.py index 9cbbd20b14..289883583a 100644 --- a/lisa/transformers/kernel_source_installer.py +++ b/lisa/transformers/kernel_source_installer.py @@ -155,6 +155,27 @@ def install(self) -> str: 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 < 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: From 7a8474d76fc6262f4f71f127effbb8a140105049 Mon Sep 17 00:00:00 2001 From: Konstantin Olshanov Date: Fri, 15 Dec 2023 07:07:44 +0400 Subject: [PATCH 4/4] source installed: add ability to amend config values Add ability to enable/disable config entry or set it to 'm'. Signed-off-by: Konstantin Olshanov --- lisa/transformers/kernel_source_installer.py | 47 +++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/lisa/transformers/kernel_source_installer.py b/lisa/transformers/kernel_source_installer.py index 289883583a..acb96e5882 100644 --- a/lisa/transformers/kernel_source_installer.py +++ b/lisa/transformers/kernel_source_installer.py @@ -104,6 +104,12 @@ class SourceInstallerSchema(BaseInstallerSchema): ), ) + # Config options + kernel_config_enable: List[str] = field(default_factory=list) + kernel_config_disable: List[str] = field(default_factory=list) + kernel_config_module: List[str] = field(default_factory=list) + + class SourceInstaller(BaseInstaller): _code_path: PurePath @@ -191,9 +197,13 @@ def install(self) -> str: kconfig_file = runbook.kernel_config_file local_version = runbook.kernel_local_version + kconfig_enable = runbook.kernel_config_enable + kconfig_disable = runbook.kernel_config_disable + kconfig_module = runbook.kernel_config_module self._build_code( node=node, code_path=self._code_path, kconfig_file=kconfig_file, - local_version=local_version + local_version=local_version, kconfig_enable=kconfig_enable, + kconfig_disable=kconfig_disable, kconfig_module=kconfig_module, ) self._install_build(node=node, code_path=self._code_path) @@ -274,7 +284,16 @@ 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, local_version: str) -> None: + def _build_code( + self, + node: Node, + code_path: PurePath, + kconfig_file: str, + local_version: str, + kconfig_enable: list[str], + kconfig_disable: list[str], + kconfig_module: list[str], + ) -> None: self._log.info("building code...") uname = node.tools[Uname] @@ -340,6 +359,30 @@ def _build_code(self, node: Node, code_path: PurePath, kconfig_file: str, local_ ) result.assert_exit_code() + for config_option in kconfig_enable: + result = node.execute( + f"scripts/config --enable {config_option}", + cwd=code_path, + shell=True, + ) + result.assert_exit_code() + + for config_option in kconfig_disable: + result = node.execute( + f"scripts/config --disable {config_option}", + cwd=code_path, + shell=True, + ) + result.assert_exit_code() + + for config_option in kconfig_module: + result = node.execute( + f"scripts/config --module {config_option}", + cwd=code_path, + shell=True, + ) + result.assert_exit_code() + # the gcc version of Redhat 7.x is too old. Upgrade it. if isinstance(node.os, Redhat) and node.os.information.version < "8.0.0": node.os.install_packages(["devtoolset-8"])