Bug #17873
closedforeman_url ignores templates proxy when provisioning discovered host
Description
When provisioning a discovered host and changing the provisioning interface, the foreman_url method ignores a templates (or tftp) proxy set on the subnet.
Unsure yet if this is really limited to discovery or an issue in core.
foreman_url method calls
proxy = @host.try(:subnet).try(:tftp)
to find the proxy.
It seems like subnet is nil, however the (new!) provisioning interface has a subnet attached.
Steps to reproduce:
Provision a discovered host, add a new bond interface as primary, provision and managed (tick all three!).
Save the discovered host.
The deployed PXELinux template will now have the foreman url set and not the one from the proxy.
Debug output when rendering the template (this is interesting!)
host: #{@host} (#{@host.class}), subnet: #{@host.try(:subnet)}, proxy: #{@host.try(:subnet).try(:tftp)}, provision_interface: #{@host.try(:provision_interface).try(:inspect)}, primary_interface: #{@host.try(:primary_interface).try(:inspect)}
yields:
host: abc.example.com (Host::Managed), subnet: , proxy: , provision_interface: #<Nic::Bond id: nil, mac: nil, ip: "1.2.3.4", type: "Nic::Bond", name: "abc.example.com", host_id: 14325, subnet_id: 135, domain_id: 1, attrs: {}, created_at: nil, updated_at: nil, provider: nil, username: nil, password: nil, virtual: true, link: true, identifier: "bond0", tag: "", attached_to: "", managed: true, mode: "active-backup", attached_devices: "p5p1,p5p2", bond_options: "", primary: true, provision: true, compute_attributes: {}, execution: false, ip6: "", subnet6_id: nil>, primary_interface: #<Nic::Managed id: 17646, mac: "...", ip: "", type: "Nic::Managed", name: "abc", host_id: 14325, subnet_id: nil, domain_id: nil, ... subnet6_id: nil>
That means:
When it tries to save/validate the provision_interface and render the template, the primary interface (used for foreman_url) is still the old/wrong interface without the subnet set.