diff --git a/src/mrack/transformers/beaker.py b/src/mrack/transformers/beaker.py index 1f504c00..f1cec380 100644 --- a/src/mrack/transformers/beaker.py +++ b/src/mrack/transformers/beaker.py @@ -86,17 +86,39 @@ def _get_ks_meta(self, host): def _construct_ks_append_script(self, ks_append, pubkeys=None): """Create ks_appdend from requirements.""" + res_ks_list = [] if not ks_append and not pubkeys: return [] - res_ks_append = ["%post"] - if pubkeys: - ks_append += self._allow_ssh_keys(pubkeys) + if isinstance(ks_append, dict): + res_ks_pre = ks_append.get("pre-install") + res_ks = ks_append.get("script") + res_ks_post = ks_append.get("post-install") + if res_ks_pre: + if res_ks_pre.startswith("%pre"): + res_ks_list += [res_ks_pre] + else: + res_ks_list += ["%pre"] + [res_ks_pre] + ["%end"] + if res_ks: + res_ks_list += [res_ks] + if res_ks_post: + if res_ks_post.startswith("%post"): + res_ks_list += [res_ks_post] + else: + res_ks_list += ["%post"] + [res_ks_post] + ["%end"] + else: + res_ks_list = ["%post"] + if pubkeys: + res_ks_list += self._allow_ssh_keys(pubkeys) + + res_ks_list += ks_append + + res_ks_list.append("%end") - res_ks_append += ks_append + if pubkeys: + res_ks_list += self._allow_ssh_keys(pubkeys) - res_ks_append.append("%end") - return ["\n".join(res_ks_append)] + return ["\n".join(res_ks_list)] def _allow_ssh_keys(self, pubkeys): """Create ssh key content to be injected to xml.""" diff --git a/tests/unit/test_beaker_transformer.py b/tests/unit/test_beaker_transformer.py index bbaf0a69..c9fb9f47 100644 --- a/tests/unit/test_beaker_transformer.py +++ b/tests/unit/test_beaker_transformer.py @@ -28,6 +28,10 @@ class TestBeakerTransformer: "restraint_id": 1, "beaker": { "ks_meta": "FEDORA_HOST_KS_META", + "ks_append": { + "pre-install": "%pre\n pre_dummy\n%end", + "script": "script_dummy", + }, "tasks": [ { "name": "/distribution/check-install", @@ -156,13 +160,13 @@ async def create_transformer(self, legacy=False): "distro": "Fedora-36%", "variant": "Server", "ks_meta": "FEDORA_HOST_KS_META", - "ks_append": default_ks_append, + "ks_append": ["%pre\n pre_dummy\n%end\nscript_dummy"], "whiteboard": default_whiteboard, "priority": default_prio, "tasks": [ {"name": "/distribution/check-install", "role": "SERVER"} ], - "retention_tag": default_retention_tag, + "" "retention_tag": default_retention_tag, "product": default_product, }, ),