Revision 87c6feb2
Added by Baptiste AGASSE about 9 years ago
app/models/concerns/orchestration/dhcp.rb | ||
---|---|---|
|
||
# do we need to update our dhcp reservations
|
||
def dhcp_update_required?
|
||
# IP Address / name changed
|
||
return true if ((old.ip != ip) or (old.hostname != hostname) or (old.mac != mac) or (old.subnet != subnet))
|
||
# IP Address / name changed, or 'rebuild' action is triggered and DHCP record on the smart proxy is not present/identical.
|
||
return true if ((old.ip != ip) or (old.hostname != hostname) or (old.mac != mac) or (old.subnet != subnet) or
|
||
(!old.build? and build? and !dhcp_record.valid?))
|
||
# Handle jumpstart
|
||
#TODO, abstract this way once interfaces are fully used
|
||
if self.is_a?(Host::Base) and jumpstart?
|
test/unit/orchestration/dhcp_test.rb | ||
---|---|---|
assert_equal 1, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
end
|
||
|
||
test "when an existing host trigger a 'rebuild', its dhcp record should be updated if no dhcp record is found" do
|
||
Net::DHCP::Record.any_instance.stubs(:valid?).returns(false)
|
||
h = FactoryGirl.create(:host, :with_dhcp_orchestration)
|
||
|
||
h.build = true
|
||
|
||
assert h.valid?, h.errors.messages.to_s
|
||
assert_equal 2, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 1, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
end
|
||
|
||
test "when an existing host trigger a 'rebuild', its dhcp record should not be updated if valid dhcp record is found" do
|
||
Net::DHCP::Record.any_instance.stubs(:valid?).returns(true)
|
||
h = FactoryGirl.create(:host, :with_dhcp_orchestration)
|
||
|
||
h.build = true
|
||
|
||
assert h.valid?, h.errors.messages.to_s
|
||
assert_equal 1, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 0, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
end
|
||
|
||
test "when an existing host change its bmc mac address, its dhcp record should be updated" do
|
||
h = FactoryGirl.create(:host, :with_dhcp_orchestration)
|
||
as_admin do
|
Also available in: Unified diff
Fixes #1536 - Foreman should check DHCP entries on build.