1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
require 'spec_helper'
describe 'puppet' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
case os_facts[:osfamily]
when 'FreeBSD'
dir_owner = 'root'
dir_group = nil
confdir = '/usr/local/etc/puppet'
logdir = '/var/log/puppet'
rundir = '/var/run/puppet'
ssldir = '/var/puppet/ssl'
vardir = '/var/puppet'
when 'windows'
dir_owner = nil
dir_group = nil
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'
when 'Archlinux'
dir_owner = 'root'
dir_group = nil
confdir = '/etc/puppetlabs/puppet'
logdir = '/var/log/puppetlabs/puppet'
rundir = '/var/run/puppetlabs'
ssldir = '/etc/puppetlabs/puppet/ssl'
vardir = '/opt/puppetlabs/puppet/cache'
else
dir_owner = 'root'
dir_group = nil
confdir = '/etc/puppetlabs/puppet'
logdir = '/var/log/puppetlabs/puppet'
rundir = '/var/run/puppetlabs'
ssldir = '/etc/puppetlabs/puppet/ssl'
vardir = '/opt/puppetlabs/puppet/cache'
end
let :facts do
override_facts(os_facts, networking: {domain: 'example.org'})
end
let :params do
{}
end
describe 'with default parameters' do
it { is_expected.to contain_file(confdir).with_owner(dir_owner).with_group(dir_group) }
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[:networking]['fqdn']) }
end
describe "when dns_alt_names => ['foo','bar']" do
let :params do
super().merge(dns_alt_names: %w[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 :params do
super().merge(syslogfacility: 'local6')
end
it { is_expected.to contain_puppet__config__main('syslogfacility').with_value('local6') }
end
describe "when module_repository => 'https://myforgeapi.example.com'" do
let :params do
super().merge(module_repository: 'https://myforgeapi.example.com')
end
it { is_expected.to contain_puppet__config__main('module_repository').with_value('https://myforgeapi.example.com') }
end
describe 'when use_srv_records => true' do
let :params do
super().merge(use_srv_records: true)
end
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
context 'domain fact is unset' do
let(:facts) { override_facts(super(), networking: {domain: nil}) }
it { is_expected.to raise_error(Puppet::Error, /domain fact found to be undefined and \$srv_domain is undefined/) }
end
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
describe 'client_certname' do
let(:node) { 'client.example.com' }
context 'with client_certname => trusted certname' do
it { is_expected.to contain_puppet__config__main('certname').with_value('client.example.com') }
end
context 'with client_certname => "foobar"' do
let :params do
super().merge(client_certname: 'foobar')
end
it { is_expected.to contain_puppet__config__main('certname').with_value('foobar') }
end
context 'with client_certname => false' do
let :params do
super().merge(client_certname: false)
end
it { is_expected.not_to contain_puppet__config__main('certname') }
end
end
context 'agent_server_hostname' do
describe "when agent_server_hostname => 'myserver.example.com'" do
let :params do
super().merge(agent_server_hostname: 'myserver.example.com')
end
it { is_expected.to contain_puppet__config__main('server').with_value('myserver.example.com') }
end
# puppetmaster is provided via the Foreman ENC as a global variable
context 'with global puppetmaster' do
let(:facts) { super().merge(puppetmaster: 'global.example.com') }
describe 'it overrides fqdn' do
it { is_expected.to contain_puppet__config__main('server').with_value('global.example.com') }
end
describe 'the agent_server_hostname parameter overrides global puppetmaster' do
let(:params) { super().merge(agent_server_hostname: 'myserver.example.com') }
it { is_expected.to contain_puppet__config__main('server').with_value('myserver.example.com') }
end
end
end
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
end
|