From 868523c9f75005b92e5300d4b877c32d9cfe80f6 Mon Sep 17 00:00:00 2001 From: Lili Nie Date: Thu, 10 Oct 2024 11:12:40 -0400 Subject: [PATCH] feat: Add translantion for kernel_options and kernel_options_post --- src/mrack/transformers/beaker.py | 40 +++++++++++++++++++++++++++ tests/unit/test_beaker_transformer.py | 6 ++++ 2 files changed, 46 insertions(+) diff --git a/src/mrack/transformers/beaker.py b/src/mrack/transformers/beaker.py index 93776376..498129fc 100644 --- a/src/mrack/transformers/beaker.py +++ b/src/mrack/transformers/beaker.py @@ -84,6 +84,44 @@ def _get_ks_meta(self, host): ) return res + def _get_kernel_options(self, host): + """ + Get `kernel_options` value from host or config or default if not defined. + + The priority is following: + - host + - provisioning-config.yaml + - default from provisioning config + - empty if not defined in provisioning config + + """ + res = self._find_value( + host.get(CONFIG_KEY, {}), + "kernel_options", + "kernel_options", + host["os"], + ) + return res + + def _get_kernel_options_post(self, host): + """ + Get `kernel_options_post` value from host or config or default if not defined. + + The priority is following: + - host + - provisioning-config.yaml + - default from provisioning config + - empty if not defined in provisioning config + + """ + res = self._find_value( + host.get(CONFIG_KEY, {}), + "kernel_options_post", + "kernel_options_post", + host["os"], + ) + return res + def _construct_ks_append_script(self, ks_append, pubkeys=None): """Create ks_appdend from requirements.""" res_ks_list = [] @@ -167,6 +205,8 @@ def create_host_requirement(self, host): "arch": host.get("arch", "x86_64"), "variant": variant, "ks_meta": self._get_ks_meta(host), + "kernel_options": self._get_kernel_options(host), + "kernel_options_post": self._get_kernel_options_post(host), "retention_tag": self._find_value( host.get(CONFIG_KEY, {}), "retention_tag", diff --git a/tests/unit/test_beaker_transformer.py b/tests/unit/test_beaker_transformer.py index 252289f3..9617dead 100644 --- a/tests/unit/test_beaker_transformer.py +++ b/tests/unit/test_beaker_transformer.py @@ -58,6 +58,8 @@ class TestBeakerTransformer: "restraint_id": 1, "beaker": { "ks_meta": "FEDORA_HOST_KS_META", + "kernel_options": "FEDORA_KERNEL_OPTIONS", + "kernel_options_post": "FEDORA_KERNEL_OPTIONS_POST", "ks_append": { "pre-install": "%pre\npre_dummy\n%end", "script": "script_dummy", @@ -193,6 +195,8 @@ async def create_transformer(self, legacy=False): "variant": "Server", "ks_meta": "FEDORA_HOST_KS_META", "ks_append": maximal_ksappend, + "kernel_options": "FEDORA_KERNEL_OPTIONS", + "kernel_options_post": "FEDORA_KERNEL_OPTIONS_POST", "whiteboard": default_whiteboard, "priority": default_prio, "tasks": [ @@ -289,6 +293,8 @@ async def test_beaker_requirement( "variant", "ks_meta", "ks_append", + "kernel_options", + "kernel_options_post", "whiteboard", "priority", "tasks",