-
-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathattributes_spec.rb
More file actions
292 lines (227 loc) · 8.18 KB
/
attributes_spec.rb
File metadata and controls
292 lines (227 loc) · 8.18 KB
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
#
# Cookbook:: ntp
# Test:: attributes_spec
#
# Author:: Fletcher Nichol
# Author:: Eric G. Wolfe
#
# Copyright:: 2012-2017, Fletcher Nichol
# Copyright:: 2012-2017, Eric G. Wolfe
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'spec_helper'
describe 'ntp attributes' do
cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'aix').converge('ntp::default') }
let(:ntp) { chef_run.node['ntp'] }
describe 'on an unknown platform' do
it 'sets the package list to ntp' do
expect(ntp['packages']).to include('ntp')
expect(ntp['packages']).to_not include('ntpdate')
end
it 'sets the service name to ntpd' do
expect(ntp['service']).to eq('ntpd')
end
it 'sets the /var/lib directory' do
expect(ntp['varlibdir']).to eq('/var/lib/ntp')
end
it 'sets the driftfile to /var/lib/ntp.drift' do
expect(ntp['driftfile']).to eq('/var/lib/ntp/ntp.drift')
end
it 'sets the logfile to nil' do
expect(ntp['logfile']).to be nil
end
it 'sets the logconfig to all' do
expect(ntp['logconfig']).to eq('all')
end
it 'sets the conf file to /etc/ntp.conf' do
expect(ntp['conffile']).to eq('/etc/ntp.conf')
end
it 'sets the stats directory to /var/log/ntpstats/' do
expect(ntp['statsdir']).to eq('/var/log/ntpstats/')
end
it 'sets restrict default to kod notrap nomodify nopeer noquery' do
expect(ntp['restrict_default']).to eq('limited kod notrap nomodify nopeer noquery')
end
it 'sets the conf_owner to root' do
expect(ntp['conf_owner']).to eq('root')
end
it 'sets the conf_group to root' do
expect(ntp['conf_group']).to eq('root')
end
it 'sets the var_owner to ntp' do
expect(ntp['var_owner']).to eq('ntp')
end
it 'sets the var_group to ntp' do
expect(ntp['var_group']).to eq('ntp')
end
it 'sets the leapfile to /etc/ntp.leapseconds' do
expect(ntp['leapfile']).to eq('/etc/ntp.leapseconds')
end
it 'sets the upstream server list in the recipe' do
expect(ntp['servers']).to include('0.pool.ntp.org')
end
it 'sets apparmor_enabled to false' do
expect(ntp['apparmor_enabled']).to eq(false)
end
it 'sets monitor to false' do
expect(ntp['monitor']).to eq(false)
end
it 'sets the keys to nil' do
expect(ntp['keys']).to be nil
end
it 'sets the trustedkey to nil' do
expect(ntp['trustedkey']).to be nil
end
it 'sets the dscp to nil' do
expect(ntp['dscp']).to be nil
end
it 'sets conf_restart_immediate to false' do
expect(ntp['conf_restart_immediate']).to eq(false)
end
it 'sets peer key to nil' do
expect(ntp['peer']['key']).to be nil
end
it 'sets peer use_iburst to true' do
expect(ntp['peer']['use_iburst']).to eq(true)
end
it 'sets peer use_burst to false' do
expect(ntp['peer']['use_burst']).to eq(false)
end
it 'sets peer minpoll to 6' do
expect(ntp['peer']['minpoll']).to eq(6)
end
it 'sets peer maxpoll to 10' do
expect(ntp['peer']['maxpoll']).to eq(10)
end
it 'sets server prefer to empty string' do
expect(ntp['server']['prefer']).to eq('')
end
it 'sets server use_iburst to true' do
expect(ntp['server']['use_iburst']).to eq(true)
end
it 'sets server use_burst to false' do
expect(ntp['server']['use_burst']).to eq(false)
end
it 'sets server minpoll to 6' do
expect(ntp['server']['minpoll']).to eq(6)
end
it 'sets server maxpoll to 10' do
expect(ntp['server']['maxpoll']).to eq(10)
end
context 'tinker options' do
it 'sets allan to 1500' do
expect(ntp['tinker']['allan']).to eq(1500)
end
it 'sets dispersion to 15' do
expect(ntp['tinker']['dispersion']).to eq(15)
end
it 'sets panic to 1000' do
expect(ntp['tinker']['panic']).to eq(1000)
end
it 'sets step to 0.128' do
expect(ntp['tinker']['step']).to eq(0.128)
end
it 'sets stepout to 900' do
expect(ntp['tinker']['stepout']).to eq(900)
end
end
end
describe 'on Debian-family platforms' do
cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'debian', version: '12').converge('ntp::default') }
it 'sets the package list to ntp & ntpdate' do
expect(ntp['packages']).to include('ntp')
expect(ntp['packages']).to_not include('ntpdate')
end
it 'sets the var_owner to ntpsec' do
expect(ntp['var_owner']).to eq('ntpsec')
end
it 'sets the var_group to ntpsec' do
expect(ntp['var_group']).to eq('ntpsec')
end
end
describe 'on Ubuntu' do
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '20.04').converge('ntp::default') }
it 'sets the apparmor_enabled attribute to true when /etc/init.d/apparmor exists' do
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/etc/init.d/apparmor').and_return(true)
expect(ntp['apparmor_enabled']).to eq(true)
end
it 'sets the apparmor_enabled attribute to false when /etc/init.d/apparmor does not exist' do
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/etc/init.d/apparmor').and_return(false)
expect(ntp['apparmor_enabled']).to eq(false)
end
end
describe 'on Ubuntu >= 23.10' do
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04').converge('ntp::default') }
it 'sets the var_owner to ntpsec' do
expect(ntp['var_owner']).to eq('ntpsec')
end
it 'sets the var_group to ntpsec' do
expect(ntp['var_group']).to eq('ntpsec')
end
end
describe 'on the CentOS 7 platform' do
cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'centos', version: '7').converge('ntp::default') }
it 'sets the package list to include ntp and ntpdate' do
expect(ntp['packages']).to include('ntp')
expect(ntp['packages']).to include('ntpdate')
end
end
describe 'on the Windows platform' do
cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge('ntp::default') }
it 'sets the service name to NTP' do
expect(ntp['service']).to eq('NTP')
end
it 'sets the drift file to /var/db/ntpd.drift' do
expect(ntp['driftfile']).to eq('C:\\NTP\\ntp.drift')
end
it 'sets the conf file to /etc/ntp.conf' do
expect(ntp['conffile']).to eq('C:\\NTP\\etc\\ntp.conf')
end
it 'sets the conf_owner to root' do
expect(ntp['conf_owner']).to eq('Administrators')
end
it 'sets the conf_group to root' do
expect(ntp['conf_group']).to eq('Administrators')
end
it 'sets the package_url correctly' do
expect(ntp['package_url']).to eq('https://www.meinbergglobal.com/download/ntp/windows/ntp-4.2.8p13-win32-setup.exe')
end
end
describe 'on the FreeBSD platform' do
cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'freebsd').converge('ntp::default') }
it 'sets the package list to include only ntp' do
expect(ntp['packages']).to include('ntp')
end
it 'sets the var directories to /var/db' do
expect(ntp['varlibdir']).to eq('/var/db')
end
it 'sets the drift file to /var/db/ntpd.drift' do
expect(ntp['driftfile']).to eq('/var/db/ntpd.drift')
end
it 'sets the stats directory to /var/db/ntpstats' do
expect(ntp['statsdir']).to eq('/var/db/ntpstats')
end
it 'sets the conf_group to wheel' do
expect(ntp['conf_group']).to eq('wheel')
end
it 'sets the var_owner to root' do
expect(ntp['var_owner']).to eq('root')
end
it 'sets the var_group to wheel' do
expect(ntp['var_group']).to eq('wheel')
end
end
end