Project

General

Profile

« Previous | Next » 

Revision 21e07e92

Added by Trey Dockendorf about 10 years ago

fixes #4599 - DNS and DHCP records for BMC and managed interfaces not using FQDN

View differences:

app/models/concerns/orchestration/dhcp.rb
end
def dhcp?
name.present? && ip_available? && mac_available? && !subnet.nil? && subnet.dhcp? && managed?
hostname.present? && ip_available? && mac_available? && !subnet.nil? && subnet.dhcp? && managed?
end
def dhcp_record
......
def dhcp_attrs
return unless dhcp?
dhcp_attr = { :name => name, :filename => operatingsystem.boot_filename(self),
:ip => ip, :mac => mac, :hostname => name, :proxy => subnet.dhcp_proxy,
:ip => ip, :mac => mac, :hostname => hostname, :proxy => subnet.dhcp_proxy,
:network => subnet.network, :nextServer => boot_server }
if jumpstart?
......
# do we need to update our dhcp reservations
def dhcp_update_required?
# IP Address / name changed
return true if ((old.ip != ip) or (old.name != name) or (old.mac != mac) or (old.subnet != subnet))
return true if ((old.ip != ip) or (old.hostname != hostname) or (old.mac != mac) or (old.subnet != subnet))
# Handle jumpstart
#TODO, abstract this way once interfaces are fully used
if self.kind_of?(Host::Base) and jumpstart?
......
def dhcp_conflict_detected?
# we can't do any dhcp based validations when our MAC address is defined afterwards (e.g. in vm creation)
return false if mac.blank? or name.blank?
return false if mac.blank? or hostname.blank?
return false unless dhcp?
if dhcp_record and dhcp_record.conflicting? and (not overwrite?)
app/models/concerns/orchestration/dns.rb
end
def dns?
name.present? and ip_available? and !domain.nil? and !domain.proxy.nil? and managed?
hostname.present? and ip_available? and !domain.nil? and !domain.proxy.nil? and managed?
end
def reverse_dns?
name.present? and ip_available? and !subnet.nil? and subnet.dns? and managed?
hostname.present? and ip_available? and !subnet.nil? and subnet.dns? and managed?
end
def dns_a_record
......
private
def dns_record_attrs
{ :hostname => name, :ip => ip, :resolver => domain.resolver, :proxy => domain.proxy }
{ :hostname => hostname, :ip => ip, :resolver => domain.resolver, :proxy => domain.proxy }
end
def reverse_dns_record_attrs
{ :hostname => name, :ip => ip, :proxy => subnet.dns_proxy }
{ :hostname => hostname, :ip => ip, :proxy => subnet.dns_proxy }
end
def queue_dns
......
end
def queue_dns_update
if old.ip != ip or old.name != name
if old.ip != ip or old.hostname != hostname
queue.create(:name => _("Remove DNS record for %s") % old, :priority => 9,
:action => [old, :del_dns_a_record]) if old.dns?
queue.create(:name => _("Remove Reverse DNS record for %s") % old, :priority => 9,
......
end
def dns_conflict_detected?
return false if ip.blank? or name.blank?
return false if ip.blank? or hostname.blank?
# can't validate anything if dont have an ip-address yet
return false unless require_ip_validation?
# we should only alert on conflicts if overwrite mode is off
app/models/nic/managed.rb
@dhcp_record ||= Net::DHCP::Record.new(dhcp_attrs)
end
def hostname
unless domain.nil?
"#{name}.#{domain.name}"
else
name
end
end
protected
def uniq_fields_with_hosts
......
def dhcp_attrs
raise ::Foreman::Exception.new(N_("DHCP not supported for this NIC")) unless dhcp?
{
:hostname => name,
:hostname => hostname,
:ip => ip,
:mac => mac,
:proxy => subnet.dhcp_proxy,
test/fixtures/nics.yml
ip: 10.0.0.1
mac: AA:AA:AA:AA:AA:AA
type: Nic::BMC
name: host-bmc.domain.com
name: host-bmc
host: one
attrs:
:username: foo
test/fixtures/subnets.yml
mask: 255.255.255.0
tftp: two
vlanid: 44
five:
name: five
network: 10.0.0.0
mask: 255.255.255.0
dhcp: one
tftp: two
dns: three
test/unit/nic_test.rb
assert_equal subnet.network, interface.network
assert_equal subnet.vlanid, interface.vlanid
end
test "Nic::BMC should have hostname containing name and domain name" do
subnet = subnets(:five)
domain = domains(:mydomain)
interface = nics(:bmc)
interface.subnet = subnet
interface.domain = domain
assert_equal "#{interface.name}.#{interface.domain.name}", interface.hostname
end
test "Nic::BMC should have hostname containing name when domain nil" do
subnet = subnets(:five)
interface = nics(:bmc)
interface.subnet = subnet
interface.domain = nil
assert_equal interface.name, interface.hostname
end
end
test/unit/orchestration/dhcp_test.rb
end
end
def test_bmc_should_have_valid_dhcp_record
if unattended?
b = nics(:bmc)
b.domain = domains(:mydomain)
b.subnet = subnets(:five)
assert b.dhcp?
assert_equal "#{b.name}.#{b.domain.name}-#{b.mac}/#{b.ip}", b.dhcp_record.to_s
end
end
test "jumpstart parameter generation" do
h = hosts(:sol10host)
Resolv::DNS.any_instance.stubs(:getaddress).with("brsla01").returns("2.3.4.5").once
test/unit/orchestration/dns_test.rb
assert_not_nil h.dns_ptr_record
end
end
def test_bmc_should_have_valid_dns_records
if unattended?
b = nics(:bmc)
b.domain = domains(:mydomain)
b.subnet = subnets(:five)
assert b.dns?
assert b.reverse_dns?
assert_equal "#{b.name}.#{b.domain.name}/#{b.ip}", b.dns_a_record.to_s
assert_equal "#{b.ip}/#{b.name}.#{b.domain.name}", b.dns_ptr_record.to_s
end
end
end

Also available in: Unified diff