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

Fixes #16105 - Force DNS rebuild when provisioning discovered host #297

Closed
wants to merge 1 commit into from

Conversation

imriz
Copy link
Member

@imriz imriz commented Aug 16, 2016

No description provided.

@imriz
Copy link
Member Author

imriz commented Aug 16, 2016

[test]

@imriz imriz force-pushed the 16105 branch 3 times, most recently from 2cc8bc6 to 4f76415 Compare August 17, 2016 09:40
@lzap
Copy link
Member

lzap commented Aug 18, 2016

Will take a look tomorrow, thanks!

@@ -73,6 +73,7 @@ def update
def perform_update(host, success_message = nil)
Taxonomy.no_taxonomy_scope do
::ForemanDiscovery::HostConverter.set_build_clean_facts(host)
@host.primary_interface.discovery_queue_rebuild_dns unless @host.primary_interface.pending_dns_record_changes?
Copy link
Member

Choose a reason for hiding this comment

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

This code will not work with auto-provisioning, make sure it work in both ways. Anyways.

I think instead of calling this explicitly, we should create new after_validation :queue_dns_discovery hook. In the hook method, check if we are converting from Discovered, like we do in other hooks, then queue it when necessary.

Add tests for normal and autoprovisioning please. And make the commit message shorter :-)

@lzap lzap changed the title Fixes #16105 - Force DNS rebuild when provisioning discovered host, even if it appears to have no DNS changes pending Fixes #16105 - Force DNS rebuild when provisioning discovered host Aug 18, 2016
@lzap
Copy link
Member

lzap commented Aug 18, 2016

Example:

module MyExtensions
  extend ActiveSupport::Concern

  included do
    after_validation :queue_dns_rebuild
  end

  def queue_dns_rebuild
    return unless errors.empty? && !Setting[:discovery_always_rebuild_dns]
    return if new_record? # Discovered Hosts already exist, and new_records will break `find`
    return unless type_changed? and ::Host::Base.find(self.id).type == "Host::Discovered"

    # do your stuff here
  end

@lzap
Copy link
Member

lzap commented Aug 18, 2016

The code could be perhaps part of discovery's Host::ManagedExtensions I think. Just another method I believe.

@imriz
Copy link
Member Author

imriz commented Aug 19, 2016

The code could be perhaps part of discovery's Host::ManagedExtensions I think. Just another method I believe.

Mmm, maybe the same convention as the other orchestration concerns? Orchestration::Discovery::DnsExtensions or something like that, or, since it belongs to the Nic model, Nic::ManagedExtensions?

@imriz
Copy link
Member Author

imriz commented Aug 21, 2016

@lzap updated the PR.

@@ -31,6 +31,7 @@ def self.load_defaults
self.set('discovery_facts_ipmi', N_("Regex to organize facts for ipmi section"), "", N_("IPMI facts")),
self.set('discovery_lock', N_("Automatically generate PXE configuration to pin a newly discovered host to discovery"), false, N_("Lock PXE")),
self.set('discovery_lock_template', N_("PXE template to be used when pinning a host to discovery"), 'pxelinux_discovery', N_("Locked template name"),nil,{ :collection => Proc.new {Hash[ProvisioningTemplate.all.map{|template| [template[:name], template[:name]]}]} }),
self.set('discovery_always_rebuild_dns', N_("Force DNS entries creation when provisioning discovered host"), true, N_("Force DNS")),
Copy link
Member

Choose a reason for hiding this comment

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

Looks great. Why this is enabled by default? Normally, discovered hosts should not be added to DNS, thus I'd set this to false.

Copy link
Member Author

Choose a reason for hiding this comment

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

This only affects when you provision the host, not when it enters discovery, and in that case you always expect DNS to be created.

Copy link
Member

Choose a reason for hiding this comment

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

This only affects when you provision the host, not when it enters discovery, and in that case you always expect DNS to be created.

Disregard my comment, this should be turned on by default.

Later,
Lukas #lzap Zapletal

@lzap
Copy link
Member

lzap commented Aug 24, 2016

What a coincidence, I just accepted my very first MyHeritage Instant Discovery e-mail when I noticed your domain. I am newcomer there. I was wondering if you could update http://projects.theforeman.org/projects/foreman/wiki/Who_Uses_Foreman (if that's valid and appropriate).

Very nice patch indeed. Please do my smallish comments and I will test and merge it later this week.

@imriz
Copy link
Member Author

imriz commented Aug 24, 2016

I was wondering if you could update http://projects.theforeman.org/projects/foreman/wiki/Who_Uses_Foreman (if that's valid and appropriate).

Sure! will do :)

@imriz
Copy link
Member Author

imriz commented Aug 25, 2016

@lzap PR updated per your comments, and I've updated the "Who_Uses_Foreman" :)

Thanks!!

@lzap
Copy link
Member

lzap commented Aug 26, 2016

It work fine, in my environment I see:

2016-08-26T14:38:42 2576109c [app] [I] Create DHCP reservation for x525400e94080.local.lan-52:54:00:e9:40:80/192.168.122.101
2016-08-26T14:38:42 2576109c [app] [D] DHCP reservation on net 192.168.122.0 with attrs: {:hostname=>"x525400e94080.local.lan", :mac=>"52:54:00:e9:40:80", :ip=>"192.168.122.101", :network=>"192.168.122.0", :nextServer=>"192.168.122.1", :filename=>"pxelinux.0"}
2016-08-26T14:38:42 2576109c [app] [I] Delete the DNS A record for x525400e94080.local.lan/192.168.122.101
2016-08-26T14:38:42 2576109c [app] [I] Add DNS A record for x525400e94080.local.lan/192.168.122.101
2016-08-26T14:38:42 2576109c [app] [I] Delete the DNS PTR record for 192.168.122.101/x525400e94080.local.lan
2016-08-26T14:38:42 2576109c [app] [D] Fetching DNS reservation for 192.168.122.101/x525400e94080.local.lan
2016-08-26T14:38:42 2576109c [app] [I] Add DNS PTR record for 192.168.122.101/x525400e94080.local.lan

The initial DNS deletion failed on proxy and returned 404 but this was not reason for rollback and the transaction continued. Which brings this question - do we want really to rebuild DNS (delete/add operations) or simply build DNS (add operation only)? I lean towards the latter to prevent such 404 errors. Or both maybe (make it a three state flag), because I would like to implement naming discovered hosts using the "deacon" gem we recently added (http://projects.theforeman.org/issues/16330).

Explain me your use case - why you prefer rebuilding instead of building DNS entry? Do you create DNS name during discovery phase somehow?

@imriz
Copy link
Member Author

imriz commented Aug 26, 2016

No specific reason. I used it because it is safe, and can overcome stale
records, if such exists. I don't mind changing to add only if you prefer.

On Aug 26, 2016 3:57 PM, "Lukáš Zapletal" notifications@github.com wrote:

It work fine, in my environment I see:

2016-08-26T14:38:42 2576109c [app] [I] Create DHCP reservation for x525400e94080.local.lan-52:54:00:e9:40:80/192.168.122.101
2016-08-26T14:38:42 2576109c [app] [D] DHCP reservation on net 192.168.122.0 with attrs: {:hostname=>"x525400e94080.local.lan", :mac=>"52:54:00:e9:40:80", :ip=>"192.168.122.101", :network=>"192.168.122.0", :nextServer=>"192.168.122.1", :filename=>"pxelinux.0"}
2016-08-26T14:38:42 2576109c [app] [I] Delete the DNS A record for x525400e94080.local.lan/192.168.122.101
2016-08-26T14:38:42 2576109c [app] [I] Add DNS A record for x525400e94080.local.lan/192.168.122.101
2016-08-26T14:38:42 2576109c [app] [I] Delete the DNS PTR record for 192.168.122.101/x525400e94080.local.lan
2016-08-26T14:38:42 http://192.168.122.101/x525400e94080.local.lan2016-08-26T14:38:42 2576109c [app] [D] Fetching DNS reservation for 192.168.122.101/x525400e94080.local.lan
2016-08-26T14:38:42 http://192.168.122.101/x525400e94080.local.lan2016-08-26T14:38:42 2576109c [app] [I] Add DNS PTR record for 192.168.122.101/x525400e94080.local.lan

The initial DNS deletion failed on proxy and returned 404 but this was not
reason for rollback and the transaction continued. Which brings this
question - do we want really to rebuild DNS (delete/add operations) or
simply build DNS (add operation only)? I lean towards the latter to
prevent such 404 errors. Or both maybe (make it a three state flag),
because I would like to implement naming discovered hosts using the
"deacon" gem we recently added (http://projects.theforeman.
org/issues/16330).

Explain me your use case - why you prefer rebuilding instead of building
DNS entry? Do you create DNS name during discovery phase somehow?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#297 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFcUWyDCZY2J40bu-1HE-M-CBFHwK5iLks5qjuKjgaJpZM4JlJXe
.

@lzap
Copy link
Member

lzap commented Aug 29, 2016

Merged as fe52972, thank you!

@lzap lzap closed this Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants