This repository was archived by the owner on Dec 20, 2019. It is now read-only.
forked from puppetlabs/puppetlabs-ntp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathntp_spec.rb
856 lines (748 loc) · 25.4 KB
/
ntp_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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
require 'spec_helper'
describe 'ntp' do
let(:facts) {{ :is_virtual => 'false' }}
on_supported_os.select { |_, f| f[:os]['family'] != 'Solaris' }.each do |os, f|
context "on #{os}" do
let(:facts) do
f.merge(super())
end
it { is_expected.to compile.with_all_deps }
it { should contain_class('ntp::install') }
it { should contain_class('ntp::config') }
it { should contain_class('ntp::service') }
describe "ntp::config" do
it { should contain_file('/etc/ntp.conf').with_owner('0') }
it { should contain_file('/etc/ntp.conf').with_group('0') }
it { should contain_file('/etc/ntp.conf').with_mode('0644') }
if f[:os]['family'] == 'RedHat'
it { should contain_file('/etc/ntp/step-tickers').with_owner('0') }
it { should contain_file('/etc/ntp/step-tickers').with_group('0') }
it { should contain_file('/etc/ntp/step-tickers').with_mode('0644') }
end
if f[:os]['family'] == 'Suse' && f[:os]['release']['major'] == '12'
it { should contain_file('/var/run/ntp/servers-netconfig').with_ensure_absent }
end
describe 'allows template to be overridden with erb template' do
let(:params) {{ :config_template => 'my_ntp/ntp.conf.erb' }}
it { should contain_file('/etc/ntp.conf').with_content(/erbserver1/) }
end
describe 'allows template to be overridden with epp template' do
let(:params) {{ :config_epp => 'my_ntp/ntp.conf.epp' }}
it { should contain_file('/etc/ntp.conf').with_content(/eppserver1/) }
end
describe 'keys' do
context "when enabled" do
let(:params) {{
:keys_enable => true,
:keys_trusted => [1, 2, 3],
:keys_controlkey => 2,
:keys_requestkey => 3,
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
it { should contain_file('/etc/ntp.conf').with({
'content' => /controlkey 2/})
}
it { should contain_file('/etc/ntp.conf').with({
'content' => /requestkey 3/})
}
end
end
context "when disabled" do
let(:params) {{
:keys_enable => false,
:keys_trusted => [1, 2, 3],
:keys_controlkey => 2,
:keys_requestkey => 3,
}}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /controlkey 2/})
}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /requestkey 3/})
}
end
describe 'preferred servers' do
context "when set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:preferred_servers => ['a', 'b'],
:iburst_enable => false,
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /server a prefer( maxpoll 9)?\nserver b prefer( maxpoll 9)?\nserver c( maxpoll 9)?\nserver d( maxpoll 9)?/})
}
end
context "when not set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:preferred_servers => []
}}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /server a prefer/})
}
end
end
describe 'noselect servers' do
context "when set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:noselect_servers => ['a', 'b'],
:iburst_enable => false,
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /server a (maxpoll 9 )?noselect\nserver b (maxpoll 9 )?noselect\nserver c( maxpoll 9)?\nserver d( maxpoll 9)?/})
}
end
context "when not set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:noselect_servers => []
}}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /server a noselect/})
}
end
end
describe 'specified interfaces' do
context "when set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:interfaces => ['127.0.0.1', 'a.b.c.d']
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /interface ignore wildcard\ninterface listen 127.0.0.1\ninterface listen a.b.c.d/})
}
end
context "when not set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
}}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /interface ignore wildcard/})
}
end
end
describe 'specified ignore interfaces' do
context "when set" do
let(:params) {{
:interfaces => ['a.b.c.d'],
:interfaces_ignore => ['wildcard', 'ipv6']
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /interface ignore wildcard\ninterface ignore ipv6\ninterface listen a.b.c.d/})
}
end
context "when not set" do
let(:params) {{
:interfaces => ['127.0.0.1'],
:servers => ['a', 'b', 'c', 'd'],
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /interface ignore wildcard\ninterface listen 127.0.0.1/})
}
end
end
describe 'with parameter disable_auth' do
context 'when set to true' do
let(:params) {{
:disable_auth => true,
}}
it 'should contain disable auth setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^disable auth\n/,
})
end
end
context 'when set to false' do
let(:params) {{
:disable_auth => false,
}}
it 'should not contain disable auth setting' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^disable auth\n/,
})
end
end
end
describe 'with parameter disable_dhclient' do
context 'when set to true' do
let(:params) {{
:disable_dhclient => true,
}}
it 'should contain disable ntp-servers setting' do
should contain_augeas('disable ntp-servers in dhclient.conf')
end
it 'should contain dhcp file' do
should contain_file('/var/lib/ntp/ntp.conf.dhcp').with_ensure('absent')
end
end
context 'when set to false' do
let(:params) {{
:disable_dhclient => false,
}}
it 'should not contain disable ntp-servers setting' do
should_not contain_augeas('disable ntp-servers in dhclient.conf')
end
it 'should not contain dhcp file' do
should_not contain_file('/var/lib/ntp/ntp.conf.dhcp').with_ensure('absent')
end
end
end
describe 'with parameter disable_kernel' do
context 'when set to true' do
let(:params) {{
:disable_kernel => true,
}}
it 'should contain disable kernel setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^disable kernel\n/,
})
end
end
context 'when set to false' do
let(:params) {{
:disable_kernel => false,
}}
it 'should not contain disable kernel setting' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^disable kernel\n/,
})
end
end
end
describe 'with parameter disable_monitor' do
context 'default' do
let(:params) {{
}}
it 'should contain disable monitor setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^disable monitor\n/,
})
end
end
context 'when set to true' do
let(:params) {{
:disable_monitor => true,
}}
it 'should contain disable monitor setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^disable monitor\n/,
})
end
end
context 'when set to false' do
let(:params) {{
:disable_monitor => false,
}}
it 'should not contain disable monitor setting' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^disable monitor\n/,
})
end
end
end
describe 'with parameter broadcastclient' do
context 'when set to true' do
let(:params) {{
:broadcastclient => true,
}}
it 'should contain broadcastclient setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^broadcastclient\n/,
})
end
end
context 'when set to false' do
let(:params) {{
:broadcastclient => false,
}}
it 'should not contain broadcastclient setting' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^broadcastclient\n/,
})
end
end
context 'when setting custom config_dir' do
let(:params) {{
:keys_enable => true,
:config_dir => '/tmp/foo',
:keys_file => '/tmp/foo/ntp.keys',
}}
it 'should contain custom config directory' do
should contain_file('/tmp/foo').with(
'ensure' => 'directory',
'owner' => '0',
'group' => '0',
'mode' => '0775',
'recurse' => 'false'
)
end
end
context 'when manually setting conf file mode to 0777' do
let(:params) {{
:config_file_mode => '0777',
}}
it 'should contain file mode of 0777' do
should contain_file('/etc/ntp.conf').with_mode('0777')
end
end
end
context 'when choosing the default pool servers' do
case f[:os]['family']
when 'RedHat'
if f[:os]['name'] == 'Fedora'
it 'uses the fedora ntp servers' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.fedora.pool.ntp.org/,
})
end
it do
should contain_file('/etc/ntp/step-tickers').with({
'content' => /\d.fedora.pool.ntp.org/,
})
end
else
it 'uses the centos ntp servers' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.centos.pool.ntp.org/,
})
end
it do
should contain_file('/etc/ntp/step-tickers').with({
'content' => /\d.centos.pool.ntp.org/,
})
end
end
when 'Debian'
it 'uses the debian ntp servers' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.debian.pool.ntp.org iburst\n/,
})
end
when 'Suse'
it 'uses the opensuse ntp servers' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.opensuse.pool.ntp.org/,
})
end
when 'FreeBSD'
it 'uses the freebsd ntp servers' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.freebsd.pool.ntp.org iburst maxpoll 9/,
})
end
when 'Archlinux'
it 'uses the Archlinux NTP servers' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.arch.pool.ntp.org/,
})
end
when 'Solaris', 'Gentoo'
it 'uses the generic NTP pool servers' do
should contain_file('/etc/inet/ntp.conf').with({
'content' => /server \d.pool.ntp.org/,
})
end
else
it { expect{ catalogue }.to raise_error(
/The ntp module is not supported on an unsupported based system./
)}
end
end
end
describe 'ntp::install' do
let(:params) {{ :package_ensure => 'present', :package_name => ['ntp'], :package_manage => true, }}
it { should contain_package('ntp').with(
:ensure => 'present'
)}
describe 'should allow package ensure to be overridden' do
let(:params) {{ :package_ensure => 'latest', :package_name => ['ntp'], :package_manage => true, }}
it { should contain_package('ntp').with_ensure('latest') }
end
describe 'should allow the package name to be overridden' do
let(:params) {{ :package_ensure => 'present', :package_name => ['hambaby'], :package_manage => true, }}
it { should contain_package('hambaby') }
end
describe 'should allow the package to be unmanaged' do
let(:params) {{ :package_manage => false, :package_name => ['ntp'], }}
it { should_not contain_package('ntp') }
end
end
describe 'ntp::service' do
let(:params) {{
:service_manage => true,
:service_enable => true,
:service_ensure => 'running',
:service_name => 'ntp'
}}
describe 'with defaults' do
it { should contain_service('ntp').with(
:enable => true,
:ensure => 'running',
:name => 'ntp'
)}
end
describe 'service_ensure' do
describe 'when overridden' do
let(:params) {{ :service_name => 'ntp', :service_ensure => 'stopped' }}
it { should contain_service('ntp').with_ensure('stopped') }
end
end
describe 'service_manage' do
let(:params) {{
:service_manage => false,
:service_enable => true,
:service_ensure => 'running',
:service_name => 'ntpd',
}}
it 'when set to false' do
should_not contain_service('ntp').with({
'enable' => true,
'ensure' => 'running',
'name' => 'ntpd'
})
end
end
end
describe 'with parameter iburst_enable' do
context 'when set to true' do
let(:params) {{
:iburst_enable => true,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /iburst/,
})
end
end
context 'when set to false' do
let(:params) {{
:iburst_enable => false,
}}
it do
should_not contain_file('/etc/ntp.conf').with({
'content' => /iburst\n/,
})
end
end
end
describe 'with tinker parameter changed' do
describe 'when set to false' do
context 'when panic or stepout not overriden' do
let(:params) {{
:tinker => false,
}}
it do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^tinker /,
})
end
end
context 'when panic overriden' do
let(:params) {{
:tinker => false,
:panic => 257,
}}
it do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^tinker /,
})
end
end
context 'when stepout overriden' do
let(:params) {{
:tinker => false,
:stepout => 5,
}}
it do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^tinker /,
})
end
end
context 'when panic and stepout overriden' do
let(:params) {{
:tinker => false,
:panic => 257,
:stepout => 5,
}}
it do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^tinker /,
})
end
end
end
describe 'when set to true' do
context 'when only tinker set to true' do
let(:params) {{
:tinker => true,
}}
it do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^tinker /,
})
end
end
context 'when panic changed' do
let(:params) {{
:tinker => true,
:panic => 257,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /^tinker panic 257\n/,
})
end
end
context 'when stepout changed' do
let(:params) {{
:tinker => true,
:stepout => 5,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /^tinker stepout 5\n/,
})
end
end
context 'when panic and stepout changed' do
let(:params) {{
:tinker => true,
:panic => 257,
:stepout => 5,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /^tinker panic 257 stepout 5\n/,
})
end
end
end
end
describe 'with parameters minpoll or maxpoll changed from default' do
context 'when minpoll changed from default' do
let(:params) {{
:minpoll => 6,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /minpoll 6/,
})
end
end
context 'when maxpoll changed from default' do
let(:params) {{
:maxpoll => 12,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /maxpoll 12\n/,
})
end
end
context 'when minpoll and maxpoll changed from default simultaneously' do
let(:params) {{
:minpoll => 6,
:maxpoll => 12,
}}
it do
should contain_file('/etc/ntp.conf').with({
'content' => /minpoll 6 maxpoll 12\n/,
})
end
end
end
describe 'with parameter leapfile' do
context 'when set to true' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:leapfile => '/etc/leap-seconds.3629404800',
}}
it 'should contain leapfile setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^leapfile \/etc\/leap-seconds\.3629404800\n/,
})
end
end
context 'when set to false' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
}}
it 'should not contain a leapfile line' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /leapfile /,
})
end
end
end
describe 'with parameter logfile' do
context 'when set to true' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:logfile => '/var/log/foobar.log',
}}
it 'should contain logfile setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^logfile \/var\/log\/foobar\.log\n/,
})
end
end
context 'when set to false' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
}}
it 'should not contain a logfile line' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /logfile /,
})
end
end
end
describe 'with parameter ntpsigndsocket' do
context 'when set to true' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:ntpsigndsocket => '/usr/local/samba/var/lib/ntp_signd',
}}
it 'should contain ntpsigndsocket setting' do
should contain_file('/etc/ntp.conf').with({
'content' => %r(^ntpsigndsocket /usr/local/samba/var/lib/ntp_signd\n),
})
end
end
context 'when set to false' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
}}
it 'should not contain a ntpsigndsocket line' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /ntpsigndsocket /,
})
end
end
end
describe 'with parameter authprov' do
context 'when set to true' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:authprov => '/opt/novell/xad/lib64/libw32time.so 131072:4294967295 global',
}}
it 'should contain authprov setting' do
should contain_file('/etc/ntp.conf').with({
'content' => %r(^authprov /opt/novell/xad/lib64/libw32time.so 131072:4294967295 global\n),
})
end
end
context 'when set to false' do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
}}
it 'should not contain a authprov line' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /authprov /,
})
end
end
end
describe 'with parameter tos' do
context 'when set to true' do
let(:params) {{
:tos => true,
}}
it 'should contain tos setting' do
should contain_file('/etc/ntp.conf').with({
'content' => /^tos/,
})
end
end
context 'when set to false' do
let(:params) {{
:tos => false,
}}
it 'should not contain tos setting' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /^tos/,
})
end
end
end
describe 'pool' do
context 'when empty' do
let(:params) do
{
:pool => []
}
end
it 'should not contain a pool line' do
should contain_file('/etc/ntp.conf').without_content(/^pool/)
end
end
context 'set' do
let(:params) do
{
:pool => ['foo', 'bar'],
}
end
it 'should contain the pool lines' do
should contain_file('/etc/ntp.conf').with_content(/pool foo/)
should contain_file('/etc/ntp.conf').with_content(/pool bar/)
end
end
end
describe 'peers' do
context 'when empty' do
let(:params) do
{
:peers => []
}
end
it 'should not contain a peer line' do
should contain_file('/etc/ntp.conf').without_content(/^peer/)
end
end
context 'set' do
let(:params) do
{
:peers => ['foo', 'bar'],
}
end
it 'should contain the peer lines' do
should contain_file('/etc/ntp.conf').with_content(/peer foo/)
should contain_file('/etc/ntp.conf').with_content(/peer bar/)
end
end
end
describe 'for virtual machines' do
let :facts do
super().merge({ :is_virtual => 'true', })
end
it 'should not use local clock as a time source' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /server.*127.127.1.0.*fudge.*127.127.1.0 stratum 10/,
})
end
it 'allows large clock skews' do
should contain_file('/etc/ntp.conf').with({
'content' => /tinker panic 0/,
})
end
end
describe 'for physical machines' do
let :facts do
super().merge({ :is_virtual => 'false', })
end
it 'disallows large clock skews' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /tinker panic 0/,
})
end
end
end
end
end