-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #37834 - Set Firmware selection correct #10550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Another try, similar to #10529 to solve the firmware issue. @nofaralfasi, please have a look. We can work together on a solution and jump on a call if you have further ideas. |
There was a problem hiding this 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?
09172e7 to
6d0aa2d
Compare
|
@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.
|
|
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. |
nofaralfasi
left a comment
There was a problem hiding this 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?
I don't know how because this flag need to be set so that it will do the magic. Do you have an idea? |
|
all tests have passed. |
nofaralfasi
left a comment
There was a problem hiding this 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.
I will try this out tomorrow. |
71e8425 to
688794d
Compare
688794d to
b6a28a5
Compare
b6a28a5 to
dd79fd8
Compare
app/models/compute_resource.rb
Outdated
| firmware = resolve_automatic_firmware(firmware, firmware_type) | ||
| attrs[:firmware] = normalize_firmware_type(firmware) | ||
| else | ||
| attrs[:firmware] = firmware || 'bios' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After processing the user’s input, the default type should be BIOS. For a new form, the default should be Automatic. References:
VMware: https://github.com/nofaralfasi/foreman/blob/develop/app/models/compute_resources/foreman/model/vmware.rb#L823
https://github.com/nofaralfasi/foreman/blob/develop/app/views/compute_resources_vms/form/vmware/_base.html.erb#L10
Libvirt:
https://github.com/nofaralfasi/foreman/blob/develop/app/models/compute_resources/foreman/model/libvirt.rb#L300
https://github.com/nofaralfasi/foreman/blob/develop/app/views/compute_resources_vms/form/libvirt/_base.html.erb#L11
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
dd79fd8 to
25060c2
Compare
25060c2 to
3f5ef80
Compare
3f5ef80 to
2923033
Compare
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
2923033 to
5158c02
Compare
nofaralfasi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @sbernhard!!
|
I know this is "Closed and Merged", but why "After processing the user’s input, the default type should be BIOS" Just a question to prompt a change of thinking for the future if I may be so bold. Thanks |
Hi Peter, 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. |
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