Skip to content
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

Refactor the dhcp_update_required? method #10261

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we refactor it more like:

return true if requires_jumpstart_update?
  false

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't even just requires_jumpstart_update? do the trick? Or double-negate it to cast it from a truthy/falsey value into a bool?

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
Loading