Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/models/compute_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/libvirt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? }
Expand Down
20 changes: 20 additions & 0 deletions test/models/compute_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading