forked from voxpupuli/puppet-yum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_spec.rb
808 lines (729 loc) · 25.9 KB
/
init_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
# frozen_string_literal: true
require 'spec_helper'
require 'deep_merge'
shared_examples 'a Yum class' do |value|
value ||= 3
it { is_expected.to contain_yum__config('installonly_limit').with_ensure(value.to_s) }
it 'contains Exec[package-cleanup_oldkernels' do
is_expected.to contain_exec('package-cleanup_oldkernels').with(
command: "/usr/bin/package-cleanup --oldkernels --count=#{value} -y",
refreshonly: true
).that_subscribes_to('Yum::Config[installonly_limit]')
end
end
shared_examples 'a catalog containing repos' do |repos|
repos.each do |repo|
it { is_expected.to contain_yumrepo(repo) }
end
end
shared_examples 'a catalog not containing repos' do |repos|
repos.each do |repo|
it { is_expected.not_to contain_yumrepo(repo) }
end
end
describe 'yum' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('yum') }
context 'without any parameters' do
let(:params) { {} }
it_behaves_like 'a Yum class'
it { is_expected.to have_yumrepo_resource_count(0) }
end
context 'when `manage_os_default_repos` is enabled' do
let(:params) { { 'manage_os_default_repos' => true } }
case facts[:os]['name']
when 'Rocky'
it_behaves_like 'a catalog containing repos', %w[
appstream
appstream-source
baseos
baseos-source
devel
extras
ha
ha-source
nfv
plus
powertools
powertools-source
resilient-storage
resilient-storage-source
rt
]
case facts[:os]['release']['major']
when '8'
it { is_expected.to have_yumrepo_resource_count(15) }
else
it { is_expected.to have_yumrepo_resource_count(0) } # rubocop:disable RSpec/RepeatedExample
end
when 'CentOS'
case facts[:os]['release']['major']
when '9'
it_behaves_like 'a catalog containing repos', %w[
appstream
baseos
crb
extras-common
appstream-source
appstream-debug
baseos-source
baseos-debug
crb-source
crb-debug
highavailability
highavailability-source
highavailability-debug
nfv
nfv-source
nfv-debug
rt
rt-source
rt-debug
resilientstorage
resilientstorage-source
resilientstorage-debug
extras-common
extras-common-source
]
it_behaves_like 'a catalog not containing repos', %w[
AppStream
BaseOS
cr
Devel
HA
PowerTools
BaseOS-source
Appstream-source
c8-media-BaseOS
c8-media-AppStream
]
when '8'
it_behaves_like 'a catalog containing repos', %w[
AppStream
BaseOS
cr
Devel
HA
PowerTools
BaseOS-source
Appstream-source
c8-media-BaseOS
c8-media-AppStream
extras
centosplus
fasttrack
extras-source
base-debuginfo
]
it_behaves_like 'a catalog not containing repos', %w[
base
updates
contrib
base-source
updates-source
centos-media
]
when '7'
it_behaves_like 'a catalog containing repos', %w[
base
updates
cr
base-source
updates-source
centos-media
extras
centosplus
fasttrack
extras-source
base-debuginfo
]
it_behaves_like 'a catalog not containing repos', %w[
contrib
AppStream
BaseOS
Devel
HA
PowerTools
BaseOS-source
Appstream-source
c8-media-BaseOS
c8-media-AppStream
]
else
it { is_expected.to have_yumrepo_resource_count(4) }
end
when 'Amazon'
it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample
it_behaves_like 'a catalog containing repos', %w[
amzn-main
amzn-main-debuginfo
amzn-main-source
amzn-nosrc
amzn-preview
amzn-preview-debuginfo
amzn-preview-source
amzn-updates
amzn-updates-debuginfo
amzn-updates-source
epel
epel-debuginfo
epel-source
epel-testing
epel-testing-debuginfo
epel-testing-source
]
when 'RedHat'
it { is_expected.to have_yumrepo_resource_count(18) }
it_behaves_like 'a catalog containing repos', %w[
rhui-REGION-rhel-server-releases
rhui-REGION-rhel-server-releases-debug
rhui-REGION-rhel-server-releases-source
rhui-REGION-rhel-server-rhscl
rhui-REGION-rhel-server-debug-rhscl
rhui-REGION-rhel-server-source-rhscl
rhui-REGION-rhel-server-extras
rhui-REGION-rhel-server-debug-extras
rhui-REGION-rhel-server-source-extras
rhui-REGION-rhel-server-optional
rhui-REGION-rhel-server-debug-optional
rhui-REGION-rhel-server-source-optional
rhui-REGION-rhel-server-rh-common
rhui-REGION-rhel-server-debug-rh-common
rhui-REGION-rhel-server-source-rh-common
rhui-REGION-rhel-server-supplementary
rhui-REGION-rhel-server-debug-supplementary
rhui-REGION-rhel-server-source-supplementary
]
when 'VirtuozzoLinux'
case facts[:os]['release']['major']
when '6'
it { is_expected.to have_yumrepo_resource_count(12) }
it_behaves_like 'a catalog containing repos', %w[
virtuozzolinux-base
virtuozzolinux-updates
virtuozzolinux-base-debuginfo
virtuozzolinux-updates-debuginfo
virtuozzolinux-factory
virtuozzolinux-factory-debuginfo
virtuozzo-os
virtuozzo-updates
virtuozzo-os-debuginfo
virtuozzo-updates-debuginfo
virtuozzo-readykernel
obsoleted_tmpls
]
when '7'
it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample
it_behaves_like 'a catalog containing repos', %w[
virtuozzolinux-base
virtuozzolinux-updates
virtuozzolinux-base-debuginfo
virtuozzolinux-updates-debuginfo
virtuozzolinux-factory
virtuozzolinux-factory-debuginfo
virtuozzo-os
virtuozzo-updates
virtuozzo-os-debuginfo
virtuozzo-updates-debuginfo
virtuozzo-readykernel
obsoleted_tmpls
factory
factory-debuginfo
virtuozzolinux-vz-factory
virtuozzolinux-vz-factory-debuginfo
]
end
when 'AlmaLinux'
case facts[:os]['release']['major']
when '8'
it { is_expected.to have_yumrepo_resource_count(21) }
it_behaves_like 'a catalog containing repos', %w[
baseos
appstream
powertools
extras
ha
plus
resilientstorage
baseos-source
appstream-source
powertools-source
extras-source
ha-source
plus-source
resilientstorage-source
baseos-debuginfo
appstream-debuginfo
powertools-debuginfo
extras-debuginfo
ha-debuginfo
plus-debuginfo
resilientstorage-debuginfo
]
end
when 'Fedora'
it { is_expected.to have_yumrepo_resource_count(11) }
it_behaves_like 'a catalog containing repos', %w[
fedora
fedora-debuginfo
fedora-source
fedora-cisco-openh264
fedora-cisco-openh264-debuginfo
updates
updates-debuginfo
updates-source
updates-testing
updates-testing-debuginfo
updates-testing-source
]
else
it { is_expected.to have_yumrepo_resource_count(0) } # rubocop:disable RSpec/RepeatedExample
end
context 'and the CentOS base repo is negated' do
case facts[:os]['release']['major']
when '8'
let(:params) { super().merge(repo_exclusions: ['BaseOS']) }
else
let(:params) { super().merge(repo_exclusions: ['base']) }
end
it { is_expected.to compile.with_all_deps }
case facts[:os]['name']
when 'CentOS'
it { is_expected.not_to contain_yumrepo('base') }
it { is_expected.not_to contain_yumrepo('BaseOS') }
case facts[:os]['release']['major']
when '9'
it_behaves_like 'a catalog containing repos', %w[
appstream
baseos
crb
extras-common
appstream-source
appstream-debug
baseos-source
baseos-debug
crb-source
crb-debug
highavailability
highavailability-source
highavailability-debug
nfv
nfv-source
nfv-debug
rt
rt-source
rt-debug
resilientstorage
resilientstorage-source
resilientstorage-debug
extras-common
extras-common-source
]
when '8'
it_behaves_like 'a catalog containing repos', %w[
AppStream
cr
Devel
fasttrack
HA
PowerTools
BaseOS-source
Appstream-source
c8-media-BaseOS
c8-media-AppStream
extras
centosplus
extras-source
base-debuginfo
]
when '7'
it_behaves_like 'a catalog containing repos', %w[
cr
updates
extras
base-source
updates-source
extras-source
base-debuginfo
centosplus
centos-media
extras
centosplus
extras-source
base-debuginfo
]
when '6'
it_behaves_like 'a catalog containing repos', %w[
contrib
updates
extras
base-source
updates-source
extras-source
base-debuginfo
centosplus
centos-media
]
end
when 'Amazon'
it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample
it_behaves_like 'a catalog containing repos', %w[
amzn-main
amzn-main-debuginfo
amzn-main-source
amzn-nosrc
amzn-preview
amzn-preview-debuginfo
amzn-preview-source
amzn-updates
amzn-updates-debuginfo
amzn-updates-source
epel
epel-debuginfo
epel-source
epel-testing
epel-testing-debuginfo
epel-testing-source
]
when 'RedHat'
it { is_expected.to have_yumrepo_resource_count(18) }
it_behaves_like 'a catalog containing repos', %w[
rhui-REGION-rhel-server-releases
rhui-REGION-rhel-server-releases-debug
rhui-REGION-rhel-server-releases-source
rhui-REGION-rhel-server-rhscl
rhui-REGION-rhel-server-debug-rhscl
rhui-REGION-rhel-server-source-rhscl
rhui-REGION-rhel-server-extras
rhui-REGION-rhel-server-debug-extras
rhui-REGION-rhel-server-source-extras
rhui-REGION-rhel-server-optional
rhui-REGION-rhel-server-debug-optional
rhui-REGION-rhel-server-source-optional
rhui-REGION-rhel-server-rh-common
rhui-REGION-rhel-server-debug-rh-common
rhui-REGION-rhel-server-source-rh-common
rhui-REGION-rhel-server-supplementary
rhui-REGION-rhel-server-debug-supplementary
rhui-REGION-rhel-server-source-supplementary
]
when 'VirtuozzoLinux'
case facts[:os]['release']['major']
when '6'
it { is_expected.to have_yumrepo_resource_count(12) }
it_behaves_like 'a catalog containing repos', %w[
virtuozzolinux-base
virtuozzolinux-updates
virtuozzolinux-base-debuginfo
virtuozzolinux-updates-debuginfo
virtuozzolinux-factory
virtuozzolinux-factory-debuginfo
virtuozzo-os
virtuozzo-updates
virtuozzo-os-debuginfo
virtuozzo-updates-debuginfo
virtuozzo-readykernel
obsoleted_tmpls
]
when '7'
it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample
it_behaves_like 'a catalog containing repos', %w[
virtuozzolinux-base
virtuozzolinux-updates
virtuozzolinux-base-debuginfo
virtuozzolinux-updates-debuginfo
virtuozzolinux-factory
virtuozzolinux-factory-debuginfo
virtuozzo-os
virtuozzo-updates
virtuozzo-os-debuginfo
virtuozzo-updates-debuginfo
virtuozzo-readykernel
obsoleted_tmpls
factory
factory-debuginfo
virtuozzolinux-vz-factory
virtuozzolinux-vz-factory-debuginfo
]
end
when 'AlmaLinux'
case facts[:os]['release']['major']
when '8'
it { is_expected.to have_yumrepo_resource_count(21) }
it_behaves_like 'a catalog containing repos', %w[
baseos
appstream
powertools
extras
ha
plus
resilientstorage
baseos-source
appstream-source
powertools-source
extras-source
ha-source
plus-source
resilientstorage-source
baseos-debuginfo
appstream-debuginfo
powertools-debuginfo
extras-debuginfo
ha-debuginfo
plus-debuginfo
resilientstorage-debuginfo
]
when '9'
it { is_expected.to have_yumrepo_resource_count(33) }
it_behaves_like 'a catalog containing repos', %w[
appstream
appstream-debug
appstream-source
plus
plus-debug
plus-source
saphana
saphana-debug
saphana-source
crb
crb-debug
crb-source
baseos
baseos-debug
baseos-source
highavailability
highavailability-debug
highavailability-source
extras
extras-debug
extras-source
nfv
nfv-debug
nfv-source
resilientstorage
resilientstorage-debug
resilientstorage-source
rt
rt-debug
rt-source
sap
sap-debug
sap-source
]
end
when 'Rocky'
case facts[:os]['release']['major']
when '8'
it { is_expected.to have_yumrepo_resource_count(15) }
it_behaves_like 'a catalog containing repos', %w[
appstream
appstream-source
baseos
baseos-source
devel
extras
ha
ha-source
nfv
plus
powertools
powertools-source
resilient-storage
resilient-storage-source
rt
]
end
when 'Fedora'
it { is_expected.to have_yumrepo_resource_count(11) }
it_behaves_like 'a catalog containing repos', %w[
fedora
fedora-debuginfo
fedora-source
fedora-cisco-openh264
fedora-cisco-openh264-debuginfo
updates
updates-debuginfo
updates-source
updates-testing
updates-testing-debuginfo
updates-testing-source
]
else
it { is_expected.to have_yumrepo_resource_count(0) }
end
end
end
context 'when `managed_repos` is set' do
# TODO: This should be generated with something like `lookup('yum::repos').keys`,
# but the setup for `Puppet::Pops::Lookup` is to complicated to be worth it as of
# this writing (2017-04-11). For now, we just pull from `repos.yaml`.
repos_yaml_data = YAML.safe_load(File.read('./spec/fixtures/modules/yum/data/repos/repos.yaml'))
case facts[:os]['family']
when 'RedHat'
case facts[:os]['release']['major']
when '8'
rh8_repos_yaml_data = YAML.safe_load(File.read('./spec/fixtures/modules/yum/data/repos/RedHat/8.yaml'))
repos_yaml_data = repos_yaml_data.deep_merge(rh8_repos_yaml_data)
end
end
supported_repos = repos_yaml_data['yum::repos'].keys
supported_repos.each do |supported_repo|
context "to ['#{supported_repo}']" do
let(:params) { { managed_repos: [supported_repo] } }
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_yumrepo_resource_count(1) }
it { is_expected.to contain_yumrepo(supported_repo) }
end
end
context 'to an array of all supported repos' do
let(:params) { { managed_repos: supported_repos } }
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_yumrepo_resource_count(supported_repos.count) }
it_behaves_like 'a catalog containing repos', supported_repos
end
end
context 'when `config_options[installonly_limit]` is modified' do
context 'with an Integer' do
let(:params) { { config_options: { 'installonly_limit' => 10 } } }
it_behaves_like 'a Yum class', 10
end
context 'with an invalid data type' do
let(:params) { { config_options: { 'installonly_limit' => false } } }
it 'raises a useful error' do
is_expected.to compile.and_raise_error(
%r{The value or ensure for `\$yum::config_options\[installonly_limit\]` must be an Integer, but it is not\.}
)
end
end
end
context 'when a config option other than `installonly_limit` is set' do
context 'to a String' do
let(:params) { { config_options: { 'cachedir' => '/var/cache/yum' } } }
it { is_expected.to contain_yum__config('cachedir').with_ensure('/var/cache/yum') }
it_behaves_like 'a Yum class'
end
context 'to an Integer' do
let(:params) { { config_options: { 'debuglevel' => 5 } } }
it { is_expected.to contain_yum__config('debuglevel').with_ensure('5') }
it_behaves_like 'a Yum class'
end
context 'to a Boolean' do
let(:params) { { config_options: { 'gpgcheck' => true } } }
it { is_expected.to contain_yum__config('gpgcheck').with_ensure('1') }
it_behaves_like 'a Yum class'
end
context 'to a Sensitive value' do
let(:params) { { config_options: { 'proxy_password' => sensitive('secret') } } }
it { is_expected.to contain_yum__config('proxy_password').with_ensure('Sensitive [value redacted]') }
it_behaves_like 'a Yum class'
end
context 'using the nested attributes syntax' do
context 'to a String' do
let(:params) { { config_options: { 'my_cachedir' => { 'ensure' => '/var/cache/yum', 'key' => 'cachedir' } } } }
it { is_expected.to contain_yum__config('my_cachedir').with_ensure('/var/cache/yum').with_key('cachedir') }
it_behaves_like 'a Yum class'
end
context 'to an Integer' do
let(:params) { { config_options: { 'my_debuglevel' => { 'ensure' => 5, 'key' => 'debuglevel' } } } }
it { is_expected.to contain_yum__config('my_debuglevel').with_ensure('5').with_key('debuglevel') }
it_behaves_like 'a Yum class'
end
context 'to a Boolean' do
let(:params) { { config_options: { 'my_gpgcheck' => { 'ensure' => true, 'key' => 'gpgcheck' } } } }
it { is_expected.to contain_yum__config('my_gpgcheck').with_ensure('1').with_key('gpgcheck') }
it_behaves_like 'a Yum class'
end
end
end
context 'when clean_old_kernels => false' do
let(:params) { { clean_old_kernels: false } }
it { is_expected.to contain_exec('package-cleanup_oldkernels').without_subscribe }
end
context 'when epel is enabled' do
let(:params) { { managed_repos: ['epel'] } }
it { is_expected.to contain_yumrepo('epel') }
case facts[:os]['release']['major']
when '9'
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9') }
when '8'
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8') }
when '7'
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7') }
when '6'
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6') }
end
end
context 'when utils_package_name is not set' do
it { is_expected.to compile.with_all_deps }
case facts[:os]['name']
when 'Fedora'
it { is_expected.to contain_package('dnf-utils') }
else
it { is_expected.to contain_package('yum-utils') }
end
end
context 'when utils_package_name is set' do
let(:params) { { utils_package_name: 'dnf-utils' } }
it { is_expected.not_to contain_package('yum-utils') }
it { is_expected.to contain_package('dnf-utils') }
end
context 'when custom repos is set' do
let(:params) do
{
managed_repos: ['example'],
repos: {
example: {
baseurl: 'https://example.com',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example'
}
},
gpgkeys: {
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example' => {
'source' => 'http://example.com/gpg'
}
}
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_yumrepo_resource_count(1) }
it { is_expected.to contain_yumrepo('example') }
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example') }
end
context 'when custom repos with multiple gpgkeys is set' do
let(:params) do
{
managed_repos: ['example'],
repos: {
example: {
baseurl: 'https://example.com',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example2',
}
},
gpgkeys: {
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example' => {
'source' => 'http://example.com/gpg'
},
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example2' => {
'source' => 'http://example.com/gpg2'
}
}
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to have_yumrepo_resource_count(1) }
it { is_expected.to contain_yumrepo('example') }
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example') }
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example2') }
end
end
end
context 'on an unsupported operating system' do
let(:facts) { { os: { family: 'Solaris', name: 'Nexenta' } } }
it { is_expected.to raise_error(Puppet::Error, %r{Nexenta not supported}) }
end
end