-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathpuppet_agent_service_systemd_spec.rb
92 lines (79 loc) · 3.29 KB
/
puppet_agent_service_systemd_spec.rb
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
require 'spec_helper'
describe 'puppet::agent::service::systemd' do
on_os_under_test.each do |os, facts|
context "on #{os}" do
if facts[:osfamily] == 'FreeBSD'
bindir = '/usr/local/bin'
confdir = '/usr/local/etc/puppet'
elsif facts[:osfamily] == 'Archlinux'
bindir = '/usr/bin'
confdir = '/etc/puppetlabs/puppet'
else
bindir = '/opt/puppetlabs/bin'
confdir = '/etc/puppetlabs/puppet'
end
let :facts do
facts.merge(ipaddress: '192.0.2.100')
end
describe 'when runmode is not systemd' do
let :pre_condition do
"class {'puppet': agent => true}"
end
case os
when /\Adebian-(8|9)/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-16/, /\Aarchlinux-/
it 'should disable systemd timer' do
should contain_class('puppet::agent::service::systemd').with({
'enabled' => false,
})
should contain_service('puppet-run.timer').with({
:provider => 'systemd',
:ensure => 'stopped',
:name => 'puppet-run.timer',
:enable => 'false',
})
should contain_file('/etc/systemd/system/puppet-run.timer').with_ensure(:absent)
should contain_file('/etc/systemd/system/puppet-run.service').with_ensure(:absent)
should contain_exec('systemctl-daemon-reload-puppet').with({
:refreshonly => true,
:command => 'systemctl daemon-reload',
})
end
else
it 'should not have a systemd timer service' do
should_not contain_service('puppet-run.timer')
should_not contain_file('/etc/systemd/system/puppet-run.timer')
should_not contain_file('/etc/systemd/system/puppet-run.service')
should_not contain_exec('systemctl-daemon-reload-puppet')
end
end
end
describe 'when runmode => systemd.timer' do
let :pre_condition do
"class {'puppet': agent => true, runmode => 'systemd.timer'}"
end
case os
when /\Adebian-(8|9)/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-16/, /\Aarchlinux-/
it 'should enable systemd timer' do
should contain_class('puppet::agent::service::systemd').with_enabled(true)
should contain_file('/etc/systemd/system/puppet-run.timer').
with_content(/.*OnCalendar\=\*-\*-\* \*\:10,40:00.*/)
should contain_file('/etc/systemd/system/puppet-run.service').
with_content(/.*ExecStart=#{bindir}\/puppet agent --config #{confdir}\/puppet.conf --onetime --no-daemonize.*/)
should contain_exec('systemctl-daemon-reload-puppet').with({
:refreshonly => true,
:command => 'systemctl daemon-reload',
})
should contain_service('puppet-run.timer').with({
:provider => 'systemd',
:ensure => 'running',
:name => 'puppet-run.timer',
:enable => 'true',
})
end
else
it { should raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) }
end
end
end
end
end