Skip to content

Commit

Permalink
Fixes #27879 - token is properly generated for iPXE Embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and tbrisker committed May 18, 2020
1 parent 5d32b66 commit 1751098
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/hostext/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Token
scope :for_token, ->(token) { joins(:token).where(:tokens => { :value => token }).where("expires >= ?", Time.now.utc.to_s(:db)).select('hosts.*') }
scope :for_token_when_built, ->(token) { joins(:token).where(:tokens => { :value => token }).select('hosts.*') }

after_validation :refresh_token_on_build
before_validation :refresh_token_on_build
end

# Sets and expire provisioning tokens
Expand Down
9 changes: 7 additions & 2 deletions app/models/concerns/orchestration/dhcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,13 @@ def queue_dhcp_update
# do we need to update our dhcp reservations
def dhcp_update_required?
# IP Address / name changed, or 'rebuild' action is triggered and DHCP record on the smart proxy is not present/identical.
return true if ((old.ip != ip) || (old.hostname != hostname) || provision_mac_addresses_changed? || (old.subnet != subnet) || (operatingsystem.boot_filename(old.host) != operatingsystem.boot_filename(host)) ||
(!old.build? && build? && !all_dhcp_records_valid?))
return true if ((old.ip != ip) ||
(old.hostname != hostname) ||
provision_mac_addresses_changed? ||
(old.subnet != subnet) ||
(old.operatingsystem.boot_filename(old.host) != operatingsystem.boot_filename(host)) ||
((old.host.pxe_loader == "iPXE Embedded" || host.pxe_loader == "iPXE Embedded") && (old.host.build != host.build)) ||
(!old.build? && build? && !all_dhcp_records_valid?))
# Handle jumpstart
# TODO, abstract this way once interfaces are fully used
if is_a?(Host::Base) && jumpstart?
Expand Down
2 changes: 1 addition & 1 deletion lib/foreman/foreman_url_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def render_foreman_url(host, options, params)
url_for :only_path => false, :controller => "/unattended", :action => 'host_template',
:protocol => options[:protocol], :host => options[:host],
:port => options[:port], :script_name => options[:path],
:token => (host.token.value unless host.try(:token).nil?),
:token => (host.token.value if (host.try(:build) && host.try(:token))),
:kind => options[:action], **params
end

Expand Down
4 changes: 4 additions & 0 deletions test/factories/host_related.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ def set_environment_taxonomies(host_or_hostgroup, environment = host_or_hostgrou
set_environment_taxonomies(host)
end

trait :with_build do
build { true }
end

trait :with_model do
model
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/foreman_url_renderer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Renderer
attr_accessor :host, :template_url
end

let(:host) { FactoryBot.build_stubbed(:host, :managed, :with_dhcp_orchestration) }
let(:host) { FactoryBot.build_stubbed(:host, :managed, :with_dhcp_orchestration, :with_build) }
let(:renderer) { Renderer.new }
let(:action) { 'provision' }

Expand Down

0 comments on commit 1751098

Please sign in to comment.