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

Conversation

archanaserver
Copy link
Contributor

Based on discussion: https://github.com/theforeman/foreman/pull/10068/files/5dc13229ccc9e02791121f055b7a7b7d4a14918e#r1699753281

Extracted complex condition into separate methods and handle the TODO comment related to jumpstart logic.

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?

Extracted complex condition into separate method and handle the TODO comment related to jumpstart logic.
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

What I meant was that perhaps it already is properly abstracted away.

The whole method tries to determine if the DHCP record needs to be updated. That is if any parameter has changed. We Net::DHCP::Record and subclasses in lib/net/dhcp.

These are called in ProxyAPI::DHCP:

# Retrieves a DHCP entry for a mac
# [+subnet+] : String in dotted decimal format
# [+mac+] : String in coloned sextuplet format
# Returns : Hash or false
def record(subnet, mac)
response = parse(get("#{subnet}/mac/#{mac}"))
attrs = response.merge(:network => subnet, :proxy => self)
if response.keys.grep(/Sun/i).empty?
Net::DHCP::Record.new attrs
else
Net::DHCP::SparcRecord.new attrs
end
rescue RestClient::ResourceNotFound
nil
rescue => e
raise ProxyException.new(url, e, N_("Unable to retrieve DHCP entry for %s"), mac)
end

And indirectly in orchestration:

def build_dhcp_record(record_mac)
raise ::Foreman::Exception.new(N_("DHCP not supported for this NIC")) unless dhcp?
record_attrs = dhcp_attrs(record_mac)
record_type = operatingsystem.dhcp_record_type
handle_validation_errors do
record_type.new(record_attrs)
end
end

The latter one is more relevant (it's also this file), so dhcp_update_required? should compare all attributes that dhcp_attrs can return.

Note it has this bit already:

if jumpstart?
jumpstart_arguments = os.jumpstart_params host, model.vendor_class

So I'd expect you can compare os.jumpstart_params and old.os.jumpstart_params.

Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

Just to be extra sure I'm not missing anything, this just extracts a chunk of code into a method, correct? There are no actual changes to what are all the things that get checked, right?

Edit: somehow I haven't seen Ewoud's previous comment, oh well

return true
end

if requires_jumpstart_update?
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants