diff --git a/app/models/compute_resource.rb b/app/models/compute_resource.rb index 1ac04c3772..9c1049f228 100644 --- a/app/models/compute_resource.rb +++ b/app/models/compute_resource.rb @@ -437,18 +437,20 @@ def resolve_automatic_firmware(firmware, firmware_type) # # @param firmware [String] The firmware setting to be processed. # @param firmware_type [String] The firmware type based on the provided PXE Loader. + # @param provision_method [String] The provisioning method. # @return [Hash] A hash containing the processed firmware attributes. - def process_firmware_attributes(firmware, firmware_type) + def process_firmware_attributes(firmware, firmware_type, provision_method = nil) attrs = {} # The `firmware_type` flag is set through `host_compute_attrs(host)` and only used # during host creation via the orchestration process. + # The `provision_method` is used during host creation as well. # If not set, the method may be used for validation, preview, or UI-related logic # without performing any real provisioning actions. # The normalization should only be used during host creation, otherwise the firmware is set # to the initial firmware value so that the UI can display the correct value. - if firmware_type.present? + if provision_method == 'image' || firmware_type.present? firmware = resolve_automatic_firmware(firmware, firmware_type) attrs[:firmware] = normalize_firmware_type(firmware) else diff --git a/app/models/compute_resources/foreman/model/libvirt.rb b/app/models/compute_resources/foreman/model/libvirt.rb index 53c6d0160d..6e40623f5a 100644 --- a/app/models/compute_resources/foreman/model/libvirt.rb +++ b/app/models/compute_resources/foreman/model/libvirt.rb @@ -149,7 +149,7 @@ def new_vm(attr = { }) opts[:boot_order].unshift 'network' unless attr[:image_id] firmware_type = opts.delete(:firmware_type).to_s - opts.merge!(process_firmware_attributes(opts[:firmware], firmware_type)) + opts.merge!(process_firmware_attributes(opts[:firmware], firmware_type, opts[:provision_method])) vm = client.servers.new opts vm.memory = opts[:memory] if opts[:memory] diff --git a/app/models/compute_resources/foreman/model/vmware.rb b/app/models/compute_resources/foreman/model/vmware.rb index 8f3841b658..ff0b082d52 100644 --- a/app/models/compute_resources/foreman/model/vmware.rb +++ b/app/models/compute_resources/foreman/model/vmware.rb @@ -482,7 +482,7 @@ def parse_args(args) args.except!(:hardware_version) if args[:hardware_version] == 'Default' firmware_type = args.delete(:firmware_type).to_s - args.merge!(process_firmware_attributes(args[:firmware], firmware_type)) + args.merge!(process_firmware_attributes(args[:firmware], firmware_type, args[:provision_method])) args[:virtual_tpm] = validate_tpm_compatibility(args[:virtual_tpm], args[:firmware]) args.reject! { |k, v| v.nil? } diff --git a/test/models/compute_resource_test.rb b/test/models/compute_resource_test.rb index 1bc76fe69c..36b32fd78a 100644 --- a/test/models/compute_resource_test.rb +++ b/test/models/compute_resource_test.rb @@ -509,5 +509,25 @@ def setup attr_exp = { :secure_boot => true, :firmware => "efi" } assert_equal attr_exp, @cr.send(:process_firmware_attributes, 'uefi_secure_boot', 'uefi_secure_boot') end + + test "firmware is 'uefi' and provisioning_method is 'image'" do + attr_exp = { :firmware => "efi" } + assert_equal attr_exp, @cr.send(:process_firmware_attributes, 'uefi', nil, 'image') + end + + test "firmware is 'uefi_secure_boot' and provisioning_method is 'image'" do + attr_exp = { :firmware => "efi", :secure_boot => true } + assert_equal attr_exp, @cr.send(:process_firmware_attributes, 'uefi_secure_boot', nil, 'image') + end + + test "firmware is 'bios' and provisioning_method is 'image'" do + attr_exp = { :firmware => "bios" } + assert_equal attr_exp, @cr.send(:process_firmware_attributes, 'bios', nil, 'image') + end + + test "firmware is 'automatic' and provisioning_method is 'image'" do + attr_exp = { :firmware => "bios" } + assert_equal attr_exp, @cr.send(:process_firmware_attributes, 'automatic', nil, 'image') + end end end