diff --git a/app/controllers/unattended_controller.rb b/app/controllers/unattended_controller.rb index c039c07c8ce..e13566ce9e1 100644 --- a/app/controllers/unattended_controller.rb +++ b/app/controllers/unattended_controller.rb @@ -217,8 +217,16 @@ def update_ip logger.debug "Built notice from #{ip}, current host ip is #{@host.ip}, updating" if @host.ip != ip # @host has been changed even if the save fails, so we have to change it back - old_ip = @host.ip - @host.ip = old_ip unless @host.update({'ip' => ip}) + address = IPAddr.new(ip) + if address.ipv4? + old_ip = @host.ip + @host.ip = old_ip unless @host.update({'ip' => ip}) + end + + if address.ipv6? + old_ip = @host.ip6 + @host.ip6 = old_ip unless @host.update({'ip6' => ip}) + end end def ipxe_request? diff --git a/test/controllers/unattended_controller_test.rb b/test/controllers/unattended_controller_test.rb index ec04f7cdde1..21dc0588b18 100644 --- a/test/controllers/unattended_controller_test.rb +++ b/test/controllers/unattended_controller_test.rb @@ -373,6 +373,16 @@ class UnattendedControllerTest < ActionController::TestCase refute nic.build end + test "should accept built notifications over ipv6 and store the address" do + nic6 = FactoryBot.build(:nic_managed, :with_ipv6) + Setting[:update_ip_from_built_request] = true + @request.env["REMOTE_ADDR"] = nic6.ip6 + post :built, params: { mac: @ub_host.primary_interface.mac } + assert_response :created + @ub_host.reload + assert_equal nic6.ip6, @ub_host.primary_interface.ip6 + end + test "should accept failed notifications" do @request.env["REMOTE_ADDR"] = @ub_host.ip post :failed