Skip to content

Commit 6e090a7

Browse files
author
Andrew Roetker
committed
(PDB-1485) Add default PuppetDB root context
This commit changes the terminus configuration to use the new root prefix for PuppetDB and changes the connection validator to do the same. This commit also adds the terminus package name changes `terminus` to `termini` and tries to be smart about the default, checking to see what version of PuppetDB was passed in and defaulting off of that value.
1 parent 4e407f8 commit 6e090a7

6 files changed

Lines changed: 50 additions & 43 deletions

File tree

lib/puppet/util/puppetdb_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PuppetdbValidator
1010
attr_reader :test_path
1111
attr_reader :test_headers
1212

13-
def initialize(puppetdb_server, puppetdb_port, use_ssl=true, test_path = "/v3/version")
13+
def initialize(puppetdb_server, puppetdb_port, use_ssl=true, test_path = "/pdb/query/v4/version")
1414
@puppetdb_server = puppetdb_server
1515
@puppetdb_port = puppetdb_port
1616
@use_ssl = use_ssl

manifests/master/config.pp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,27 @@
2323
$puppet_confdir = $puppetdb::params::puppet_confdir,
2424
$puppet_conf = $puppetdb::params::puppet_conf,
2525
$puppetdb_version = $puppetdb::params::puppetdb_version,
26-
$terminus_package = $puppetdb::params::terminus_package,
26+
$terminus_package = '',
2727
$puppet_service_name = $puppetdb::params::puppet_service_name,
2828
$puppetdb_startup_timeout = $puppetdb::params::puppetdb_startup_timeout,
2929
$test_url = $puppetdb::params::test_url,
3030
$restart_puppet = true,
3131
) inherits puppetdb::params {
3232

33-
package { $terminus_package:
33+
if empty($terminus_package) {
34+
$old_terminus_name = versioncmp($puppetdb_version, '3.0.0') < 0
35+
$terminus_package_name = $puppetdb_version ? {
36+
/(latest|present|absent)/ => 'puppetdb-termini',
37+
default => $old_terminus_name ? {
38+
true => 'puppetdb-terminus',
39+
false => 'puppetdb-termini'
40+
}
41+
}
42+
} else {
43+
$terminus_package_name = $terminus_package
44+
}
45+
46+
package { $terminus_package_name:
3447
ensure => $puppetdb_version,
3548
}
3649

@@ -52,7 +65,7 @@
5265
default => true,
5366
},
5467
timeout => $puppetdb_startup_timeout,
55-
require => Package[$terminus_package],
68+
require => Package[$terminus_package_name],
5669
test_url => $test_url,
5770
}
5871

@@ -71,7 +84,7 @@
7184
masterless => $masterless,
7285
require => $strict_validation ? {
7386
true => Puppetdb_conn_validator['puppetdb_conn'],
74-
default => Package[$terminus_package],
87+
default => Package[$terminus_package_name],
7588
},
7689
}
7790
}
@@ -85,7 +98,7 @@
8598
masterless => $masterless,
8699
require => $strict_validation ? {
87100
true => Puppetdb_conn_validator['puppetdb_conn'],
88-
default => Package[$terminus_package],
101+
default => Package[$terminus_package_name],
89102
},
90103
}
91104
}
@@ -100,7 +113,7 @@
100113
enable => $enable_reports,
101114
require => $strict_validation ? {
102115
true => Puppetdb_conn_validator['puppetdb_conn'],
103-
default => Package[$terminus_package],
116+
default => Package[$terminus_package_name],
104117
},
105118
}
106119
}
@@ -115,7 +128,7 @@
115128
puppet_confdir => $puppet_confdir,
116129
require => $strict_validation ? {
117130
true => Puppetdb_conn_validator['puppetdb_conn'],
118-
default => Package[$terminus_package],
131+
default => Package[$terminus_package_name],
119132
},
120133
}
121134
}

manifests/master/puppetdb_conf.pp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616
path => "${puppet_confdir}/puppetdb.conf",
1717
}
1818

19-
ini_setting { 'puppetdbserver':
20-
setting => 'server',
21-
value => $server,
22-
}
23-
24-
ini_setting { 'puppetdbport':
25-
setting => 'port',
26-
value => $port,
19+
ini_setting { 'puppetdbserver_urls':
20+
setting => 'server_urls',
21+
value => "https://#{server}:#{port}/",
2722
}
2823

2924
ini_setting { 'soft_write_failure':

manifests/params.pp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@
5858

5959
$manage_firewall = true
6060
$java_args = {}
61-
$test_url = '/v3/version'
61+
$test_url = '/pdb/query/v4/version'
6262

6363
$puppetdb_package = 'puppetdb'
6464
$puppetdb_service = 'puppetdb'
6565
$puppetdb_user = 'puppetdb'
6666
$puppetdb_group = 'puppetdb'
6767
$masterless = false
68-
$terminus_package = 'puppetdb-terminus'
6968

7069
case $::osfamily {
7170
'RedHat', 'Suse', 'Archlinux': {

spec/unit/classes/master/config_spec.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,53 @@
2626
context 'when PuppetDB and Puppet Master are on the same server' do
2727

2828
context 'when using default values' do
29-
3029
let(:pre_condition) { 'class { "puppetdb": }' }
3130

3231
it { should contain_puppetdb_conn_validator('puppetdb_conn').with(
33-
:puppetdb_server => 'puppetdb.example.com',
34-
:puppetdb_port => '8081',
35-
:use_ssl => 'true') }
32+
:puppetdb_server => 'puppetdb.example.com',
33+
:puppetdb_port => '8081',
34+
:use_ssl => 'true') }
3635
end
3736

3837
context 'when puppetdb class is declared with disable_ssl => true' do
39-
4038
let(:pre_condition) { 'class { "puppetdb": disable_ssl => true }' }
4139

4240
it { should contain_puppetdb_conn_validator('puppetdb_conn').with(
43-
:puppetdb_port => '8080',
44-
:use_ssl => 'false')
45-
}
46-
41+
:puppetdb_port => '8080',
42+
:use_ssl => 'false')}
4743
end
4844

4945
context 'when puppetdb_port => 1234' do
50-
5146
let(:pre_condition) { 'class { "puppetdb": }' }
52-
5347
let(:params) do { :puppetdb_port => '1234' } end
5448

5549
it { should contain_puppetdb_conn_validator('puppetdb_conn').with(
56-
:puppetdb_port => '1234',
57-
:use_ssl => 'true')
58-
}
59-
50+
:puppetdb_port => '1234',
51+
:use_ssl => 'true')}
6052
end
6153

6254
context 'when puppetdb_port => 1234 AND the puppetdb class is declared with disable_ssl => true' do
63-
6455
let(:pre_condition) { 'class { "puppetdb": disable_ssl => true }' }
65-
66-
let(:params) do {
67-
:puppetdb_port => '1234'
68-
} end
56+
let(:params) do {:puppetdb_port => '1234'} end
6957

7058
it { should contain_puppetdb_conn_validator('puppetdb_conn').with(
71-
:puppetdb_port => '1234',
72-
:use_ssl => 'false')
73-
}
59+
:puppetdb_port => '1234',
60+
:use_ssl => 'false')}
7461

7562
end
63+
64+
context 'when using default values' do
65+
let (:pre_condition) { 'class { "puppetdb": }' }
66+
67+
it { should contain_package('puppetdb-termini').with( :ensure => 'present' )}
68+
end
69+
70+
context 'when using an older puppetdb version' do
71+
let (:pre_condition) { 'class { "puppetdb": puppetdb_version => "2.2.0", }' }
72+
let (:params) do { :puppetdb_version => '2.2.0' } end
73+
74+
it { should contain_package('puppetdb-terminus').with( :ensure => '2.2.0' )}
75+
end
7676

7777
end
7878

spec/unit/util/puppetdb_validator_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
response_not_found.stubs(:msg).returns('Not found')
1313

1414
conn_ok = stub()
15-
conn_ok.stubs(:get).with('/v3/version', {"Accept" => "application/json"}).returns(response_ok)
15+
conn_ok.stubs(:get).with('/pdb/query/v4/version', {"Accept" => "application/json"}).returns(response_ok)
1616
conn_ok.stubs(:read_timeout=).with(2)
1717
conn_ok.stubs(:open_timeout=).with(2)
1818

1919
conn_not_found = stub()
20-
conn_not_found.stubs(:get).with('/v3/version', {"Accept" => "application/json"}).returns(response_not_found)
20+
conn_not_found.stubs(:get).with('/pdb/query/v4/version', {"Accept" => "application/json"}).returns(response_not_found)
2121

2222
Puppet::Network::HttpPool.stubs(:http_instance).raises('Unknown host')
2323
Puppet::Network::HttpPool.stubs(:http_instance).with('mypuppetdb.com', 8080, true).raises('Connection refused')

0 commit comments

Comments
 (0)