Skip to content

Conversation

@sbernhard
Copy link
Contributor

Without this PR, its is currently really broken. Without this PR, it does always! show 'Automatic' - except while editing hosts. For new/edit of Compute Profile or in the Create Host page - always 'Automatic' is shown. A user would never know what is really configured. This is because of [1].

If you create a host later, 'Automatic' is always displayed, regardless of which firmware is selected in the Compute Profile.

This change makes sure, that the selected firmware on the Compute Profile is the one which was saved previously and represents the value from the database while editing a existing Compute Profile.

The trick is to extend the new_vm() method with a "dry-run" parameter. dry-run is normally set to "true" as the new_vm() method is used at the compute_profile and hosts page for showing the form. The firmware modification should only be done in case the vm is later on really saved.

[1] https://github.com/theforeman/foreman/pull/10321/files#diff-c88b347f9af46e109987241498e9db3c776cc76433ffe3ba6f58ae1d8a74b9adR11

@sbernhard
Copy link
Contributor Author

Another try, similar to #10529 to solve the firmware issue.
This PR tries to solve the root cause of the issue, that the original firmware form value is changed while showing / validating the form and not only just before generating the vm.

@nofaralfasi, please have a look. We can work together on a solution and jump on a call if you have further ideas.

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

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

The code looks good overall. It’s not the ideal solution, but it fixes the problem we’re trying to solve.
One small suggestion: I think the dry_run variable name could be more descriptive. Maybe something like new_host, or another name that better reflects its purpose.
Also, it might help future readers if you could add a short comment explaining why this variable is needed in the first place.
Also, could you update the tests and consider adding a few more for better coverage?

@sbernhard
Copy link
Contributor Author

sbernhard commented Jul 10, 2025

@nofaralfasi changed the name of the flag and changed it from additional function parameter to a attribute. This solved a lot of test issues. Additionally, I have added a comment.

I have adapted the tests. Foreman tests are green now.

  • I tested host create and edit manually with the UI and it worked.
  • I tested compute profile create and edit manually with the UI and it worked.
  • Tested host creation with existing compute profiles (Automatic, BIOS, UEFI, UEFI SECURE) and it worked. The host uses the correct profile afterwards:
    • it choose BIOS if Automatic was used
    • it choose UEFI Secure Boot if boot loader was Grub2 UEFI SecureBoot)

@sbernhard
Copy link
Contributor Author

Looks like the test issues in Katello are not related. E.g. https://github.com/theforeman/foreman/actions/runs/16202971385/job/45746456820?pr=10600 is failing because of the same issue.

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

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

I feel that adding the create_vm_ctx variable in multiple places introduces unnecessary complexity and makes the code harder to follow and maintain. Is there a way we could simplify or centralize it?

@sbernhard
Copy link
Contributor Author

I feel that adding the create_vm_ctx variable in multiple places introduces unnecessary complexity and makes the code harder to follow and maintain. Is there a way we could simplify or centralize it?

I don't know how because this flag need to be set so that it will do the magic. Do you have an idea?

@sbernhard
Copy link
Contributor Author

all tests have passed.

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

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

Instead of introducing a new create_vm_ctx flag, have you considered using the host_compute_attrs method? It only passes a hash during actual VM creation from Foreman, so we might be able to leverage it to simplify the logic.

@sbernhard
Copy link
Contributor Author

Instead of introducing a new create_vm_ctx flag, have you considered using the host_compute_attrs method? It only passes a hash during actual VM creation from Foreman, so we might be able to leverage it to simplify the logic.

I will try this out tomorrow.
Other than that, thanks for your suggestions - I have applied them.

firmware = resolve_automatic_firmware(firmware, firmware_type)
attrs[:firmware] = normalize_firmware_type(firmware)
else
attrs[:firmware] = firmware || 'bios'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use bios instead of automatic? I think it would be better to set the default to automatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @sbernhard, any updates on this?

Copy link
Contributor Author

@sbernhard sbernhard Nov 4, 2025

Choose a reason for hiding this comment

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

Hi @sbernhard, any updates on this?

Sorry, have a look at the last changes. There are 2 commits: 1 with the "original" implementation and the second commit for changing the default from "bios" to "automatic" and the required *-test changes.

Let me know what you think about. If ok, I can squash it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @sbernhard, yes please squash it and I will merge this PR. Thanks!

Without this PR, its is currently really broken. Without this PR, it
does always! show 'Automatic' - except while editing hosts. For
new/edit of Compute Profile or in the Create Host page - always
'Automatic' is shown. A user would never know what is really configured.
This is because of [1].

If you create a host later, 'Automatic' is always displayed, regardless
of which firmware is selected in the Compute Profile.

This change makes sure, that the selected firmware on the Compute
Profile is the one which was saved previously and represents the
value from the database while editing a existing Compute Profile.

The `process_firmware_attributes` is modified so that the methods
`resolve_automatic_firmware` and `normalize_firmware_type` are only used
if a host is created on the compute resource.

[1] https://github.com/theforeman/foreman/pull/10321/files#diff-c88b347f9af46e109987241498e9db3c776cc76433ffe3ba6f58ae1d8a74b9adR11
Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

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

Thank you @sbernhard!!

@nofaralfasi nofaralfasi merged commit c04d6ae into theforeman:develop Nov 21, 2025
35 checks passed
@nlaphine
Copy link

I know this is "Closed and Merged", but why "After processing the user’s input, the default type should be BIOS"
We live in modern times. EFI is available on every new machine. BIOS is the odd one out now.

Just a question to prompt a change of thinking for the future if I may be so bold.

Thanks
Peter

@nofaralfasi
Copy link
Contributor

I know this is "Closed and Merged", but why "After processing the user’s input, the default type should be BIOS" We live in modern times. EFI is available on every new machine. BIOS is the odd one out now.

Hi Peter,
The default is set to BIOS only when no PXE Loader is selected and the Firmware type is set to Automatic. This has been the existing behavior until now, and this PR does not change it.

If we want to change that behavior, we should open a new issue explaining the rationale, discuss it as a team, and then address it in a separate PR.

This PR focuses on fixing a different problem, so we shouldn’t mix the two concerns.

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.

5 participants