Skip to content

Commit

Permalink
Refactor the dhcp_update_required? method
Browse files Browse the repository at this point in the history
Extracted complex comdition into separate methods and handle the TODO comment related to jumpstart logic.
  • Loading branch information
archanaserver committed Aug 1, 2024
1 parent 2f947f7 commit af2299b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/models/concerns/orchestration/dhcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,18 @@ def dhcp_update_required?
(old&.operatingsystem&.boot_filename(old.host) != operatingsystem&.boot_filename(host)) ||
((old.host.pxe_loader == "iPXE Embedded" || host.pxe_loader == "iPXE Embedded") && (old.host.build != host.build)) ||
(!old.build? && build? && !all_dhcp_records_valid?))
# Handle jumpstart
# TODO, abstract this way once interfaces are fully used
if is_a?(Host::Base) && jumpstart?
if !old.build? || (old.medium != medium || old.arch != arch) ||
(os && old.os && (old.os.name != os.name || old.os != os))
return true
end

if requires_jumpstart_update?
return true
end
false
end

def requires_jumpstart_update?
is_a?(Host::Base) && jumpstart? && (!old.build? || (old.medium != medium || old.arch != arch) ||
(os && old.os && (old.os.name != os.name || old.os != os)))
end

def all_dhcp_records_valid?
dhcp_records.all? { |record| record.valid? }
end
Expand Down

0 comments on commit af2299b

Please sign in to comment.