Skip to content

Commit e7b9060

Browse files
authored
Merge pull request #141 from nmburgan/maint/main/change_default_for_hosts_with_pe_profile
(maint) Change default for hosts_with_pe_profile when storeconfigs is false
2 parents 3717d28 + a689aa1 commit e7b9060

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

functions/hosts_with_pe_profile.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ function puppet_metrics_collector::hosts_with_pe_profile($profile) {
3030
}
3131

3232
if empty($hosts) {
33-
['127.0.0.1']
33+
$default = $facts['clientcert'] ? {
34+
undef => '127.0.0.1',
35+
default => $facts['clientcert']
36+
}
37+
[$default]
3438
}
3539
else {
3640
sort($hosts)

spec/acceptance/functions/hosts_with_pe_profile_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
require 'spec_helper_acceptance'
22

33
describe 'hosts_with_pe_profile function' do
4-
it 'returns 127.0.0.1 when no hosts are found' do
4+
it 'returns the certname of the node when no hosts are found' do
55
pp = <<-MANIFEST
66
$result=puppet_metrics_collector::hosts_with_pe_profile('non_existant')
77
notice "Received=$result"
88
MANIFEST
99
output = apply_manifest(pp).stdout
10-
expect(output).to match(%r{Received=\[127.0.0.1\]})
10+
expect(output).to match(%r{Received=\[#{host_inventory['fqdn']}\]})
1111
end
12+
1213
it 'return the FQDN for the master profile' do
1314
# This influences the custom facts
1415
run_shell('puppet config set storeconfigs true --section user', expect_failures: false)
@@ -20,4 +21,15 @@
2021
expect(output).to match(%r{Received=\[#{host_inventory['fqdn']}\]})
2122
run_shell('puppet config set storeconfigs false --section user', expect_failures: false)
2223
end
24+
25+
it 'returns the certname of the node when storeconfigs is false' do
26+
# Should be set to false in the previous section
27+
# In this case, the certname == fqdn, so we use that here
28+
pp = <<-MANIFEST
29+
$result=puppet_metrics_collector::hosts_with_pe_profile('master')
30+
notice "Received=$result"
31+
MANIFEST
32+
output = apply_manifest(pp).stdout
33+
expect(output).to match(%r{Received=\[#{host_inventory['fqdn']}\]})
34+
end
2335
end

spec/acceptance/pe_metric_spec.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper_acceptance'
22

3+
certname = host_inventory['fqdn']
34
describe 'default includes' do
45
before(:all) do
56
pp = <<-MANIFEST
@@ -31,52 +32,52 @@
3132
expect(files.split("\n").count).to eq(5)
3233
end
3334

34-
describe file('/opt/puppetlabs/puppet-metrics-collector/puppetserver/127.0.0.1') do
35+
describe file("/opt/puppetlabs/puppet-metrics-collector/puppetserver/#{certname}") do
3536
before(:each) { run_shell('systemctl start puppet_puppetserver-metrics.service') }
3637

3738
it { is_expected.to be_directory }
3839
it 'contains metric files' do
39-
files = run_shell('ls /opt/puppetlabs/puppet-metrics-collector/puppetserver/127.0.0.1/*').stdout
40+
files = run_shell("ls /opt/puppetlabs/puppet-metrics-collector/puppetserver/#{certname}/*").stdout
4041
expect(files.split('\n')).not_to be_empty
4142
end
4243
end
4344

44-
describe file('/opt/puppetlabs/puppet-metrics-collector/puppetdb/127.0.0.1') do
45+
describe file("/opt/puppetlabs/puppet-metrics-collector/puppetdb/#{certname}") do
4546
before(:each) { run_shell('systemctl start puppet_puppetdb-metrics.service') }
4647

4748
it { is_expected.to be_directory }
4849
it 'contains metric files' do
49-
files = run_shell('ls /opt/puppetlabs/puppet-metrics-collector/puppetdb/127.0.0.1/*').stdout
50+
files = run_shell("ls /opt/puppetlabs/puppet-metrics-collector/puppetdb/#{certname}/*").stdout
5051
expect(files.split('\n')).not_to be_empty
5152
end
5253
end
5354

54-
describe file('/opt/puppetlabs/puppet-metrics-collector/orchestrator/127.0.0.1') do
55+
describe file("/opt/puppetlabs/puppet-metrics-collector/orchestrator/#{certname}") do
5556
before(:each) { run_shell('systemctl start puppet_orchestrator-metrics.service') }
5657

5758
it { is_expected.to be_directory }
5859
it 'contains metric files' do
59-
files = run_shell('ls /opt/puppetlabs/puppet-metrics-collector/orchestrator/127.0.0.1/*').stdout
60+
files = run_shell("ls /opt/puppetlabs/puppet-metrics-collector/orchestrator/#{certname}/*").stdout
6061
expect(files.split('\n')).not_to be_empty
6162
end
6263
end
6364

64-
describe file('/opt/puppetlabs/puppet-metrics-collector/ace/127.0.0.1') do
65+
describe file("/opt/puppetlabs/puppet-metrics-collector/ace/#{certname}") do
6566
before(:each) { run_shell('systemctl start puppet_ace-metrics.service') }
6667

6768
it { is_expected.to be_directory }
6869
it 'contains metric files' do
69-
files = run_shell('ls /opt/puppetlabs/puppet-metrics-collector/ace/127.0.0.1/*').stdout
70+
files = run_shell("ls /opt/puppetlabs/puppet-metrics-collector/ace/#{certname}/*").stdout
7071
expect(files.split('\n')).not_to be_empty
7172
end
7273
end
7374

74-
describe file('/opt/puppetlabs/puppet-metrics-collector/bolt/127.0.0.1') do
75+
describe file("/opt/puppetlabs/puppet-metrics-collector/bolt/#{certname}") do
7576
before(:each) { run_shell('systemctl start puppet_bolt-metrics.service') }
7677

7778
it { is_expected.to be_directory }
7879
it 'contains metric files' do
79-
files = run_shell('ls /opt/puppetlabs/puppet-metrics-collector/bolt/127.0.0.1/*').stdout
80+
files = run_shell("ls /opt/puppetlabs/puppet-metrics-collector/bolt/#{certname}/*").stdout
8081
expect(files.split('\n')).not_to be_empty
8182
end
8283
end

0 commit comments

Comments
 (0)