beaker-puppet 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -638,7 +638,7 @@ describe ClassMixedWithDSLHelpers do
638
638
  end
639
639
  end
640
640
 
641
- it 'signs certs with `puppetserver ca` in Puppet 6' do
641
+ it 'signs certs with `puppetserver ca`' do
642
642
  allow(subject).to receive(:sleep).and_return(true)
643
643
 
644
644
  result.stdout = "+ \"#{agent}\""
@@ -647,34 +647,12 @@ describe ClassMixedWithDSLHelpers do
647
647
  arg
648
648
  end
649
649
 
650
- version_result = double('version', stdout: '6.0.0')
651
- expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
652
- expect(subject).to receive(:version_is_less).and_return(false)
653
650
  expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]).once
654
651
  expect(subject).to receive(:on).with(master, 'puppetserver ca list --all').once.and_return(result)
655
652
 
656
653
  subject.sign_certificate_for(agent)
657
654
  end
658
655
 
659
- it 'signs certs with `puppet cert` in Puppet 5' do
660
- allow(subject).to receive(:sleep).and_return(true)
661
-
662
- result.stdout = "+ \"#{agent}\""
663
-
664
- allow(subject).to receive(:puppet) do |arg|
665
- arg
666
- end
667
-
668
- version_result = double('version', stdout: '5.0.0')
669
- expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
670
- expect(subject).to receive(:version_is_less).and_return(true)
671
- expect(subject).to receive(:on).with(master, 'cert --sign --all --allow-dns-alt-names',
672
- acceptable_exit_codes: [0, 24]).once
673
- expect(subject).to receive(:on).with(master, 'cert --list --all').once.and_return(result)
674
-
675
- subject.sign_certificate_for(agent)
676
- end
677
-
678
656
  it 'retries 11 times before quitting' do
679
657
  allow(subject).to receive(:sleep).and_return(true)
680
658
 
@@ -685,8 +663,6 @@ describe ClassMixedWithDSLHelpers do
685
663
  arg
686
664
  end
687
665
 
688
- version_result = double('version', stdout: '6.0.0')
689
- expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
690
666
  expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all',
691
667
  acceptable_exit_codes: [0, 24]).exactly(11).times
692
668
  expect(subject).to receive(:on).with(master,
@@ -706,8 +682,6 @@ describe ClassMixedWithDSLHelpers do
706
682
  arg
707
683
  end
708
684
  expect(subject).to receive(:on).with(master, 'agent -t', acceptable_exit_codes: [0, 1, 2]).once
709
- version_result = double('version', stdout: '6.0.0')
710
- expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
711
685
  expect(subject).to receive(:on).with(master, 'puppetserver ca sign --certname master').once
712
686
  expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all',
713
687
  acceptable_exit_codes: [0, 24]).once
@@ -760,7 +734,6 @@ describe ClassMixedWithDSLHelpers do
760
734
  end
761
735
 
762
736
  it 'raises the early_exception if backup_the_file fails' do
763
- allow(host).to receive(:use_service_scripts?)
764
737
  allow(subject).to receive(:restore_puppet_conf_from_backup)
765
738
  expect(subject).to receive(:backup_the_file).and_raise(RuntimeError.new('puppet conf backup failed'))
766
739
  expect do
@@ -772,7 +745,6 @@ describe ClassMixedWithDSLHelpers do
772
745
  allow(subject).to receive(:backup_the_file).and_raise(Minitest::Assertion.new('assertion failed!'))
773
746
  allow(host).to receive(:puppet).and_return({})
774
747
  allow(subject).to receive(:restore_puppet_conf_from_backup)
775
- allow(host).to receive(:use_service_scripts?)
776
748
  expect(subject).to receive(:fail_test)
777
749
  subject.with_puppet_running_on(host, {})
778
750
  end
@@ -847,7 +819,6 @@ describe ClassMixedWithDSLHelpers do
847
819
  allow(subject).to receive(:dump_puppet_log)
848
820
  allow(subject).to receive(:restore_puppet_conf_from_backup)
849
821
  allow(subject).to receive(:puppet_master_started)
850
- allow(subject).to receive(:start_puppet_from_source_on!)
851
822
  allow(subject).to receive(:lay_down_new_puppet_conf)
852
823
  allow(subject).to receive(:logger).and_return(logger)
853
824
  allow(logger).to receive(:error)
@@ -953,160 +924,6 @@ describe ClassMixedWithDSLHelpers do
953
924
  end
954
925
  end
955
926
 
956
- context 'for foss packaged hosts using passenger' do
957
- before(:each) do
958
- host.uses_passenger!
959
- end
960
- it 'bounces puppet twice' do
961
- allow(subject).to receive(:curl_with_retries)
962
- subject.with_puppet_running_on(host, {})
963
- expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
964
- end
965
-
966
- it 'gracefully restarts using apache2ctl' do
967
- allow(host).to receive(:check_for_command).and_return(true)
968
- allow(subject).to receive(:curl_with_retries)
969
- subject.with_puppet_running_on(host, {})
970
- expect(host).to execute_commands_matching(/apache2ctl graceful/).exactly(2).times
971
- end
972
-
973
- it 'gracefully restarts using apachectl' do
974
- allow(host).to receive(:check_for_command).and_return(false)
975
- allow(subject).to receive(:curl_with_retries)
976
- subject.with_puppet_running_on(host, {})
977
- expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
978
- end
979
-
980
- it 'yields to a block after bouncing service' do
981
- execution = 0
982
- allow(subject).to receive(:curl_with_retries)
983
- expect do
984
- subject.with_puppet_running_on(host, {}) do
985
- expect(host).to execute_commands_matching(/apachectl graceful/).once
986
- execution += 1
987
- end
988
- end.to change { execution }.by(1)
989
- expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
990
- end
991
-
992
- context ':restart_when_done flag set false' do
993
- it 'bounces puppet once' do
994
- allow(subject).to receive(:curl_with_retries)
995
- subject.with_puppet_running_on(host, { restart_when_done: false })
996
- expect(host).to execute_commands_matching(/apachectl graceful/).once
997
- end
998
-
999
- it 'yields to a block after bouncing service' do
1000
- execution = 0
1001
- allow(subject).to receive(:curl_with_retries)
1002
- expect do
1003
- subject.with_puppet_running_on(host, { restart_when_done: false }) do
1004
- expect(host).to execute_commands_matching(/apachectl graceful/).once
1005
- execution += 1
1006
- end
1007
- end.to change { execution }.by(1)
1008
- end
1009
- end
1010
- end
1011
-
1012
- context 'for foss packaged hosts using webrick' do
1013
- let(:use_service) { true }
1014
-
1015
- it 'stops and starts master using service scripts twice' do
1016
- allow(subject).to receive(:curl_with_retries)
1017
- subject.with_puppet_running_on(host, {})
1018
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
1019
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
1020
- end
1021
-
1022
- it 'yields to a block in between bounce calls for the service' do
1023
- execution = 0
1024
- expect do
1025
- subject.with_puppet_running_on(host, {}) do
1026
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
1027
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
1028
- execution += 1
1029
- end
1030
- end.to change { execution }.by(1)
1031
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
1032
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
1033
- end
1034
-
1035
- context ':restart_when_done flag set false' do
1036
- it 'stops (twice) and starts (once) master using service scripts' do
1037
- allow(subject).to receive(:curl_with_retries)
1038
- subject.with_puppet_running_on(host, { restart_when_done: false })
1039
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
1040
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
1041
- end
1042
-
1043
- it 'yields to a block after stopping and starting service' do
1044
- execution = 0
1045
- expect do
1046
- subject.with_puppet_running_on(host, { restart_when_done: false }) do
1047
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
1048
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
1049
- execution += 1
1050
- end
1051
- end.to change { execution }.by(1)
1052
- end
1053
- end
1054
- end
1055
-
1056
- context 'running from source' do
1057
- it 'does not try to stop if not started' do
1058
- expect(subject).to receive(:start_puppet_from_source_on!).and_return false
1059
- expect(subject).to_not receive(:stop_puppet_from_source_on)
1060
-
1061
- subject.with_puppet_running_on(host, {})
1062
- end
1063
-
1064
- context 'successfully' do
1065
- before do
1066
- expect(host).to receive(:port_open?).with(8140).and_return(true)
1067
- end
1068
-
1069
- it 'starts puppet from source' do
1070
- subject.with_puppet_running_on(host, {})
1071
- end
1072
-
1073
- it 'stops puppet from source' do
1074
- subject.with_puppet_running_on(host, {})
1075
- expect(host).to execute_commands_matching(/^kill [^-]/).once
1076
- expect(host).to execute_commands_matching(/^kill -0/).once
1077
- end
1078
-
1079
- it 'yields between starting and stopping' do
1080
- execution = 0
1081
- expect do
1082
- subject.with_puppet_running_on(host, {}) do
1083
- expect(host).to execute_commands_matching(/^puppet master/).once
1084
- execution += 1
1085
- end
1086
- end.to change { execution }.by(1)
1087
- expect(host).to execute_commands_matching(/^kill [^-]/).once
1088
- expect(host).to execute_commands_matching(/^kill -0/).once
1089
- end
1090
-
1091
- it 'passes on commandline args' do
1092
- subject.with_puppet_running_on(host, { __commandline_args__: '--with arg' })
1093
- expect(host).to execute_commands_matching(/^puppet master --with arg/).once
1094
- end
1095
-
1096
- it 'is not affected by the :restart_when_done flag' do
1097
- execution = 0
1098
- expect do
1099
- subject.with_puppet_running_on(host, { restart_when_done: true }) do
1100
- expect(host).to execute_commands_matching(/^puppet master/).once
1101
- execution += 1
1102
- end
1103
- end.to change { execution }.by(1)
1104
- expect(host).to execute_commands_matching(/^kill [^-]/).once
1105
- expect(host).to execute_commands_matching(/^kill -0/).once
1106
- end
1107
- end
1108
- end
1109
-
1110
927
  describe 'backup and restore of puppet.conf' do
1111
928
  before :each do
1112
929
  allow(subject).to receive(:puppet_config).with(host, 'confdir', anything).and_return('/root/mock')
@@ -1139,70 +956,6 @@ describe ClassMixedWithDSLHelpers do
1139
956
  /ensure=running/)
1140
957
  end
1141
958
  end
1142
-
1143
- context 'when a puppetservice is not used' do
1144
- before do
1145
- expect(host).to receive(:port_open?).with(8140).and_return(true)
1146
- end
1147
-
1148
- it 'backs up puppet.conf' do
1149
- subject.with_puppet_running_on(host, {})
1150
- expect(host).to execute_commands_matching(/cp #{original_location} #{backup_location}/).once
1151
- expect(host).to execute_commands_matching(/cat #{new_location} > #{original_location}/).once
1152
- end
1153
-
1154
- it 'restores puppet.conf after restarting when a puppetservice is not used' do
1155
- subject.with_puppet_running_on(host, {})
1156
- expect(host).to execute_commands_matching_in_order(/kill [^-]/,
1157
- /cat '#{backup_location}' > '#{original_location}'/m)
1158
- end
1159
-
1160
- it "doesn't restore a non-existent file" do
1161
- allow(subject).to receive(:backup_the_file)
1162
- subject.with_puppet_running_on(host, {})
1163
- expect(host).to execute_commands_matching(/rm -f '#{original_location}'/)
1164
- end
1165
- end
1166
- end
1167
-
1168
- let(:logger) { double.as_null_object }
1169
- describe 'handling failures' do
1170
- before do
1171
- allow(subject).to receive(:logger).and_return(logger)
1172
- expect(subject).to receive(:stop_puppet_from_source_on).and_raise(RuntimeError.new('Also failed in teardown.'))
1173
- expect(host).to receive(:port_open?).with(8140).and_return(true)
1174
- end
1175
-
1176
- it 'does not swallow an exception raised from within test block if ensure block also fails' do
1177
- expect(subject.logger).to receive(:error).with(/Raised during attempt to teardown.*Also failed in teardown/)
1178
-
1179
- expect do
1180
- subject.with_puppet_running_on(host, {}) { raise 'Failed while yielding.' }
1181
- end.to raise_error(RuntimeError, /failed.*because.*Failed while yielding./)
1182
- end
1183
-
1184
- it 'dumps the puppet logs if there is an error in the teardown' do
1185
- expect(subject.logger).to receive(:notify).with(/Dumping master log/)
1186
-
1187
- expect do
1188
- subject.with_puppet_running_on(host, {})
1189
- end.to raise_error(RuntimeError, /Also failed in teardown/)
1190
- end
1191
-
1192
- it 'does not mask the teardown error with an error from dumping the logs' do
1193
- expect(subject.logger).to receive(:notify).with(/Dumping master log/).and_raise('Error from dumping logs')
1194
-
1195
- expect do
1196
- subject.with_puppet_running_on(host, {})
1197
- end.to raise_error(RuntimeError, /Also failed in teardown/)
1198
- end
1199
-
1200
- it 'does not swallow a teardown exception if no earlier exception was raised' do
1201
- expect(subject.logger).to_not receive(:error)
1202
- expect do
1203
- subject.with_puppet_running_on(host, {})
1204
- end.to raise_error(RuntimeError, 'Also failed in teardown.')
1205
- end
1206
959
  end
1207
960
  end
1208
961
  end
@@ -1229,7 +982,6 @@ describe ClassMixedWithDSLHelpers do
1229
982
  host = FakeHost.create
1230
983
  allow(result).to receive(:exit_code).and_return(0)
1231
984
  allow(host).to receive(:any_exec_result).and_return(result)
1232
- allow(host).to receive(:graceful_restarts?).and_return(false)
1233
985
 
1234
986
  expect(Beaker::Command).to receive(:new).with(
1235
987
  /service not_real_service reload/,
@@ -1251,7 +1003,6 @@ describe ClassMixedWithDSLHelpers do
1251
1003
 
1252
1004
  it 'uses the default port argument if none given' do
1253
1005
  host = FakeHost.create
1254
- expect(host).to receive(:graceful_restarts?).and_return(false)
1255
1006
  allow(result).to receive(:exit_code).and_return(1)
1256
1007
  expect(subject).to receive(:curl_with_retries).with(
1257
1008
  anything, anything, /8140/, anything, anything
@@ -1261,7 +1012,6 @@ describe ClassMixedWithDSLHelpers do
1261
1012
 
1262
1013
  it 'takes the port argument' do
1263
1014
  host = FakeHost.create
1264
- expect(host).to receive(:graceful_restarts?).and_return(false)
1265
1015
  allow(result).to receive(:exit_code).and_return(1)
1266
1016
  expect(subject).to receive(:curl_with_retries).with(
1267
1017
  anything, anything, /8000/, anything, anything