stages: add test for coreos.platform generate_console_settings_file

And a tiny tweak to avoid an empty line at the start of the
`boot/grub2/console.cfg`
This commit is contained in:
Michael Vogt 2024-02-26 10:14:05 +01:00
parent e9c31c035b
commit 30f740ec9f
2 changed files with 34 additions and 1 deletions

View file

@ -59,7 +59,7 @@ def generate_console_settings_file(console_settings, file_path):
settings_content = ""
if console_settings is not None:
settings_content = "\n".join(console_settings)
file_content = f"""
file_content = f"""\
# Any non-default console settings will be inserted here.
# CONSOLE-SETTINGS-START
{settings_content}

View file

@ -53,3 +53,36 @@ def test_process_platforms_json(tmp_path, stage_module, platform, expected_grub,
grub_cmds, kernel_args = stage_module.process_platforms_json(fake_platforms_path, platform)
assert grub_cmds == expected_grub
assert kernel_args == expected_kernel
def test_generate_console_settings_none(tmp_path, stage_module):
fake_console_settings_path = tmp_path / "boot/grub2/console.cfg"
fake_console_settings_path.parent.mkdir(parents=True)
console_settings = None
stage_module.generate_console_settings_file(console_settings, fake_console_settings_path)
# ensure we generate a template even if no settings are provided
assert fake_console_settings_path.read_text(encoding="utf8") == textwrap.dedent("""\
# Any non-default console settings will be inserted here.
# CONSOLE-SETTINGS-START
# CONSOLE-SETTINGS-END
""")
def test_generate_console_settings_multiple(tmp_path, stage_module):
fake_console_settings_path = tmp_path / "boot/grub2/console.cfg"
fake_console_settings_path.parent.mkdir(parents=True)
# console settings are the grub commands from the platforms.json
console_settings = ["serial --speed=115200", "terminal_input serial console", "terminal_output serial console"]
stage_module.generate_console_settings_file(console_settings, fake_console_settings_path)
# ensure we generate a template even if no settings are provided
assert fake_console_settings_path.read_text(encoding="utf8") == textwrap.dedent("""\
# Any non-default console settings will be inserted here.
# CONSOLE-SETTINGS-START
serial --speed=115200
terminal_input serial console
terminal_output serial console
# CONSOLE-SETTINGS-END
""")