forked from olevole/puppetlabs-ntp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathntp_service_spec.rb
97 lines (91 loc) · 2.77 KB
/
ntp_service_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
93
94
95
96
require 'spec_helper_acceptance'
require 'specinfra'
case fact('osfamily')
when 'RedHat', 'FreeBSD', 'Linux', 'Gentoo'
servicename = 'ntpd'
when 'Solaris'
servicename = 'network/ntp'
when 'AIX'
servicename = 'xntpd'
else
if fact('operatingsystem') == 'SLES' and fact('operatingsystemmajrelease') == '12'
servicename = 'ntpd'
else
servicename = 'ntp'
end
end
shared_examples 'running' do
describe service(servicename) do
if !(fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12')
it { should be_running }
if (fact('operatingsystem') == 'Debian' && fact('operatingsystemmajrelease') == '8')
pending 'Should be enabled - Bug 760616 on Debian 8'
else
it { should be_enabled }
end
else
# hack until we either update SpecInfra or come up with alternative
it {
output = shell('service ntpd status')
expect(output.stdout).to match(/Active\:\s+active\s+\(running\)/)
expect(output.stdout).to match(/^\s+Loaded.*enabled\)$/)
}
end
end
end
describe 'ntp::service class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
describe 'basic test' do
it 'sets up the service' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end
it_should_behave_like 'running'
end
describe 'service parameters' do
it 'starts the service' do
pp = <<-EOS
class { 'ntp':
service_enable => true,
service_ensure => running,
service_manage => true,
service_name => '#{servicename}'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it_should_behave_like 'running'
end
end
describe 'service is unmanaged' do
it 'shouldnt stop the service' do
pp = <<-EOS
class { 'ntp':
service_enable => false,
service_ensure => stopped,
service_manage => false,
service_name => '#{servicename}'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe service(servicename) do
if !(fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12')
it { should be_running }
if (fact('operatingsystem') == 'Debian' && fact('operatingsystemmajrelease') == '8')
pending 'Should be enabled - Bug 760616 on Debian 8'
else
it { should be_enabled }
end
else
# hack until we either update SpecInfra or come up with alternative
output = shell('service ntpd status', :acceptable_exit_codes => [0, 3])
it 'should be disabled' do
expect(output.stdout).to match(/^\s+Loaded.*disabled\)$/)
end
it 'should be stopped' do
expect(output.stdout).to match(/Active\:\s+inactive/)
end
end
end
end