Skip to content

Commit

Permalink
Test puppet::config without preconditions
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Oct 26, 2018
1 parent 50d808e commit b704527
Showing 1 changed file with 95 additions and 156 deletions.
251 changes: 95 additions & 156 deletions spec/classes/puppet_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,254 +1,193 @@
require 'spec_helper'

describe 'puppet::config' do
describe 'puppet' do
on_os_under_test.each do |os, facts|
context "on #{os}" do

newline = facts[:osfamily] == 'windows' ? "\r\n" : "\n"

case facts[:osfamily]
when 'FreeBSD'
dir_owner = 'puppet'
dir_group = 'puppet'
codedir = '/usr/local/etc/puppet'
confdir = '/usr/local/etc/puppet'
logdir = '/var/log/puppet'
rundir = '/var/run/puppet'
ssldir = '/var/puppet/ssl'
vardir = '/var/puppet'
sharedir = '/usr/local/share/puppet'
when 'windows'
dir_owner = nil
dir_group = nil
codedir = 'C:/ProgramData/PuppetLabs/puppet/etc'
confdir = 'C:/ProgramData/PuppetLabs/puppet/etc'
logdir = 'C:/ProgramData/PuppetLabs/puppet/var/log'
rundir = 'C:/ProgramData/PuppetLabs/puppet/var/run'
ssldir = 'C:/ProgramData/PuppetLabs/puppet/etc/ssl'
vardir = 'C:/ProgramData/PuppetLabs/puppet/var'
sharedir = 'C:/ProgramData/PuppetLabs/puppet/share'
else
dir_owner = 'root'
dir_group = nil
codedir = '/etc/puppetlabs/code'
confdir = '/etc/puppetlabs/puppet'
logdir = '/var/log/puppetlabs/puppet'
rundir = '/var/run/puppetlabs'
ssldir = '/etc/puppetlabs/puppet/ssl'
vardir = '/opt/puppetlabs/puppet/cache'
sharedir = '/opt/puppetlabs/puppet'
end

let :facts do
facts.merge(domain: 'example.org')
end

describe 'with default parameters' do
let :pre_condition do
'include ::puppet'
end

it 'should contain confdir' do
should contain_file(confdir)
.with_owner(dir_owner)
.with_group(dir_group)
end

it 'should contain auth.conf' do
should_not contain_file("#{confdir}/auth.conf").with_content(%r{^path /certificate_revocation_list/ca#{newline}method find#{newline}})
should contain_file("#{confdir}/auth.conf").with_content(%r{/puppet/v3/})
end

it 'should_not contain default_manifest setting in puppet.conf' do
should_not contain_puppet__config__main("default_manifest")
end

it 'should_not contain default manifest /etc/puppet/manifests/default_manifest.pp' do
should_not contain_file('/etc/puppet/manifests/default_manifest.pp')
end

it 'should_not contain reports setting in puppet.conf' do
should_not contain_puppet__config__main("reports")
end
let :params do
{}
end

it 'should contain puppet.conf [main]' do
should contain_puppet__config__main("vardir").with({'value' => "#{vardir}"})
should contain_puppet__config__main("logdir").with({'value' => "#{logdir}"})
should contain_puppet__config__main("rundir").with({'value' => "#{rundir}"})
should contain_puppet__config__main("ssldir").with({'value' => "#{ssldir}"})
should contain_puppet__config__main("privatekeydir").with({'value' => '$ssldir/private_keys { group = service }'})
should contain_puppet__config__main("hostprivkey").with({'value' => '$privatekeydir/$certname.pem { mode = 640 }'})
should contain_puppet__config__main("show_diff").with({'value' => 'false'})
should contain_puppet__config__main("server").with({'value' => "#{facts[:fqdn]}"})
end
describe 'with default parameters' do
it { is_expected.to contain_file(confdir).with_owner(dir_owner).with_group(dir_group) }
it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{/puppet/v3/}) }
it { is_expected.not_to contain_file("#{confdir}/auth.conf").with_content(%r{^path /certificate_revocation_list/ca#{newline}method find#{newline}}) }
it { is_expected.not_to contain_puppet__config__main('default_manifest') }
it { is_expected.not_to contain_file('/etc/puppet/manifests/default_manifest.pp') }
it { is_expected.not_to contain_puppet__config__main('reports') }
it { is_expected.to contain_puppet__config__main('vardir').with_value(vardir) }
it { is_expected.to contain_puppet__config__main('logdir').with_value(logdir) }
it { is_expected.to contain_puppet__config__main('rundir').with_value(rundir) }
it { is_expected.to contain_puppet__config__main('ssldir').with_value(ssldir) }
it { is_expected.to contain_puppet__config__main('privatekeydir').with_value('$ssldir/private_keys { group = service }') }
it { is_expected.to contain_puppet__config__main('hostprivkey').with_value('$privatekeydir/$certname.pem { mode = 640 }') }
it { is_expected.to contain_puppet__config__main('show_diff').with_value('false') }
it { is_expected.to contain_puppet__config__main('server').with_value(facts[:fqdn]) }
end

describe 'with allow_any_crl_auth' do
let :pre_condition do
'class {"::puppet": allow_any_crl_auth => true}'
let :params do
super().merge(allow_any_crl_auth: true)
end

it 'should contain auth.conf with auth any' do
should contain_file("#{confdir}/auth.conf").with_content(%r{^path /puppet-ca/v1/certificate_revocation_list/ca#{newline}auth any#{newline}})
end
it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /puppet-ca/v1/certificate_revocation_list/ca#{newline}auth any#{newline}}) }
end

describe 'with auth_allowed' do
let :pre_condition do
'class {"::puppet": auth_allowed => [\'$1\', \'puppetproxy\']}'
let :params do
super().merge(auth_allowed: ['$1', 'puppetproxy'])
end

it 'should contain auth.conf with allow' do
should contain_file("#{confdir}/auth.conf").with_content(%r{^allow \$1, puppetproxy#{newline}})
end
it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(/^allow \$1, puppetproxy#{newline}/) }
end

describe "when dns_alt_names => ['foo','bar']" do
let :pre_condition do
"class { 'puppet': dns_alt_names => ['foo','bar'] }"
let :params do
super().merge(dns_alt_names: %w[foo bar])
end

it 'should contain puppet.conf [main] with dns_alt_names' do
should contain_puppet__config__main("dns_alt_names").with({'value' => ['foo','bar']})
end
it { is_expected.to contain_puppet__config__main('dns_alt_names').with_value(%w[foo bar]) }
end

describe "when syslogfacility => 'local6'" do
let :pre_condition do
"class { 'puppet': syslogfacility => 'local6' }"
let :params do
super().merge(syslogfacility: 'local6')
end

it 'should contain puppet.conf [main] with syslogfacility' do
should contain_puppet__config__main("syslogfacility").with({'value' => 'local6'})
end
it { is_expected.to contain_puppet__config__main('syslogfacility').with_value('local6') }
end

describe "when puppetmaster => 'mymaster.example.com'" do
let :pre_condition do
"class { 'puppet': puppetmaster => 'mymaster.example.com' }"
describe "when module_repository => 'https://myforgeapi.example.com'" do
let :params do
super().merge(module_repository: 'https://myforgeapi.example.com')
end

it "should contain puppet.conf [main] with server = 'mymaster.example.com'" do
should contain_puppet__config__main('server').with({'value' => 'mymaster.example.com'})
end
it { is_expected.to contain_puppet__config__main('module_repository').with_value('https://myforgeapi.example.com') }
end

describe "when module_repository => 'https://myforgeapi.example.com'" do
let :pre_condition do
"class { 'puppet': module_repository => 'https://myforgeapi.example.com' }"
describe 'when use_srv_records => true' do
let :params do
super().merge(use_srv_records: true)
end

it 'should contain puppet.conf [main] with module_repository' do
should contain_puppet__config__main("module_repository").with({'value' => 'https://myforgeapi.example.com'})
context 'domain fact is defined' do
it { is_expected.to contain_puppet__config__main('use_srv_records').with_value('true') }
it { is_expected.to contain_puppet__config__main('srv_domain').with_value('example.org') }
it { is_expected.to contain_puppet__config__main('pluginsource').with_value('puppet:///plugins') }
it { is_expected.to contain_puppet__config__main('pluginfactsource').with_value('puppet:///pluginfacts') }
it { is_expected.not_to contain_puppet__config__main('server') }
end
end

describe "when use_srv_records => true, and domain fact" do
context 'is defined' do
let :pre_condition do
"class { 'puppet': use_srv_records => true }"
end
context 'domain fact is unset' do
let(:facts) { facts.merge(domain: nil) }

it 'should contain puppet.conf [main] with SRV settings' do
should contain_puppet__config__main("use_srv_records").with({'value' => "true"})
should contain_puppet__config__main("srv_domain").with({'value' => "example.org"})
should contain_puppet__config__main("pluginsource").with({'value' => "puppet:///plugins"})
should contain_puppet__config__main("pluginfactsource").with({'value' => "puppet:///pluginfacts"})
end
it { is_expected.to raise_error(Puppet::Error, /\$::domain fact found to be undefined and \$srv_domain is undefined/) }
end

it 'should not contain server setting' do
should_not contain_puppet__config__main('server')
context 'is overriden via param' do
let :params do
super().merge(srv_domain: 'special.example.com')
end

it { is_expected.to contain_puppet__config__main('use_srv_records').with_value(true) }
it { is_expected.to contain_puppet__config__main('srv_domain').with_value('special.example.com') }
end
end

context 'is unset' do
let(:facts) { facts.merge({domain: nil}) }
let :pre_condition do
'class { ::puppet:
use_srv_records => true
}'
context 'puppetmaster' do
describe "when puppetmaster => 'mymaster.example.com'" do
let :params do
super().merge(puppetmaster: 'mymaster.example.com')
end

it 'should fail with a helpful message' do
should raise_error(Puppet::Error, /\$::domain fact found to be undefined and \$srv_domain is undefined/)
end
it { is_expected.to contain_puppet__config__main('server').with_value('mymaster.example.com') }
end

context 'is overriden via param' do
let :pre_condition do
'class { "::puppet":
use_srv_records => true,
srv_domain => "special_domain.com"
}'
describe 'puppetmaster parameter overrides global puppetmaster' do
let :params do
super().merge(puppetmaster: 'mymaster.example.com')
end

it 'should configure srv domain' do
should contain_puppet__config__main('use_srv_records').with_value(true)
should contain_puppet__config__main('srv_domain').with_value('special_domain.com')
let :facts do
facts.merge(puppetmaster: 'global.example.com')
end
end
end

describe 'when listen and listen_to has values' do
let :pre_condition do
'class {"::puppet": listen => true, listen_to => ["node1.example.com","node2.example.com",],}'
it { is_expected.to contain_puppet__config__main('server').with_value('mymaster.example.com') }
end

it 'should contain auth.conf with auth any' do
should contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow node1.example.com,node2.example.com#{newline}})
end
end
describe 'global puppetmaster overrides fqdn' do
let :facts do
facts.merge(puppetmaster: 'global.example.com')
end

describe 'when listen and puppetmaster has value' do
let :pre_condition do
'class {"::puppet": listen => true, puppetmaster => "master.example.com",}'
it { is_expected.to contain_puppet__config__main('server').with_value('global.example.com') }
end

it 'should contain auth.conf with auth any' do
should contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow master.example.com#{newline}})
end
end
context 'when listen' do
let :params do
super().merge(listen: true)
end

describe 'when listen => true and default value is used' do
let :pre_condition do
'class {"::puppet": listen => true}'
end
describe 'puppetmaster default value is used' do
it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow #{facts[:fqdn]}#{newline}}) }
end

it 'should contain auth.conf with auth any' do
should contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow #{facts[:fqdn]}#{newline}})
end
end
describe 'puppetmaster has value' do
let :params do
super().merge(puppetmaster: 'mymaster.example.com')
end

describe 'with additional settings' do
let :pre_condition do
"class {'puppet':
additional_settings => {disable_warnings => deprecations},
}"
end
it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow mymaster.example.com#{newline}}) }
end

it 'should configure puppet.conf' do
should contain_puppet__config__main("disable_warnings").with({'value' => "deprecations"})
end
end
describe 'listen_to has values' do
let :params do
super().merge(listen_to: ['node1.example.com', 'node2.example.com'])
end

describe 'puppetmaster parameter overrides global puppetmaster' do
let(:pre_condition) { "class {'puppet': puppetmaster => 'mymaster.example.com'}" }
let :facts do
facts.merge({:puppetmaster => 'global.example.com'})
end
it do
should contain_puppet__config__main('server').with({'value' => 'mymaster.example.com'})
it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow node1\.example\.com,node2\.example\.com#{newline}}) }
end
end
end

describe 'global puppetmaster overrides fqdn' do
let(:pre_condition) { "include ::puppet" }
let :facts do
facts.merge({:puppetmaster => 'mymaster.example.com'})
end
it do
should contain_puppet__config__main('server').with({'value' => 'mymaster.example.com'})
describe 'with additional settings' do
let :params do
super().merge(additional_settings: { disable_warnings: 'deprecations' })
end

it { is_expected.to contain_puppet__config__main('disable_warnings').with_value('deprecations') }
end
end
end
Expand Down

0 comments on commit b704527

Please sign in to comment.