Skip to content

Commit b1fe48c

Browse files
committed
Fix MODULES-10876 - use new client platform
1 parent 293d959 commit b1fe48c

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/puppet/util/puppetdb_validator.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
# Validator class, for testing that PuppetDB is alive
44
class Puppet::Util::PuppetdbValidator
5-
attr_reader :puppetdb_server
6-
attr_reader :puppetdb_port
7-
attr_reader :use_ssl
8-
attr_reader :test_path
5+
attr_reader :test_uri
96
attr_reader :test_headers
107

118
def initialize(puppetdb_server, puppetdb_port, use_ssl = true, test_path = '/pdb/meta/v1/version')
12-
@puppetdb_server = puppetdb_server
13-
@puppetdb_port = puppetdb_port
14-
@use_ssl = use_ssl
15-
@test_path = test_path
9+
@test_uri = URI("#{use_ssl ? 'https' : 'http'}://#{puppetdb_server}:#{puppetdb_port}#{test_path}")
1610
@test_headers = { 'Accept' => 'application/json' }
1711
end
1812

@@ -25,16 +19,17 @@ def attempt_connection
2519
# All that we care about is that we are able to connect successfully via
2620
# http(s), so here we're simpling hitting a somewhat arbitrary low-impact URL
2721
# on the puppetdb server.
28-
conn = Puppet::Network::HttpPool.http_instance(puppetdb_server, puppetdb_port, use_ssl)
22+
conn = Puppet.runtime[:http]
2923

30-
response = conn.get(test_path, test_headers)
31-
unless response.is_a?(Net::HTTPSuccess)
32-
Puppet.notice "Unable to connect to puppetdb server (http#{use_ssl ? 's' : ''}://#{puppetdb_server}:#{puppetdb_port}): [#{response.code}] #{response.msg}"
24+
response = conn.get(test_uri, headers: test_headers)
25+
if response.is_a?(Puppet::HTTP::ResponseNetHTTP) && response.success?
26+
return true
27+
else
28+
Puppet.notice "Unable to connect to puppetdb server (#{test_uri}): [#{response.code}] #{response.reason}"
3329
return false
3430
end
35-
return true
3631
rescue StandardError => e
37-
Puppet.notice "Unable to connect to puppetdb server (http#{use_ssl ? 's' : ''}://#{puppetdb_server}:#{puppetdb_port}): #{e.message}"
32+
Puppet.notice "Unable to connect to puppetdb server (#{test_uri}): #{e.message}"
3833
return false
3934
end
4035
end

0 commit comments

Comments
 (0)