Skip to content

Commit

Permalink
Fixes #36639 - Use Templates feature on IPv6
Browse files Browse the repository at this point in the history
This now looks at, and prefers, the IPv6 subnet on the
provision_interface to determine the template proxy. This allows using
the Templates feature in pure IPv6 provisioning setups.
  • Loading branch information
ekohl committed Aug 5, 2023
1 parent 7c41286 commit b8402dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/services/foreman/foreman_url_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def foreman_url_options

host = @host
host = self if @host.nil? && self.class < Host::Base
template_proxy = host.try(:provision_interface).try(:subnet).try(:template_proxy)
template_proxy = host.try(:provision_interface).try(:subnet6).try(:template_proxy)
template_proxy ||= host.try(:provision_interface).try(:subnet).try(:template_proxy)

# Use template_url from the request if set, but otherwise look for a Template
# feature proxy, as PXE templates are written without an incoming request.
Expand Down
41 changes: 37 additions & 4 deletions test/unit/foreman/renderer/scope/macros/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,47 @@ class BaseMacrosTest < ActiveSupport::TestCase
end
end

test "foreman_url should respect proxy with Templates feature" do
test "foreman_url should respect proxy with Templates feature over ipv4" do
host = FactoryBot.build(:host, :with_separate_provision_interface, :with_dhcp_orchestration)
host.provision_interface.subnet.template = FactoryBot.build(:template_smart_proxy)
ProxyAPI::Template.any_instance.stubs(:template_url).returns(host.provision_interface.subnet.template.url)

v4_template_proxy = Minitest::Mock.new()
v4_template_proxy.expects(:template_url, 'http://192.0.2.1')
host.provision_interface.subnet.stubs(:template_proxy).returns(v4_template_proxy)

host.provision_interface.subnet6.stubs(:template_proxy).returns(nil)

@scope.instance_variable_set('@host', host)

assert_match('http://192.0.2.1/', @scope.foreman_url('provision'))
end

test "foreman_url should respect proxy with Templates feature over ipv6" do
host = FactoryBot.build(:host, :with_separate_provision_interface, :with_dhcp_orchestration)

host.provision_interface.subnet.stubs(:template_proxy).returns(nil)

v6_template_proxy = Minitest::Mock.new()
v6_template_proxy.expects(:template_url, 'http://[2001:db8::1]')
host.provision_interface.subnet6.stubs(:template_proxy).returns(v6_template_proxy)

@scope.instance_variable_set('@host', host)

assert_match('http://[2001:db8::1]/', @scope.foreman_url('provision'))
end

test "foreman_url prefer proxy with Templates feature over ipv6" do
host = FactoryBot.build(:host, :with_separate_provision_interface, :with_dhcp_orchestration)

v4_template_proxy = Minitest::Mock.new()
host.provision_interface.subnet.stubs(:template_proxy).returns(v4_template_proxy)

v6_template_proxy = Minitest::Mock.new()
v6.expects(:template_url, 'http://[2001:db8::1]/')
host.provision_interface.subnet6.stubs(:template_proxy).returns(v6_template_proxy)

@scope.instance_variable_set('@host', host)

assert_match(host.provision_interface.subnet.template.url, @scope.foreman_url('provision'))
assert_match('http://[2001:db8::1]/', @scope.foreman_url('provision'))
end

test "foreman_url should run with @host as nil" do
Expand Down

0 comments on commit b8402dd

Please sign in to comment.