diff --git a/Gemfile b/Gemfile index 366b326c390..25be1017622 100644 --- a/Gemfile +++ b/Gemfile @@ -84,3 +84,5 @@ if File.exist? "#{__FILE__}.local" end # vim:filetype=ruby + +gem "erb", "~> 6.0" diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index ec31c7a21c2..b87a02157d9 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -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) diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index 957df9bffa7..2908294abdd 100644 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -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 = {}) diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 578d748178c..2f8880a99f4 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -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 @@ -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] @@ -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 @@ -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? diff --git a/spec/unit/configurer_spec.rb b/spec/unit/configurer_spec.rb index 04c8f1abbe9..303fc3a8ee6 100644 --- a/spec/unit/configurer_spec.rb +++ b/spec/unit/configurer_spec.rb @@ -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] = [] diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb index ad9849e7b6b..5bea31d4327 100644 --- a/spec/unit/node/facts_spec.rb +++ b/spec/unit/node/facts_spec.rb @@ -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") diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb index bb0640b6b94..cf40198ecc9 100644 --- a/spec/unit/transaction/report_spec.rb +++ b/spec/unit/transaction/report_spec.rb @@ -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