diff --git a/lib/puppet/http/session.rb b/lib/puppet/http/session.rb index a81b8d5b066..4a4c9d08162 100644 --- a/lib/puppet/http/session.rb +++ b/lib/puppet/http/session.rb @@ -90,6 +90,9 @@ def process_response(response) site = Puppet::HTTP::Site.from_uri(response.url) @server_versions[site] = version end + if (compiler = response['X-Puppet-Compiler-Name']) + Puppet.notice("Catalog compiled by #{compiler}") + end end # Determine if a session supports a capability. Depending on the server version diff --git a/spec/integration/application/agent_spec.rb b/spec/integration/application/agent_spec.rb index 2198471bb54..5b033665289 100644 --- a/spec/integration/application/agent_spec.rb +++ b/spec/integration/application/agent_spec.rb @@ -33,6 +33,19 @@ def copy_fixtures(sources, dest) end end + context 'server identification' do + it 'emits a notice if the server sends the X-Puppet-Compiler-Name header' do + server.start_server do |port| + Puppet[:serverport] = port + expect { + agent.command_line.args << '--test' + agent.run + }.to exit_with(0) + .and output(%r{Notice: Catalog compiled by test-compiler-hostname}).to_stdout + end + end + end + context 'server_list' do it "uses the first server in the list" do Puppet[:server_list] = '127.0.0.1' diff --git a/spec/lib/puppet_spec/puppetserver.rb b/spec/lib/puppet_spec/puppetserver.rb index ef080e85618..be6e5cc0d67 100644 --- a/spec/lib/puppet_spec/puppetserver.rb +++ b/spec/lib/puppet_spec/puppetserver.rb @@ -19,6 +19,7 @@ def do_GET request, response class CatalogServlet < WEBrick::HTTPServlet::AbstractServlet def do_POST request, response response['Content-Type'] = 'application/json' + response['X-Puppet-Compiler-Name'] = 'test-compiler-hostname' catalog = Puppet::Resource::Catalog.new(Puppet[:certname], 'production') response.body = catalog.render(:json) end diff --git a/spec/unit/http/session_spec.rb b/spec/unit/http/session_spec.rb index 99bf150d696..829bbf7a668 100644 --- a/spec/unit/http/session_spec.rb +++ b/spec/unit/http/session_spec.rb @@ -222,7 +222,10 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end context 'when retrieving capabilities' do - let(:response) { Puppet::HTTP::Response.new(uri, 200, 'OK') } + let(:response) { Puppet::HTTP::ResponseNetHTTP.new(uri, + Net::HTTPResponse.new('http_version', + 200, + "OK")) } let(:session) do resolver = DummyResolver.new(good_service) @@ -244,6 +247,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end it "supports locales if the cached service's version is 5.3.4 or greater" do + allow(response).to receive(:[]).and_call_original allow(response).to receive(:[]).with('X-Puppet-Version').and_return('5.3.4') session.route_to(:puppet) @@ -253,6 +257,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end it "does not support locales if the cached service's version is 5.3.3" do + allow(response).to receive(:[]).and_call_original allow(response).to receive(:[]).with('X-Puppet-Version').and_return('5.3.3') session.route_to(:puppet) @@ -262,6 +267,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end it "does not support locales if the cached service's version is missing" do + allow(response).to receive(:[]).and_call_original allow(response).to receive(:[]).with('X-Puppet-Version').and_return(nil) session.route_to(:puppet) @@ -279,6 +285,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end it "supports json if the cached service's version is 5 or greater" do + allow(response).to receive(:[]).and_call_original allow(response).to receive(:[]).with('X-Puppet-Version').and_return('5.5.12') session.route_to(:puppet) @@ -288,6 +295,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end it "does not support json if the cached service's version is less than 5.0" do + allow(response).to receive(:[]).and_call_original allow(response).to receive(:[]).with('X-Puppet-Version').and_return('4.10.1') session.route_to(:puppet) @@ -297,6 +305,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) end it "supports json if the cached service's version is missing" do + allow(response).to receive(:[]).and_call_original allow(response).to receive(:[]).with('X-Puppet-Version').and_return(nil) session.route_to(:puppet)