-
Notifications
You must be signed in to change notification settings - Fork 56
/
pe_utils_spec.rb
2037 lines (1747 loc) · 82.2 KB
/
pe_utils_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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require 'spec_helper'
require 'scooter'
class ClassMixedWithDSLInstallUtils
include Beaker::DSL::InstallUtils
include Beaker::DSL::Wrappers
include Beaker::DSL::Helpers
include Beaker::DSL::Structure
include Beaker::DSL::Roles
include Beaker::DSL::Patterns
include Beaker::DSL::PE
attr_accessor :hosts, :metadata, :options
def initialize
@metadata = {}
@options = {}
end
# Because some the methods now actually call out to the `step` method, we need to
# mock out `metadata` that is initialized in a test case.
def metadata
@metadata ||= {}
end
def logger
@logger ||= RSpec::Mocks::Double.new('logger').as_null_object
end
end
describe ClassMixedWithDSLInstallUtils do
let(:presets) { Beaker::Options::Presets.new }
let(:opts) { presets.presets.merge(presets.env_vars) }
let(:basic_hosts) { make_hosts( { :pe_ver => '3.0',
:platform => 'linux',
:roles => [ 'agent' ],
:type => 'pe'}, 4 ) }
let(:hosts) { basic_hosts[0][:roles] = ['master', 'database', 'dashboard']
basic_hosts[1][:platform] = 'windows'
basic_hosts[2][:platform] = 'osx-10.9-x86_64'
basic_hosts[3][:platform] = 'eos'
basic_hosts }
let(:hosts_sorted) { [ hosts[1], hosts[0], hosts[2], hosts[3] ] }
let(:winhost) { make_host( 'winhost', { :platform => 'windows',
:pe_ver => '3.0',
:type => 'pe',
:working_dir => '/tmp' } ) }
let(:machost) { make_host( 'machost', { :platform => 'osx-10.9-x86_64',
:pe_ver => '3.0',
:type => 'pe',
:working_dir => '/tmp' } ) }
let(:unixhost) { make_host( 'unixhost', { :platform => 'linux',
:pe_ver => '3.0',
:type => 'pe',
:working_dir => '/tmp',
:dist => 'puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386' } ) }
let(:eoshost) { make_host( 'eoshost', { :platform => 'eos',
:pe_ver => '3.0',
:type => 'pe',
:working_dir => '/tmp',
:dist => 'puppet-enterprise-3.7.1-rc0-78-gffc958f-eos-4-i386' } ) }
context '#prep_host_for_upgrade' do
it 'sets per host options before global options' do
opts['pe_upgrade_ver'] = 'options-specific-var'
hosts.each do |host|
host['pe_upgrade_dir'] = 'host-specific-pe-dir'
host['pe_upgrade_ver'] = 'host-specific-pe-ver'
subject.prep_host_for_upgrade(host, opts, 'argument-specific-pe-dir')
expect(host['pe_dir']).to eq('host-specific-pe-dir')
expect(host['pe_ver']).to eq('host-specific-pe-ver')
end
end
it 'sets global options when no host options are available' do
opts['pe_upgrade_ver'] = 'options-specific-var'
hosts.each do |host|
host['pe_upgrade_dir'] = nil
host['pe_upgrade_ver'] = nil
subject.prep_host_for_upgrade(host, opts, 'argument-specific-pe-dir')
expect(host['pe_dir']).to eq('argument-specific-pe-dir')
expect(host['pe_ver']).to eq('options-specific-var')
end
end
it 'calls #load_pe_version when neither global or host options are present' do
opts['pe_upgrade_ver'] = nil
hosts.each do |host|
host['pe_upgrade_dir'] = nil
host['pe_upgrade_ver'] = nil
expect( Beaker::Options::PEVersionScraper ).to receive(:load_pe_version).and_return('file_version')
subject.prep_host_for_upgrade(host, opts, 'argument-specific-pe-dir')
expect(host['pe_ver']).to eq('file_version')
expect(host['pe_dir']).to eq('argument-specific-pe-dir')
end
end
end
context '#configure_pe_defaults_on' do
it 'uses aio paths for hosts of role aio' do
hosts.each do |host|
host[:pe_ver] = nil
host[:version] = nil
host[:roles] = host[:roles] | ['aio']
end
expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_aio_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_puppet_paths_on).exactly(hosts.length).times
subject.configure_pe_defaults_on( hosts )
end
it 'uses pe paths for hosts of type pe' do
hosts.each do |host|
host[:type] = 'pe'
end
expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_aio_defaults_on).never
expect(subject).to receive(:add_puppet_paths_on).exactly(hosts.length).times
subject.configure_pe_defaults_on( hosts )
end
it 'uses aio paths for hosts of type aio' do
hosts.each do |host|
host[:pe_ver] = nil
host[:version] = nil
host[:type] = 'aio'
end
expect(subject).to receive(:add_aio_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_puppet_paths_on).exactly(hosts.length).times
subject.configure_pe_defaults_on( hosts )
end
it 'uses no paths for hosts with no type' do
hosts.each do |host|
host[:type] = nil
end
expect(subject).to receive(:add_pe_defaults_on).never
expect(subject).to receive(:add_aio_defaults_on).never
expect(subject).to receive(:add_puppet_paths_on).never
subject.configure_pe_defaults_on( hosts )
end
it 'uses aio paths for hosts of version >= 4.0' do
hosts.each do |host|
host[:pe_ver] = '4.0'
end
expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_aio_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_puppet_paths_on).exactly(hosts.length).times
subject.configure_pe_defaults_on( hosts )
end
it 'uses pe paths for hosts of version < 4.0' do
hosts.each do |host|
host[:pe_ver] = '3.8'
end
expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times
expect(subject).to receive(:add_aio_defaults_on).never
expect(subject).to receive(:add_puppet_paths_on).exactly(hosts.length).times
subject.configure_pe_defaults_on( hosts )
end
end
describe 'sorted_hosts' do
it 'can reorder so that the master comes first' do
allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
expect( subject.sorted_hosts ).to be === hosts
end
it 'leaves correctly ordered hosts alone' do
allow( subject ).to receive( :hosts ).and_return( hosts )
expect( subject.sorted_hosts ).to be === hosts
end
it 'does not allow nil entries' do
allow( subject ).to receive( :options ).and_return( { :masterless => true } )
masterless_host = [basic_hosts[0]]
allow( subject ).to receive( :hosts ).and_return( masterless_host )
expect( subject.sorted_hosts ).to be === masterless_host
end
end
describe 'installer_cmd' do
it 'generates a unix PE install command for a unix host' do
the_host = unixhost.dup
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['pe_installer_conf_setting'] = '-a /tmp/answers'
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp/puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386 && ./puppet-enterprise-installer -a /tmp/answers"
end
it 'generates a unix PE frictionless install command for a unix host with role "frictionless"' do
allow( subject ).to receive( :master ).and_return( 'testmaster' )
the_host = unixhost.dup
the_host['pe_ver'] = '3.8.0'
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['roles'] = ['frictionless']
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.8.0/install.bash && bash install.bash"
end
it 'generates a unix PE frictionless install command for a unix host with role "frictionless" and "frictionless_options"' do
allow( subject ).to receive( :master ).and_return( 'testmaster' )
the_host = unixhost.dup
the_host['pe_ver'] = '3.8.0'
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['roles'] = ['frictionless']
the_host['frictionless_options'] = { 'main' => { 'dns_alt_names' => 'puppet' } }
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.8.0/install.bash && bash install.bash main:dns_alt_names=puppet"
end
it 'generates a osx PE install command for a osx host' do
the_host = machost.dup
the_host['pe_installer'] = 'puppet-enterprise-installer'
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && hdiutil attach .dmg && installer -pkg /Volumes/puppet-enterprise-3.0/puppet-enterprise-installer-3.0.pkg -target /"
end
it 'calls the EOS PE install command for an EOS host' do
the_host = eoshost.dup
expect( the_host ).to receive( :install_from_file ).with( /swix$/ )
subject.installer_cmd( the_host, {} )
end
it 'generates a unix PE install command in verbose for a unix host when pe_debug is enabled' do
the_host = unixhost.dup
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['pe_installer_conf_setting'] = '-a /tmp/answers'
the_host[:pe_debug] = true
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp/puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386 && ./puppet-enterprise-installer -D -a /tmp/answers"
end
it 'generates a osx PE install command in verbose for a osx host when pe_debug is enabled' do
the_host = machost.dup
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host[:pe_debug] = true
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && hdiutil attach .dmg && installer -verboseR -pkg /Volumes/puppet-enterprise-3.0/puppet-enterprise-installer-3.0.pkg -target /"
end
it 'generates a unix PE frictionless install command in verbose for a unix host with role "frictionless" and pe_debug is enabled' do
allow( subject ).to receive( :master ).and_return( 'testmaster' )
the_host = unixhost.dup
the_host['pe_ver'] = '3.8.0'
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['roles'] = ['frictionless']
the_host[:pe_debug] = true
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.8.0/install.bash && bash -x install.bash"
end
end
describe 'run_puppet_on_non_infrastructure_nodes' do
let(:monolithic) { make_host('monolithic', :pe_ver => '2016.4', :platform => 'el-7-x86_64', :roles => [ 'master', 'database', 'dashboard' ]) }
let(:el_agent) { make_host('agent', :pe_ver => '2016.4', :platform => 'el-7-x86_64', :roles => ['frictionless']) }
let(:deb_agent) { make_host('agent', :pe_ver => '2016.4', :platform => 'debian-7-x86_64', :roles => ['frictionless']) }
let(:master) { make_host('master', :pe_ver => '2016.4', :platform => 'el-7-x86_64', :roles => [ 'master']) }
let(:database) { make_host('database', :pe_ver => '2016.4', :platform => 'el-7-x86_64', :roles => [ 'database']) }
let(:dashboard) { make_host('dashboard', :pe_ver => '2016.4', :platform => 'el-7-x86_64', :roles => [ 'dashboard']) }
it 'runs puppet on non-infra nodes with a monolithic master' do
expect(subject).to receive(:on).with([el_agent, deb_agent], proc {|cmd| cmd.command == "puppet agent"}, hash_including(:run_in_parallel => true)).once
expect(subject).to receive(:on).with([monolithic], proc {|cmd| cmd.command == "puppet agent"}, hash_including(:run_in_parallel => true)).never
subject.run_puppet_on_non_infrastructure_nodes([monolithic, el_agent, deb_agent])
end
it 'runs puppet on non-infra nodes with a split topology' do
expect(subject).to receive(:on).with([el_agent, deb_agent], proc {|cmd| cmd.command == "puppet agent"}, hash_including(:run_in_parallel => true)).once
expect(subject).to receive(:on).with([master], proc {|cmd| cmd.command == "puppet agent"}, hash_including(:run_in_parallel => true)).never
expect(subject).to receive(:on).with([database], proc {|cmd| cmd.command == "puppet agent"}, hash_including(:run_in_parallel => true)).never
expect(subject).to receive(:on).with([dashboard], proc {|cmd| cmd.command == "puppet agent"}, hash_including(:run_in_parallel => true)).never
subject.run_puppet_on_non_infrastructure_nodes([master, database, dashboard, el_agent, deb_agent])
end
end
describe 'install_via_msi?' do
it 'returns true if pe_version is before PE 2016.4.0' do
the_host = winhost.dup
the_host['roles'] = ['frictionless']
the_host['pe_ver'] = '2015.2.3'
expect(subject.install_via_msi?(the_host)).to eq(true)
end
it 'returns nil if pe_version is PE 2016.4.0 or newer' do
the_host = winhost.dup
the_host['roles'] = ['frictionless']
the_host['pe_ver'] = '2016.4.2'
expect(subject.install_via_msi?(the_host)).to be nil
end
it 'returns true if pe_version is 2016.4.0 and platform is windows-2008r2 bug' do
the_host = winhost.dup
the_host['roles'] = ['frictionless']
the_host['platform'] = 'windows-2008r2'
the_host['pe_ver'] = '2016.4.0'
expect(subject.install_via_msi?(the_host)).to eq(true)
end
it 'returns false if pe_version is 2016.4.3 and platform is windows-2008r2 bug' do
the_host = winhost.dup
the_host['roles'] = ['frictionless']
the_host['platform'] = 'windows-2008r2'
the_host['pe_ver'] = '2016.4.3'
expect(subject.install_via_msi?(the_host)).to eq(false)
end
it 'returns true if pe_version is 2016.5.1 and platform is windows-2008r2 bug' do
the_host = winhost.dup
the_host['roles'] = ['frictionless']
the_host['platform'] = 'windows-2008r2'
the_host['pe_ver'] = '2016.5.1'
expect(subject.install_via_msi?(the_host)).to eq(true)
end
it 'returns false if pe_version is 2017.1.0 and platform is windows-2008r2 bug' do
the_host = winhost.dup
the_host['roles'] = ['frictionless']
the_host['platform'] = 'windows-2008r2'
the_host['pe_ver'] = '2017.1.0'
expect(subject.install_via_msi?(the_host)).to eq(false)
end
end
describe 'higgs installer' do
let(:host) { unixhost }
let(:higgs_regex) { %r{cd .* ; nohup \./puppet-enterprise-installer <<<#{higgs_answer} .*} }
before(:each) do
host['pe_installer'] = 'puppet-enterprise-installer'
end
def prep_host(host)
allow(subject).to receive(:sleep)
allow(host).to receive(:tmpdir).and_return('/tmp')
allow(subject).to receive(:fetch_pe)
expect(subject).to receive(:on).with(host, higgs_regex, opts).once
result = double(Beaker::Result, :stdout => 'Please go to https://somewhere in your browser to continue installation')
expect(subject).to receive(:on).with(host, %r{cd .* && cat .*}, anything)
.and_return(result)
end
context 'for legacy installer' do
let(:higgs_answer) { 'Y' }
context 'the higgs_installer_cmd' do
it 'returns correct command to invoke Higgs' do
expect(subject.higgs_installer_cmd(host)).to match(higgs_regex)
end
end
context 'the do_higgs_install' do
it 'submits the correct installer cmd to invoke Higgs' do
prep_host(host)
subject.do_higgs_install(host, opts)
end
end
end
context 'for meep installer' do
let(:higgs_answer) { '1' }
before(:each) do
host['pe_ver'] = '2016.2.0'
end
context 'the higgs_installer_cmd' do
it 'submits correct command to invoke Higgs' do
subject.prepare_host_installer_options(host)
expect(subject.higgs_installer_cmd(host)).to match(higgs_regex)
end
end
context 'the do_higgs_install' do
it 'submits the correct installer cmd to invoke Higgs' do
prep_host(host)
subject.do_higgs_install(host, opts)
end
end
end
end
describe 'prepare_host_installer_options' do
let(:legacy_settings) do
{
:pe_installer_conf_file => '/tmp/answers',
:pe_installer_conf_setting => '-a /tmp/answers',
}
end
let(:meep_settings) do
{
:pe_installer_conf_file => '/tmp/pe.conf',
:pe_installer_conf_setting => '-c /tmp/pe.conf',
}
end
let(:host) { unixhost }
before(:each) do
host['pe_ver'] = pe_ver
subject.prepare_host_installer_options(host)
end
def slice_installer_options(host)
host.host_hash.select { |k,v| [ :pe_installer_conf_file, :pe_installer_conf_setting].include?(k) }
end
context 'when version < 2016.2.0' do
let(:pe_ver) { '3.8.5' }
it 'sets legacy settings' do
expect(slice_installer_options(host)).to eq(legacy_settings)
end
end
context 'when version >= 2016.2.0' do
let (:pe_ver) { '2016.2.0' }
it 'test use_meep?' do
expect(subject.use_meep?('3.8.5')).to eq(false)
expect(subject.use_meep?('2016.1.2')).to eq(false)
expect(subject.use_meep?('2016.2.0')).to eq(true)
expect(subject.use_meep?('2016.2.0-rc1-gabcdef')).to eq(true)
end
it 'sets meep settings' do
expect(slice_installer_options(host)).to eq(meep_settings)
end
end
end
describe 'use_meep_for_classification?' do
let(:feature_flag) { nil }
let(:environment_feature_flag) { nil }
let(:answers) do
{
:answers => {
'feature_flags' => {
'pe_modules_next' => feature_flag,
},
},
}
end
let(:options) do
feature_flag.nil? ?
opts :
opts.merge(answers)
end
let(:host) { unixhost }
before(:each) do
subject.options = options
if !environment_feature_flag.nil?
ENV['PE_MODULES_NEXT'] = environment_feature_flag
end
end
after(:each) do
ENV.delete('PE_MODULES_NEXT')
end
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(false) }
context 'feature flag false' do
let(:feature_flag) { false }
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(false) }
end
context 'feature flag true' do
let(:feature_flag) { true }
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(true) }
end
context 'environment feature flag true' do
let(:environment_feature_flag) { 'true' }
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(true) }
context 'answers feature flag false' do
let(:feature_flag) { false }
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(false) }
end
end
context 'environment feature flag false' do
let(:environment_feature_flag) { 'false' }
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(false) }
context 'answers feature flag true' do
let(:feature_flag) { true }
it { expect(subject.use_meep_for_classification?('2017.1.0', options)).to eq(false) }
it { expect(subject.use_meep_for_classification?('2017.2.0', options)).to eq(true) }
end
end
end
describe 'generate_installer_conf_file_for' do
let(:master) { hosts.first }
it 'generates a legacy answer file if < 2016.2.0' do
master['pe_installer_conf_file'] = '/tmp/answers'
expect(subject).to receive(:create_remote_file).with(
master,
'/tmp/answers',
%r{q_install=y.*q_puppetmaster_certname=#{master}}m
)
subject.generate_installer_conf_file_for(master, hosts, opts)
end
it 'generates a meep config file if >= 2016.2.0' do
master['pe_installer_conf_file'] = '/tmp/pe.conf'
master['pe_ver'] = '2016.2.0'
expect(subject).to receive(:create_remote_file).with(
master,
'/tmp/pe.conf',
%r{\{.*"puppet_enterprise::puppet_master_host": "#{master.hostname}"}m
)
subject.generate_installer_conf_file_for(master, hosts, opts)
end
end
describe 'register_feature_flags!' do
it 'does nothing if no flag is set' do
expect(subject.register_feature_flags!(opts)).to eq(opts)
expect(opts[:answers]).to be_nil
end
context 'with flag set' do
before(:each) do
ENV['PE_MODULES_NEXT'] = 'true'
end
after(:each) do
ENV.delete('PE_MODULES_NEXT')
end
it 'updates answers' do
expect(subject.register_feature_flags!(opts)).to match(opts.merge({
:answers => {
:feature_flags => {
:pe_modules_next => true
}
}
}))
end
context 'and answer explicitly set' do
let(:answers) do
{
:answers => {
'feature_flags' => {
'pe_modules_next' => false
}
}
}
end
before(:each) do
opts.merge!(answers)
end
it 'keeps explicit setting' do
expect(subject.register_feature_flags!(opts)).to match(opts.merge(answers))
end
end
end
end
describe 'feature_flag?' do
context 'without :answers' do
it 'is nil for pe_modules_next' do
expect(subject.feature_flag?('pe_modules_next', opts)).to eq(nil)
expect(subject.feature_flag?(:pe_modules_next, opts)).to eq(nil)
end
end
context 'with :answers but no flag' do
before(:each) do
opts[:answers] = {}
end
it 'is nil for pe_modules_next' do
expect(subject.feature_flag?('pe_modules_next', opts)).to eq(nil)
expect(subject.feature_flag?(:pe_modules_next, opts)).to eq(nil)
end
end
context 'with answers set' do
let(:options) do
opts.merge(
:answers => {
'feature_flags' => {
'pe_modules_next' => flag
}
}
)
end
context 'false' do
let(:flag) { false }
it { expect(subject.feature_flag?('pe_modules_next', options)).to eq(false) }
it { expect(subject.feature_flag?(:pe_modules_next, options)).to eq(false) }
end
context 'true' do
let(:flag) { true }
it { expect(subject.feature_flag?('pe_modules_next', options)).to eq(true) }
it { expect(subject.feature_flag?(:pe_modules_next, options)).to eq(true) }
context 'as string' do
let(:flag) { 'true' }
it { expect(subject.feature_flag?('pe_modules_next', options)).to eq(true) }
it { expect(subject.feature_flag?(:pe_modules_next, options)).to eq(true) }
end
end
end
end
describe 'setup_beaker_answers_opts' do
let(:opts) { {} }
let(:host) { hosts.first }
context 'for legacy installer' do
it 'adds option for bash format' do
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :bash,
:include_legacy_database_defaults => false,
)
)
end
end
context 'for meep installer' do
before(:each) do
host['pe_ver'] = '2016.2.0'
end
it 'adds option for hiera format' do
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :hiera,
:include_legacy_database_defaults => false,
)
)
end
context 'with pe-modules-next' do
let(:options) do
opts.merge(
:answers => {
:feature_flags => {
:pe_modules_next => true
}
}
)
end
it 'adds meep_schema_version' do
expect(subject.setup_beaker_answers_opts(host, options)).to eq(
options.merge(
:format => :hiera,
:include_legacy_database_defaults => false,
:meep_schema_version => '2.0',
)
)
end
end
context 'when upgrading' do
let(:opts) { { :type => :upgrade } }
context 'from meep' do
it 'sets legacy password defaults false' do
host['pe_ver'] = '2016.2.1'
host['previous_pe_ver'] = '2016.2.0'
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :hiera,
:include_legacy_database_defaults => false,
)
)
end
end
context 'from legacy' do
it 'sets legacy password defaults to true' do
host['previous_pe_ver'] = '3.8.5'
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :hiera,
:include_legacy_database_defaults => true,
)
)
end
end
end
end
end
describe 'ignore_gpg_key_warning_on_hosts' do
let(:on_cmd) { "echo 'APT { Get { AllowUnauthenticated \"1\"; }; };' >> /etc/apt/apt.conf" }
let(:deb_host) do
host = hosts.first
host['platform'] = 'debian'
host
end
context 'mixed platforms' do
before(:each) do
hosts[0]['platform'] = 'centos'
hosts[1]['platform'] = 'debian'
hosts[2]['platform'] = 'ubuntu'
end
it 'does nothing on el platforms' do
expect(subject).not_to receive(:on).with(hosts[0], on_cmd)
subject.ignore_gpg_key_warning_on_hosts(hosts, opts)
end
it 'adds in apt ignore gpg-key warning' do
expect(subject).to receive(:on).with(hosts[1], on_cmd)
expect(subject).to receive(:on).with(hosts[2], on_cmd)
subject.ignore_gpg_key_warning_on_hosts(hosts, opts)
end
end
context 'mixed pe_versions' do
before(:each) do
hosts[0]['platform'] = 'debian'
hosts[0]['pe_ver'] = '2016.4.0'
hosts[1]['platform'] = 'debian'
hosts[1]['pe_ver'] = '3.8.4'
end
it 'adds apt gpg-key ignore to required hosts' do
expect(subject).not_to receive(:on).with(hosts[0], on_cmd)
expect(subject).to receive(:on).with(hosts[1], on_cmd)
subject.ignore_gpg_key_warning_on_hosts(hosts, opts)
end
end
context 'PE versions earlier than 3.8.7' do
['3.3.2', '3.7.3', '3.8.2', '3.8.4', '3.8.5', '3.8.6'].each do |pe_ver|
it "Adds apt gpg-key ignore on PE #{pe_ver}" do
deb_host['pe_ver'] = pe_ver
expect(subject).to receive(:on).with(deb_host, on_cmd)
subject.ignore_gpg_key_warning_on_hosts(hosts, opts)
end
end
end
context 'PE versions between 2015.2.0 and 2016.2.1' do
['2015.2.0', '2015.3.1', '2016.1.2', '2016.2.1'].each do |pe_ver|
it "Adds apt gpg-key ignore on PE #{pe_ver}" do
deb_host['pe_ver'] = pe_ver
expect(subject).to receive(:on).with(deb_host, on_cmd)
subject.ignore_gpg_key_warning_on_hosts(hosts, opts)
end
end
end
['2016.4.0', '2016.5.1', '2017.1.0'].each do |pe_ver|
context "PE #{pe_ver}" do
it 'does nothing' do
deb_host['pe_ver'] = pe_ver
expect(subject).not_to receive(:on).with(deb_host, on_cmd)
subject.ignore_gpg_key_warning_on_hosts(hosts, opts)
end
end
end
end
describe 'fetch_pe' do
it 'can push a local PE .tar.gz to a host and unpack it' do
allow( File ).to receive( :directory? ).and_return( true ) #is local
allow( File ).to receive( :exists? ).and_return( true ) #is a .tar.gz
unixhost['pe_dir'] = '/local/file/path'
allow( subject ).to receive( :scp_to ).and_return( true )
path = unixhost['pe_dir']
filename = "#{ unixhost['dist'] }"
extension = '.tar.gz'
expect( subject ).to receive( :scp_to ).with( unixhost, "#{ path }/#{ filename }#{ extension }", "#{ unixhost['working_dir'] }/#{ filename }#{ extension }" ).once
expect( subject ).to receive( :on ).with( unixhost, /gunzip/ ).once
expect( subject ).to receive( :on ).with( unixhost, /tar -xvf/ ).once
subject.fetch_pe( [unixhost], {} )
end
it 'can download a PE .tar from a URL to a host and unpack it' do
allow( File ).to receive( :directory? ).and_return( false ) #is not local
allow( subject ).to receive( :link_exists? ) do |arg|
if arg =~ /.tar.gz/ #there is no .tar.gz link, only a .tar
false
else
true
end
end
allow( subject ).to receive( :on ).and_return( true )
path = unixhost['pe_dir']
filename = "#{ unixhost['dist'] }"
extension = '.tar'
expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | tar -xvf -" ).once
subject.fetch_pe( [unixhost], {} )
end
it 'can download a PE .tar from a URL to #fetch_and_push_pe' do
allow( File ).to receive( :directory? ).and_return( false ) #is not local
allow( subject ).to receive( :link_exists? ) do |arg|
if arg =~ /.tar.gz/ #there is no .tar.gz link, only a .tar
false
else
true
end
end
allow( subject ).to receive( :on ).and_return( true )
filename = "#{ unixhost['dist'] }"
extension = '.tar'
expect( subject ).to receive( :fetch_and_push_pe ).with( unixhost, anything, filename, extension ).once
expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; cat #{ filename }#{ extension } | tar -xvf -" ).once
subject.fetch_pe( [unixhost], {:fetch_local_then_push_to_host => true} )
end
it 'can download a PE .tar.gz from a URL to a host and unpack it' do
allow( File ).to receive( :directory? ).and_return( false ) #is not local
allow( subject ).to receive( :link_exists? ).and_return( true ) #is a tar.gz
allow( subject ).to receive( :on ).and_return( true )
path = unixhost['pe_dir']
filename = "#{ unixhost['dist'] }"
extension = '.tar.gz'
expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | gunzip | tar -xvf -" ).once
subject.fetch_pe( [unixhost], {} )
end
it 'can download a PE .tar.gz from a URL to #fetch_and_push_pe' do
allow( File ).to receive( :directory? ).and_return( false ) #is not local
allow( subject ).to receive( :link_exists? ).and_return( true ) #is a tar.gz
allow( subject ).to receive( :on ).and_return( true )
filename = "#{ unixhost['dist'] }"
extension = '.tar.gz'
expect( subject ).to receive( :fetch_and_push_pe ).with( unixhost, anything, filename, extension ).once
expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; cat #{ filename }#{ extension } | gunzip | tar -xvf -" ).once
subject.fetch_pe( [unixhost], {:fetch_local_then_push_to_host => true} )
end
it 'calls the host method to get an EOS .swix file from a URL' do
allow( File ).to receive( :directory? ).and_return( false ) #is not local
allow( subject ).to receive( :link_exists? ).and_return( true ) #skip file check
expect( eoshost ).to receive( :get_remote_file ).with( /swix$/ ).once
subject.fetch_pe( [eoshost], {} )
end
it 'can push a local PE package to a windows host' do
allow( File ).to receive( :directory? ).and_return( true ) #is local
allow( File ).to receive( :exists? ).and_return( true ) #is present
winhost['dist'] = 'puppet-enterprise-3.0'
allow( subject ).to receive( :scp_to ).and_return( true )
path = winhost['pe_dir']
filename = "puppet-enterprise-#{ winhost['pe_ver'] }"
extension = '.msi'
expect( subject ).to receive( :scp_to ).with( winhost, "#{ path }/#{ filename }#{ extension }", "#{ winhost['working_dir'] }/#{ filename }#{ extension }" ).once
subject.fetch_pe( [winhost], {} )
end
it 'can download a PE dmg from a URL to a mac host' do
allow( File ).to receive( :directory? ).and_return( false ) #is not local
allow( subject ).to receive( :link_exists? ).and_return( true ) #is not local
allow( subject ).to receive( :on ).and_return( true )
path = machost['pe_dir']
filename = "#{ machost['dist'] }"
extension = '.dmg'
expect( subject ).to receive( :on ).with( machost, "cd #{ machost['working_dir'] }; curl -O #{ path }/#{ filename }#{ extension }" ).once
subject.fetch_pe( [machost], {} )
end
it 'can push a PE dmg to a mac host' do
allow( File ).to receive( :directory? ).and_return( true ) #is local
allow( File ).to receive( :exists? ).and_return( true ) #is present
allow( subject ).to receive( :scp_to ).and_return( true )
path = machost['pe_dir']
filename = "#{ machost['dist'] }"
extension = '.dmg'
expect( subject ).to receive( :scp_to ).with( machost, "#{ path }/#{ filename }#{ extension }", "#{ machost['working_dir'] }/#{ filename }#{ extension }" ).once
subject.fetch_pe( [machost], {} )
end
it "does nothing for a frictionless agent for PE >= 3.2.0" do
unixhost['roles'] << 'frictionless'
unixhost['pe_ver'] = '3.2.0'
expect( subject).to_not receive(:scp_to)
expect( subject).to_not receive(:on)
subject.fetch_pe( [unixhost], {} )
end
end
describe "#determine_install_type" do
let(:monolithic) { make_host('monolithic', :pe_ver => '2016.4', :roles => [ 'master', 'database', 'dashboard' ]) }
let(:master) { make_host('master', :pe_ver => '2016.4', :roles => [ 'master' ]) }
let(:puppetdb) { make_host('puppetdb', :pe_ver => '2016.4', :roles => [ 'database' ]) }
let(:console) { make_host('console', :pe_ver => '2016.4', :roles => [ 'dashboard' ]) }
let(:agent) { make_host('agent', :pe_ver => '2016.4', :roles => ['frictionless']) }
it 'identifies a monolithic install with frictionless agents' do
hosts = [monolithic, agent, agent, agent]
expect(subject.determine_install_type(hosts, {})).to eq(:simple_monolithic)
end
it 'identifies a monolithic install without frictionless agents' do
expect(subject.determine_install_type([monolithic], {})).to eq(:simple_monolithic)
end
it 'identifies a split install with frictionless agents' do
hosts = [master, puppetdb, console, agent, agent, agent]
expect(subject.determine_install_type(hosts, {})).to eq(:simple_split)
end
it 'identifies a split install without frictionless agents' do
hosts = [master, puppetdb, console]
expect(subject.determine_install_type(hosts, {})).to eq(:simple_split)
end
it 'identifies an install with multiple agent versions as generic' do
new_agent = make_host('agent', :pe_ver => '2017.2', :roles => ['frictionless'])
hosts = [monolithic, agent, new_agent]
expect(subject.determine_install_type(hosts, {})).to eq(:generic)
end
it 'identifies an upgrade as generic' do
hosts = [monolithic, agent, agent, agent]
expect(subject.determine_install_type(hosts, {:type => :upgrade})).to eq(:generic)
end
it 'identifies a legacy PE version as generic' do
old_monolithic = make_host('monolithic', :pe_ver => '3.8', :roles => [ 'master', 'database', 'dashboard' ])
old_agent = make_host('agent', :pe_ver => '3.8', :roles => ['frictionless'])
hosts = [old_monolithic, old_agent, old_agent, old_agent]
expect(subject.determine_install_type(hosts, {})).to eq(:generic)
end
it 'identifies a non-standard install as generic' do
hosts = [monolithic, master, agent, agent, agent]
expect(subject.determine_install_type(hosts, {})).to eq(:generic)
end
end
describe '#deploy_frictionless_to_master' do
let(:master) { make_host('master', :pe_ver => '2017.2', :platform => 'ubuntu-16.04-x86_64', :roles => ['master', 'database', 'dashboard']) }
let(:agent) { make_host('agent', :pe_ver => '2017.2', :platform => 'el-7-x86_64', :roles => ['frictionless']) }
let(:dispatcher) { double('dispatcher') }
let(:node_group) { {} }
before :each do
allow(subject).to receive(:on)
allow(subject).to receive(:hosts).and_return([master, agent])
allow(Scooter::HttpDispatchers::ConsoleDispatcher).to receive(:new).and_return(dispatcher)
allow(dispatcher).to receive(:get_node_group_by_name).and_return(node_group)
allow(dispatcher).to receive(:create_new_node_group_model) {|model| node_group.update(model)}
end
it 'adds the right pe_repo class to the Beaker Frictionless Agent group' do
subject.deploy_frictionless_to_master(agent)
expect(node_group['rule']).to eq(['and', ['=', 'name', 'master']])
expect(node_group['classes']).to include('pe_repo::platform::el_7_x86_64')
end
it 'only adds classes once' do
expect(dispatcher).to receive(:create_new_node_group_model).once
subject.deploy_frictionless_to_master(agent)
subject.deploy_frictionless_to_master(agent)
expect(node_group['classes']).to include('pe_repo::platform::el_7_x86_64')
end
end