Skip to content
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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ if File.exist? "#{__FILE__}.local"
end

# vim:filetype=ruby

gem "erb", "~> 6.0"
1 change: 1 addition & 0 deletions lib/puppet/configurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def run(options = {})
# exceptions.
options[:report] ||= Puppet::Transaction::Report.new(nil, @environment, @transaction_uuid, @job_id, options[:start_time] || Time.now)
report = options[:report]
report.ca_server = "#{Puppet[:ca_server]}:#{Puppet[:ca_port]}"
init_storage

Puppet::Util::Log.newdestination(report)
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/node/facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def add_local_facts
values["clientcert"] = Puppet.settings[:certname]
values["clientversion"] = Puppet.version.to_s
values["clientnoop"] = Puppet.settings[:noop]
values["ca_server"] = "#{Puppet.settings[:ca_server]}:#{Puppet.settings[:ca_port]}"
end

def initialize(name, values = {})
Expand Down
10 changes: 10 additions & 0 deletions lib/puppet/transaction/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class Puppet::Transaction::Report
# @return [String] a string of the format 'servername:port'
attr_accessor :server_used

# Contains the name and port of the configured Puppet CA server
# @return [String] a string of the format 'caname:caport'
attr_accessor :ca_server

# The host name for which the report is generated
# @return [String] the host name
attr_accessor :host
Expand Down Expand Up @@ -240,6 +244,7 @@ def initialize(configuration_version = nil, environment = nil, transaction_uuid
@catalog_uuid = nil
@cached_catalog_status = nil
@server_used = nil
@ca_server = nil
@environment = environment
@status = 'failed' # assume failed until the report is finalized
@noop = Puppet[:noop]
Expand Down Expand Up @@ -269,6 +274,10 @@ def initialize_from_hash(data)
@server_used = data['master_used']
end

if data['ca_server']
@ca_server = data['ca_server']
end

if data['catalog_uuid']
@catalog_uuid = data['catalog_uuid']
end
Expand Down Expand Up @@ -352,6 +361,7 @@ def to_data_hash

# The following is include only when set
hash['server_used'] = @server_used unless @server_used.nil?
hash['ca_server'] = @ca_server unless @ca_server.nil?
hash['catalog_uuid'] = @catalog_uuid unless @catalog_uuid.nil?
hash['code_id'] = @code_id unless @code_id.nil?
hash['job_id'] = @job_id unless @job_id.nil?
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/configurer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,17 @@ def expects_neither_new_or_cached_catalog
end
end

describe "when populating ca_server on the report" do
it "sets report.ca_server from configured ca_server and ca_port" do
Puppet[:ca_server] = "ca.example.com"
Puppet[:ca_port] = 8141

options = {}
configurer.run(options)
expect(options[:report].ca_server).to eq("ca.example.com:8141")
end
end

describe "when attempting failover" do
it "should not failover if server_list is not set" do
Puppet.settings[:server_list] = []
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/node/facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
expect(@facts.values["clientnoop"]).to eq(Puppet.settings[:noop])
end

it "adds the configured CA server and port as 'ca_server'" do
Puppet[:ca_server] = "ca.example.com"
Puppet[:ca_port] = 8141
@facts.add_local_facts
expect(@facts.values["ca_server"]).to eq("ca.example.com:8141")
end

it "doesn't add the current environment" do
@facts.add_local_facts
expect(@facts.values).not_to include("environment")
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/transaction/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,31 @@
end
end

describe "ca_server" do
it "defaults to nil" do
report = Puppet::Transaction::Report.new
expect(report.ca_server).to be_nil
end

it "round-trips through to_data_hash and from_data_hash when set" do
report = Puppet::Transaction::Report.new
report.ca_server = "ca.example.com:8140"
parsed = Puppet::Transaction::Report.from_data_hash(report.to_data_hash)
expect(parsed.ca_server).to eq("ca.example.com:8140")
end

it "is omitted from to_data_hash when nil" do
report = Puppet::Transaction::Report.new
expect(report.to_data_hash).not_to have_key('ca_server')
end

it "is included in to_data_hash when set" do
report = Puppet::Transaction::Report.new
report.ca_server = "ca.example.com:8140"
expect(report.to_data_hash['ca_server']).to eq("ca.example.com:8140")
end
end

describe "before finalizing the report" do
it "should have a status of 'failed'" do
report = Puppet::Transaction::Report.new
Expand Down