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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
|
require 'spec_helper'
describe 'puppet' do
on_supported_os.each do |os, facts|
context "on #{os}" do
case facts[:osfamily]
when 'FreeBSD'
puppet_major = facts[:puppetversion].to_i
bindir = '/usr/local/bin'
client_package = "puppet#{puppet_major}"
confdir = '/usr/local/etc/puppet'
package_provider = nil
when 'windows'
bindir = 'C:/ProgramData/PuppetLabs/puppet/bin'
client_package = 'puppet-agent'
confdir = 'C:/ProgramData/PuppetLabs/puppet/etc'
package_provider = 'chocolatey'
when 'Archlinux'
bindir = '/usr/bin'
client_package = 'puppet'
confdir = '/etc/puppetlabs/puppet'
package_provider = nil
else
bindir = '/opt/puppetlabs/bin'
client_package = 'puppet-agent'
confdir = '/etc/puppetlabs/puppet'
package_provider = nil
end
let(:facts) do
# Cron/systemd timers are based on the IP - make it consistent
override_facts(facts, networking: {ip: '192.0.2.100'})
end
let :params do
{
agent: true
}
end
describe 'with no custom parameters' do
# For windows we specify a package provider which doesn't compile
if facts[:osfamily] != 'windows'
it { is_expected.to compile.with_all_deps }
end
# install
it do
is_expected.to contain_class('puppet::agent::install')
.with_manage_packages(true)
.with_package_name([client_package])
.with_package_version('present')
.with_package_provider(package_provider)
.with_package_source(nil)
.that_notifies(['Class[puppet::agent::config]', 'Class[puppet::agent::service]'])
end
it do
is_expected.to contain_package(client_package)
.with_ensure('present')
.with_provider(package_provider)
.with_source(nil)
.with_install_options(nil)
end
# config
it { is_expected.to contain_class('puppet::agent::config').that_notifies('Class[puppet::agent::service]') }
it { is_expected.to contain_file(confdir).with_ensure('directory') }
it { is_expected.to contain_concat("#{confdir}/puppet.conf") }
it { is_expected.to contain_concat__fragment('puppet.conf_agent').with_content(/^\[agent\]/) }
it { is_expected.to contain_puppet__config__agent('report').with_value('true') }
it { is_expected.not_to contain_puppet__config__agent('prerun_command') }
it { is_expected.not_to contain_puppet__config__agent('postrun_command') }
# service
it { is_expected.to contain_class('puppet::agent::service') }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(true) }
it do
is_expected.to contain_service('puppet')
.with_ensure('running')
.with_name('puppet')
.with_hasstatus('true')
.with_enable('true')
end
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
if os =~ /\A(windows|archlinux)/
it { is_expected.not_to contain_cron('puppet') }
else
it { is_expected.to contain_cron('puppet').with_ensure('absent') }
end
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
case os
when /\A(debian|redhat|centos|scientific|fedora|ubuntu|sles|archlinux)-/
it do
is_expected.to contain_service('puppet-run.timer')
.with_ensure(false)
.with_provider('systemd')
.with_name('puppet-run.timer')
.with_enable(false)
end
it { is_expected.to contain_file('/etc/systemd/system/puppet-run.timer').with_ensure(:absent) }
it { is_expected.to contain_file('/etc/systemd/system/puppet-run.service').with_ensure(:absent) }
else
it { is_expected.not_to contain_service('puppet-run.timer') }
it { is_expected.not_to contain_file('/etc/systemd/system/puppet-run.timer') }
it { is_expected.not_to contain_file('/etc/systemd/system/puppet-run.service') }
end
end
describe 'set prerun_command will be included in config' do
let :params do
super().merge(prerun_command: '/my/prerun')
end
it { is_expected.to contain_puppet__config__agent('prerun_command').with_value('/my/prerun') }
end
describe 'set postrun_command will be included in config' do
let :params do
super().merge(postrun_command: '/my/postrun')
end
it { is_expected.to contain_puppet__config__agent('postrun_command').with_value('/my/postrun') }
end
describe 'with additional settings' do
let :params do
super().merge(agent_additional_settings: { 'ignoreschedules' => true })
end
it { is_expected.to contain_puppet__config__agent('ignoreschedules').with_value('true') }
end
context 'manage_packages' do
describe 'when manage_packages => false' do
let :params do
super().merge(manage_packages: false)
end
it { is_expected.not_to contain_package(client_package) }
end
describe "when manage_packages => 'agent'" do
let :params do
super().merge(manage_packages: 'agent')
end
it { is_expected.to contain_package(client_package) }
end
describe "when manage_packages => 'server'" do
let :params do
super().merge(manage_packages: 'server')
end
it { is_expected.not_to contain_package(client_package) }
end
end
context 'runmode' do
describe 'when runmode => cron' do
let :params do
super().merge(runmode: 'cron')
end
case os
when /\A(windows|archlinux)/
it { is_expected.to raise_error(Puppet::Error, /Runmode of cron not supported on #{facts[:kernel]} operating systems!/) }
when /\A(debian|redhat|centos|scientific|fedora|ubuntu|sles)-/
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_concat__fragment('puppet.conf_agent') }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it do
is_expected.to contain_service('puppet')
.with_ensure('stopped')
.with_name('puppet')
.with_hasstatus('true')
.with_enable('false')
end
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) }
it do
is_expected.to contain_cron('puppet')
.with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize")
.with_user('root')
.with_minute(%w[10 40])
.with_hour('*')
end
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.not_to contain_service('puppet-run.timer') }
it do
is_expected.to contain_cron('puppet')
.with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize")
.with_user('root')
.with_minute(%w[10 40])
.with_hour('*')
end
end
end
describe 'when runmode => cron with specified time' do
let :params do
super().merge(runmode: 'cron',
run_hour: 22,
run_minute: 01
)
end
case os
when /\A(windows|archlinux)/
it { is_expected.to raise_error(Puppet::Error, /Runmode of cron not supported on #{facts[:kernel]} operating systems!/) }
when /\A(debian|redhat|centos|scientific|fedora|ubuntu|sles)-/
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it do
is_expected.to contain_service('puppet')
.with_ensure('stopped')
.with_name('puppet')
.with_hasstatus('true')
.with_enable('false')
end
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) }
it do
is_expected.to contain_cron('puppet')
.with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize")
.with_user('root')
.with_minute('1')
.with_hour('22')
end
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.not_to contain_service('puppet-run.timer') }
it do
is_expected.to contain_cron('puppet')
.with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize")
.with_user('root')
.with_minute('1')
.with_hour('22')
end
end
end
describe 'when runmode => systemd.timer' do
let :params do
super().merge(runmode: 'systemd.timer')
end
case os
when /\A(debian|redhat|centos|scientific|fedora|ubuntu|sles|archlinux)-/
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(true) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(true) }
it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.timer')
.with_content(/.*OnCalendar\=\*-\*-\* \*\:10,40:00.*/)
end
it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.timer')
.with_content(/^RandomizedDelaySec\=0$/)
end
it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.service')
.with_content(%r{^ExecStart=#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure$})
end
it do
is_expected.to contain_service('puppet-run.timer')
.with_provider('systemd')
.with_ensure(true)
.with_name('puppet-run.timer')
.with_enable(true)
end
else
it { is_expected.to raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) }
end
end
describe 'when runmode => systemd.timer with configured time' do
let :params do
super().merge(runmode: 'systemd.timer',
run_hour: 22,
run_minute: 01
)
end
case os
when /\A(debian|redhat|centos|scientific|fedora|ubuntu|sles|archlinux)-/
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(true) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(true) }
it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.timer')
.with_content(/.*OnCalendar\=\*-\*-\* 22:1:00.*/)
end
it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.timer')
.with_content(/^RandomizedDelaySec\=0$/)
end
it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.service')
.with_content(%r{^ExecStart=#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure$})
end
it do
is_expected.to contain_service('puppet-run.timer')
.with_provider('systemd')
.with_ensure(true)
.with_name('puppet-run.timer')
.with_enable(true)
end
else
it { is_expected.to raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) }
end
end
describe 'when runmode => none' do
let :params do
super().merge(runmode: 'none')
end
# For windows we specify a package provider which doesn't compile
if facts[:osfamily] != 'windows'
it { is_expected.to compile.with_all_deps }
end
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
case os
when /\A(debian|redhat|centos|scientific|fedora|ubuntu|sles|archlinux)-/
it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) }
else
it { is_expected.not_to contain_service('puppet-run.timer') }
end
end
describe 'when runmode => unmanaged' do
let :params do
super().merge(runmode: 'unmanaged')
end
# For windows we specify a package provider which doesn't compile
if facts[:osfamily] != 'windows'
it { is_expected.to compile.with_all_deps }
end
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.not_to contain_cron('puppet') }
it { is_expected.not_to contain_service('puppet') }
it { is_expected.not_to contain_service('puppet-run.timer') }
end
end
describe 'when unavailable_runmodes => ["cron"]' do
let :params do
super().merge(unavailable_runmodes: ['cron'])
end
it { is_expected.not_to contain_cron('puppet') }
end
describe 'with custom service_name' do
let :params do
super().merge(service_name: 'pe-puppet')
end
it { is_expected.to contain_service('puppet').with_name('pe-puppet') }
end
context 'with report => false' do
let :params do
super().merge(report: false)
end
it { is_expected.to contain_puppet__config__agent('report').with_value('false') }
end
end
end
end
|