Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38050 - Add ip6 to search conditions for host_finder #10391

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions test/controllers/unattended_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ 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
Loading