Skip to content

Commit

Permalink
Fixes #38050 - Add ip6 to search conditions for host_finder
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimShtein committed Dec 1, 2024
1 parent 8e97632 commit 7b2f1fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/services/foreman/unattended_installation/host_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ def find_host_by_ip_or_mac

mac_list = query_params[:mac_list]

query = mac_list.empty? ? { :nics => { :ip => ip } } : ["lower(nics.mac) IN (?)", mac_list]
hosts = Host.joins(:provision_interface).where(query).order(:created_at)
# create base query
hosts = Host.joins(:provision_interface).order(:created_at)
# filter the records either by mac or by the IP address
if mac_list.empty?
hosts = hosts.where(:nics => { :ip => ip }).or(hosts.where(:nics => { :ip6 => ip }))
else
hosts = hosts.where("lower(nics.mac) IN (?)", mac_list)
end

Rails.logger.warn("Multiple hosts found with #{ip} or #{mac_list}, picking up the most recent") if hosts.count > 1

Expand Down
17 changes: 17 additions & 0 deletions test/controllers/unattended_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ class UnattendedControllerTest < ActionController::TestCase
assert_response :success
end

test "should get a kickstart when pure IPv6 address is used" do
ptable = Ptable.find_by(name: 'default')
@ipv6_host = FactoryBot.create(:host, :managed, :with_ipv6, :build => true,
:operatingsystem => operatingsystems(:redhat),
:ptable => ptable,
:medium => media(:one),
:architecture => architectures(:x86_64),
:organization => @org,
:location => @loc
)
@request.env["HTTP_X_FORWARDED_FOR"] = @ipv6_host.ip6
@request.env["REMOTE_ADDR"] = "::1"
get :host_template, params: { :kind => 'provision' }
assert_response :success
end


test "should set @static when requested" do
Setting[:safemode_render] = false
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{@rh_host.mac}"
Expand Down

0 comments on commit 7b2f1fd

Please sign in to comment.