diff --git a/lib/puppet/indirector/catalog/rest.rb b/lib/puppet/indirector/catalog/rest.rb index f246d2eccc9..1766a0180e6 100644 --- a/lib/puppet/indirector/catalog/rest.rb +++ b/lib/puppet/indirector/catalog/rest.rb @@ -13,6 +13,14 @@ def find(request) session = Puppet.lookup(:http_session) api = session.route_to(:puppet) + + ip_address = begin + " (#{Resolv.new.getaddress(api.url.host)})" + rescue Resolv::ResolvError + nil + end + Puppet.notice("Requesting catalog from #{URI(api.url).host}:#{URI(api.url).port}#{ip_address}") + _, catalog = api.post_catalog( request.key, facts: request.options[:facts_for_catalog], diff --git a/spec/unit/indirector/catalog/rest_spec.rb b/spec/unit/indirector/catalog/rest_spec.rb index 4f2730b13f6..6f184ea6c6d 100644 --- a/spec/unit/indirector/catalog/rest_spec.rb +++ b/spec/unit/indirector/catalog/rest_spec.rb @@ -25,6 +25,23 @@ def catalog_response(catalog) expect(described_class.indirection.find(certname)).to be_a(Puppet::Resource::Catalog) end + it 'logs a notice when requesting a catalog' do + expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140") + + stub_request(:post, uri).to_return(**catalog_response(catalog)) + + described_class.indirection.find(certname) + end + + it 'logs a notice when the IP address is resolvable when requesting a catalog' do + allow(Resolv).to receive_message_chain(:new, :getaddress).and_return('192.0.2.0') + expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140 (192.0.2.0)") + + stub_request(:post, uri).to_return(**catalog_response(catalog)) + + described_class.indirection.find(certname) + end + it "serializes the environment" do stub_request(:post, uri) .with(query: hash_including('environment' => 'outerspace'))