Skip to content

Commit

Permalink
feat: Add support for translanting %pre and main body part of kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily committed Jul 1, 2024
1 parent f1e7590 commit 7a87a25
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
34 changes: 28 additions & 6 deletions src/mrack/transformers/beaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_beaker_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
),
Expand Down

0 comments on commit 7a87a25

Please sign in to comment.