Skip to content

Use grubby to update kernel command line arguments - #511

Open
mihaelabalutoiu wants to merge 4 commits into
cloudbase:mainfrom
mihaelabalutoiu:add-grubby-kernel-opts
Open

mihaelabalutoiu wants to merge 4 commits into
cloudbase:mainfrom
mihaelabalutoiu:add-grubby-kernel-opts

Conversation

@mihaelabalutoiu

@mihaelabalutoiu mihaelabalutoiu commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Failing to update the kernel console options breaks text console functionality on affected platforms.

The issue is caused by BLS being enabled by default in /etc/default/grub. On RHEL 10, kernel arguments are managed through /boot/loader/entries, and grub2-mkconfig does not propagate the updated options there.

This PR implements the following:

  • Adds Grub2ConfigEditor.remove_from_option, with grubby --remove-args semantics: a bare name drops the argument whichever value it holds, a name/value pair drops it only on an exact match.
  • Adds _update_kernel_cmdline_args to the base OSMorphing tools, editing both GRUB2 cmdline options through Grub2ConfigEditor. Debian and SUSE each had their own copy of these edits and now share this one.
  • Overrides it on redhat to use grubby --update-kernel=ALL, which reaches the BLS boot entries.

Comment thread coriolis/osmorphing/base.py
@mihaelabalutoiu
mihaelabalutoiu marked this pull request as draft September 4, 2026 07:08
Removes cmdline entries with `grubby --remove-args` semantics: a bare
name drops the argument whichever value it holds, a name/value pair
drops it only on an exact match.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
@mihaelabalutoiu
mihaelabalutoiu force-pushed the add-grubby-kernel-opts branch 2 times, most recently from 17e0300 to f6177de Compare September 8, 2026 13:34
@mihaelabalutoiu
mihaelabalutoiu marked this pull request as ready for review September 9, 2026 09:47
@@ -69,33 +69,7 @@ def check_os_supported(cls, detected_os_info):
return False

def disable_predictable_nic_names(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth taking into account to modify custom implementations of disable_predictable_nic_names in the other providers as well.
Besides that LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides OCI, there's no other implementations. We should be fine, since that's already handled here: https://github.com/cloudbase/coriolis-provider-oci/pull/3/files (the extra implementations seem to be removed, as they should :D )

Comment thread coriolis/osmorphing/base.py
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Use `grubby --update-kernel=ALL` to update kernel arguments on
BLS-based systems such as RHEL 10, where `grub2-mkconfig` does not
propagate them to `/boot/loader/entries`.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Existing `name=value` arguments are parsed as `key_val`, so appending
them as `single` values duplicated them.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
self.assertFalse(result)
mock_get_grub_default_conf.assert_not_called()

@mock.patch.object(base.BaseLinuxOSMorphingTools, '_schedule_grub2_update')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate it more if this wasn't mocked and in fact actually checked (i.e. instead of using assert_called methods, use assertTrue/False on self.os_morphing_tools._grub2_update_scheduled .
If you go ahead and do this, please also make sure that the teardown or setup includes the reset of this property (basically set it back to False, so that all other tests start with that).

@mock.patch.object(
base.BaseLinuxOSMorphingTools,
'_get_grub_default_conf',
return_value='/etc/default/grub',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return value could be saved as a constant in this file.

mock_schedule_grub2_update,
):
mock_test_path_chroot.return_value = True
mock_read_file_sudo.return_value = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any point in having multiple tests for disable_predictable_nic_names anymore. Just mock update_kernel_cmdline_args and assert it got called with whatever expected args to add. That method already has enough tests itself, here you're basically just retesting that method.

@mock.patch.object(redhat.BaseRedHatMorphingTools, '_update_kernel_cmdline_args')
def test_disable_predictable_nic_names(self, mock_update_kernel_cmdline_args):
self.morphing_tools.disable_predictable_nic_names()
mock_update_kernel_cmdline_args.assert_called_once_with(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is exactly how the debian test should've looked like as well.


@mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
def test_disable_predictable_nic_names(self, mock_exec_cmd_chroot):
def test_disable_predictable_nic_names_updates_all_kernels(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

@mock.patch.object(suse.BaseSUSEMorphingTools, '_schedule_grub2_update')
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_read_file_sudo')
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path')
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for debian, just assert that _update_kernel_cmdline_args has been called with the right args :D

'GRUB_CMDLINE_LINUX="console=ttyS0"\n',
),
(
'GRUB_CMDLINE_LINUX="cloud-init=enabled console=ttyS0"',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case duplicated? Looks the same as the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants