From e8634748a1eb6973f2798eec8efee055d3064087 Mon Sep 17 00:00:00 2001 From: cid Date: Thu, 30 May 2024 14:41:09 +0100 Subject: [PATCH] GRUB conf template compatibility with arm server Determine the appropriate GRUB commands during UEFI boot based on the node's CPU architecture. Closes-Bug: #2050054 Change-Id: I0c5f513cdc8f4112f8dfdeb4ccaf566d3424a2ca --- ironic/common/pxe_utils.py | 8 ++++++ .../drivers/modules/pxe_grub_config.template | 14 +++++----- ironic/tests/unit/common/test_pxe_utils.py | 26 +++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py index 1c1a2915d1..fc4fb97447 100644 --- a/ironic/common/pxe_utils.py +++ b/ironic/common/pxe_utils.py @@ -347,6 +347,14 @@ def create_pxe_config(task, pxe_options, template=None, ipxe_enabled=False): if uefi_with_grub: pxe_config_root_tag = '(( ROOT ))' pxe_config_disk_ident = '(( DISK_IDENTIFIER ))' + + # Determine the appropriate commands based on the CPU architecture + arch = task.node.properties.get('cpu_arch', 'x86_64') + commands = { + 'linux_cmd': 'linuxefi' if arch != 'aarch64' else 'linux', + 'initrd_cmd': 'initrdefi' if arch != 'aarch64' else 'initrd' + } + pxe_options.update(commands) else: # TODO(stendulker): We should use '(' ')' as the delimiters for all our # config files so that we do not need special handling for each of the diff --git a/ironic/drivers/modules/pxe_grub_config.template b/ironic/drivers/modules/pxe_grub_config.template index 3bcdf55d65..93a0869fb0 100644 --- a/ironic/drivers/modules/pxe_grub_config.template +++ b/ironic/drivers/modules/pxe_grub_config.template @@ -3,20 +3,20 @@ set timeout=5 set hidden_timeout_quiet=false menuentry "deploy" { - linuxefi {{ pxe_options.deployment_aki_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} boot_server={{pxe_options.tftp_server}} - initrdefi {{ pxe_options.deployment_ari_path }} + {{ pxe_options.linux_cmd|default('linuxefi', true) }} {{ pxe_options.deployment_aki_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} boot_server={{pxe_options.tftp_server}} + {{ pxe_options.initrd_cmd|default('initrdefi', true) }} {{ pxe_options.deployment_ari_path }} } menuentry "boot_ramdisk" { - linuxefi {{ pxe_options.aki_path }} root=/dev/ram0 text {{ pxe_options.pxe_append_params|default("", true) }} {{ pxe_options.ramdisk_opts|default('', true) }} - initrdefi {{ pxe_options.ari_path }} + {{ pxe_options.linux_cmd|default('linuxefi', true) }} {{ pxe_options.aki_path }} root=/dev/ram0 text {{ pxe_options.pxe_append_params|default("", true) }} {{ pxe_options.ramdisk_opts|default('', true) }} + {{ pxe_options.initrd_cmd|default('initrdefi', true) }} {{ pxe_options.ari_path }} } menuentry "boot_whole_disk" { - linuxefi chain.c32 mbr:{{ DISK_IDENTIFIER }} + {{ pxe_options.linux_cmd|default('linuxefi', true) }} chain.c32 mbr:{{ DISK_IDENTIFIER }} } menuentry "boot_anaconda" { - linuxefi {{ pxe_options.aki_path }} text {{ pxe_options.pxe_append_params|default("", true) }} inst.ks={{ pxe_options.ks_cfg_url }} {% if pxe_options.repo_url %}inst.repo={{ pxe_options.repo_url }}{% else %}inst.stage2={{ pxe_options.stage2_url }}{% endif %} - initrdefi {{ pxe_options.ari_path }} + {{ pxe_options.linux_cmd|default('linuxefi', true) }} {{ pxe_options.aki_path }} text {{ pxe_options.pxe_append_params|default("", true) }} inst.ks={{ pxe_options.ks_cfg_url }} {% if pxe_options.repo_url %}inst.repo={{ pxe_options.repo_url }}{% else %}inst.stage2={{ pxe_options.stage2_url }}{% endif %} + {{ pxe_options.initrd_cmd|default('initrdefi', true) }} {{ pxe_options.ari_path }} } diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py index 14b587e5f2..ca19d621b6 100644 --- a/ironic/tests/unit/common/test_pxe_utils.py +++ b/ironic/tests/unit/common/test_pxe_utils.py @@ -166,6 +166,32 @@ class TestPXEUtils(db_base.DbTestCase): self.assertEqual(str(expected_template), rendered_template) + def test_pxe_config_x86_64(self): + self.node.properties['cpu_arch'] = 'x86_64' + self.node.save() + + rendered_template = utils.render_template( + CONF.pxe.uefi_pxe_config_template, + {'pxe_options': self.pxe_options, + 'ROOT': '{{ ROOT }}', + 'DISK_IDENTIFIER': '{{ DISK_IDENTIFIER }}'}) + + self.assertIn('linuxefi', rendered_template) + self.assertIn('initrdefi', rendered_template) + + def test_pxe_config_aarch64(self): + self.node.properties['cpu_arch'] = 'aarch64' + self.node.save() + + rendered_template = utils.render_template( + CONF.pxe.uefi_pxe_config_template, + {'pxe_options': self.pxe_options, + 'ROOT': '{{ ROOT }}', + 'DISK_IDENTIFIER': '{{ DISK_IDENTIFIER }}'}) + + self.assertIn('linux', rendered_template) + self.assertIn('initrd', rendered_template) + def test_default_ipxe_boot_script(self): rendered_template = utils.render_template( CONF.pxe.ipxe_boot_script,