Skip to content

Commit b4bd8e2

Browse files
ShimShteinstejskalleos
authored andcommitted
Fixes #38050 - Add ip6 to search conditions for host_finder
1 parent 820308f commit b4bd8e2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

app/services/foreman/unattended_installation/host_finder.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ def find_host_by_ip_or_mac
5454

5555
mac_list = query_params[:mac_list]
5656

57-
query = mac_list.empty? ? { :nics => { :ip => ip } } : ["lower(nics.mac) IN (?)", mac_list]
58-
hosts = Host.joins(:provision_interface).where(query).order(:created_at)
57+
# create base query
58+
hosts = Host.joins(:provision_interface).order(:created_at)
59+
# filter the records either by mac or by the IP address
60+
if mac_list.empty?
61+
hosts = hosts.where(:nics => { :ip => ip }).or(hosts.where(:nics => { :ip6 => ip }))
62+
else
63+
hosts = hosts.where("lower(nics.mac) IN (?)", mac_list)
64+
end
5965

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

test/controllers/unattended_controller_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ class UnattendedControllerTest < ActionController::TestCase
7575
assert_response :success
7676
end
7777

78+
test "should get a kickstart when pure IPv6 address is used" do
79+
ptable = Ptable.find_by(name: 'default')
80+
@ipv6_host = FactoryBot.create(:host, :managed, :with_ipv6, :build => true,
81+
:operatingsystem => operatingsystems(:redhat),
82+
:ptable => ptable,
83+
:medium => media(:one),
84+
:architecture => architectures(:x86_64),
85+
:organization => @org,
86+
:location => @loc)
87+
@request.env["HTTP_X_FORWARDED_FOR"] = @ipv6_host.ip6
88+
@request.env["REMOTE_ADDR"] = "::1"
89+
get :host_template, params: { :kind => 'provision' }
90+
assert_response :success
91+
end
92+
7893
test "should set @static when requested" do
7994
Setting[:safemode_render] = false
8095
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{@rh_host.mac}"

0 commit comments

Comments
 (0)