@@ -725,15 +725,74 @@ var _ = Describe("analyzeSSHOutputInstallImage", func() {
725
725
expectedErrMessage string
726
726
}
727
727
728
- type testCaseAnalyzeSSHOutputRegistering struct {
728
+ DescribeTable ("analyzeSSHOutputInstallImage - out.Err" ,
729
+ func (tc testCaseAnalyzeSSHOutputInstallImageOutErr ) {
730
+ host := helpers .BareMetalHost (
731
+ "test-host" ,
732
+ "default" ,
733
+ )
734
+
735
+ robotMock := robotmock.Client {}
736
+ robotMock .On ("GetBootRescue" , mock .Anything ).Return (& models.Rescue {Active : tc .rescueActive }, nil )
737
+
738
+ service := newTestService (host , & robotMock , nil , nil , nil )
739
+
740
+ isTimeout , isConnectionRefused , err := service .analyzeSSHOutputRegistering (sshclient.Output {Err : tc .err })
741
+ Expect (isTimeout ).To (Equal (tc .expectedIsTimeout ))
742
+ Expect (isConnectionRefused ).To (Equal (tc .expectedIsConnectionRefused ))
743
+ if tc .expectedErrMessage != "" {
744
+ Expect (err ).To (Not (BeNil ()))
745
+ Expect (err .Error ()).To (ContainSubstring (tc .expectedErrMessage ))
746
+ } else {
747
+ Expect (err ).To (BeNil ())
748
+ }
749
+ },
750
+ Entry ("timeout error" , testCaseAnalyzeSSHOutputInstallImageOutErr {
751
+ err : timeout ,
752
+ rescueActive : true ,
753
+ expectedIsTimeout : true ,
754
+ expectedIsConnectionRefused : false ,
755
+ expectedErrMessage : "" ,
756
+ }),
757
+ Entry ("authenticationFailed error, rescue active" , testCaseAnalyzeSSHOutputInstallImageOutErr {
758
+ err : sshclient .ErrAuthenticationFailed ,
759
+ rescueActive : true ,
760
+ expectedIsTimeout : false ,
761
+ expectedIsConnectionRefused : false ,
762
+ expectedErrMessage : "" ,
763
+ }),
764
+ Entry ("authenticationFailed error, rescue not active" , testCaseAnalyzeSSHOutputInstallImageOutErr {
765
+ err : sshclient .ErrAuthenticationFailed ,
766
+ rescueActive : false ,
767
+ expectedIsTimeout : false ,
768
+ expectedIsConnectionRefused : false ,
769
+ expectedErrMessage : "wrong ssh key" ,
770
+ }),
771
+ Entry ("connectionRefused error, rescue active" , testCaseAnalyzeSSHOutputInstallImageOutErr {
772
+ err : sshclient .ErrConnectionRefused ,
773
+ rescueActive : true ,
774
+ expectedIsTimeout : false ,
775
+ expectedIsConnectionRefused : true ,
776
+ expectedErrMessage : "" ,
777
+ }),
778
+ Entry ("connectionRefused error, rescue not active" , testCaseAnalyzeSSHOutputInstallImageOutErr {
779
+ err : sshclient .ErrConnectionRefused ,
780
+ rescueActive : false ,
781
+ expectedIsTimeout : false ,
782
+ expectedIsConnectionRefused : true ,
783
+ expectedErrMessage : "" ,
784
+ }),
785
+ )
786
+
787
+ type testCaseAnalyzeSSHOutputInstallImageStdErr struct {
729
788
hasNilErr bool
730
789
stdErr string
731
790
hostName string
732
791
expectedErrMessage string
733
792
}
734
793
735
794
DescribeTable ("analyzeSSHOutputRegistering - toggle stdErr and hostName" ,
736
- func (tc testCaseAnalyzeSSHOutputRegistering ) {
795
+ func (tc testCaseAnalyzeSSHOutputInstallImageStdErr ) {
737
796
var err error
738
797
if ! tc .hasNilErr {
739
798
err = errTest
@@ -765,25 +824,25 @@ var _ = Describe("analyzeSSHOutputInstallImage", func() {
765
824
Expect (err ).To (BeNil ())
766
825
}
767
826
},
768
- Entry ("stderr not empty" , testCaseAnalyzeSSHOutputRegistering {
827
+ Entry ("stderr not empty" , testCaseAnalyzeSSHOutputInstallImageStdErr {
769
828
hasNilErr : true ,
770
829
stdErr : "command failed" ,
771
830
hostName : "hostName" ,
772
831
expectedErrMessage : "failed to get hostname via ssh: StdErr:" ,
773
832
}),
774
- Entry ("stderr not empty - err != nil" , testCaseAnalyzeSSHOutputRegistering {
833
+ Entry ("stderr not empty - err != nil" , testCaseAnalyzeSSHOutputInstallImageStdErr {
775
834
hasNilErr : false ,
776
835
stdErr : "command failed" ,
777
836
hostName : "" ,
778
837
expectedErrMessage : "unhandled ssh error while getting hostname" ,
779
838
}),
780
- Entry ("stderr not empty - wrong hostName" , testCaseAnalyzeSSHOutputRegistering {
839
+ Entry ("stderr not empty - wrong hostName" , testCaseAnalyzeSSHOutputInstallImageStdErr {
781
840
hasNilErr : true ,
782
841
stdErr : "command failed" ,
783
842
hostName : "" ,
784
843
expectedErrMessage : "failed to get hostname via ssh: StdErr:" ,
785
844
}),
786
- Entry ("stderr empty - wrong hostName" , testCaseAnalyzeSSHOutputRegistering {
845
+ Entry ("stderr empty - wrong hostName" , testCaseAnalyzeSSHOutputInstallImageStdErr {
787
846
hasNilErr : true ,
788
847
stdErr : "" ,
789
848
hostName : "" ,
@@ -802,19 +861,196 @@ var _ = Describe("analyzeSSHOutputInstallImage", func() {
802
861
expectedErrMessage string
803
862
}
804
863
864
+ DescribeTable ("analyzeSSHOutputInstallImage - out.Err" ,
865
+ func (tc testCaseAnalyzeSSHOutputInstallImageOutErr ) {
866
+ sshMock := & sshmock.Client {}
867
+ var errFromGetHostName error
868
+ if ! tc .errFromGetHostNameNil {
869
+ errFromGetHostName = errTest
870
+ }
871
+ sshMock .On ("GetHostName" ).Return (sshclient.Output {Err : errFromGetHostName })
872
+
873
+ isTimeout , isConnectionRefused , err := analyzeSSHOutputInstallImage (sshclient.Output {Err : tc .err }, sshMock , tc .port )
874
+ Expect (isTimeout ).To (Equal (tc .expectedIsTimeout ))
875
+ Expect (isConnectionRefused ).To (Equal (tc .expectedIsConnectionRefused ))
876
+ if tc .expectedErrMessage != "" {
877
+ Expect (err ).To (Not (BeNil ()))
878
+ Expect (err .Error ()).To (ContainSubstring (tc .expectedErrMessage ))
879
+ } else {
880
+ Expect (err ).To (BeNil ())
881
+ }
882
+ },
883
+ Entry ("timeout error" , testCaseAnalyzeSSHOutputInstallImageOutErr {
884
+ err : timeout ,
885
+ errFromGetHostNameNil : true ,
886
+ port : 22 ,
887
+ expectedIsTimeout : true ,
888
+ expectedIsConnectionRefused : false ,
889
+ expectedErrMessage : "" ,
890
+ }),
891
+ Entry ("authenticationFailed error, port 22, no hostName error" , testCaseAnalyzeSSHOutputInstallImageOutErr {
892
+ err : sshclient .ErrAuthenticationFailed ,
893
+ errFromGetHostNameNil : true ,
894
+ port : 22 ,
895
+ expectedIsTimeout : false ,
896
+ expectedIsConnectionRefused : false ,
897
+ expectedErrMessage : "" ,
898
+ }),
899
+ Entry ("authenticationFailed error, port 22, hostName error" , testCaseAnalyzeSSHOutputInstallImageOutErr {
900
+ err : sshclient .ErrAuthenticationFailed ,
901
+ errFromGetHostNameNil : false ,
902
+ port : 22 ,
903
+ expectedIsTimeout : false ,
904
+ expectedIsConnectionRefused : false ,
905
+ expectedErrMessage : "wrong ssh key" ,
906
+ }),
907
+ Entry ("authenticationFailed error, port != 22" , testCaseAnalyzeSSHOutputInstallImageOutErr {
908
+ err : sshclient .ErrAuthenticationFailed ,
909
+ errFromGetHostNameNil : true ,
910
+ port : 23 ,
911
+ expectedIsTimeout : false ,
912
+ expectedIsConnectionRefused : false ,
913
+ expectedErrMessage : "wrong ssh key" ,
914
+ }),
915
+ Entry ("connectionRefused error, port 22" , testCaseAnalyzeSSHOutputInstallImageOutErr {
916
+ err : sshclient .ErrConnectionRefused ,
917
+ errFromGetHostNameNil : true ,
918
+ port : 22 ,
919
+ expectedIsTimeout : false ,
920
+ expectedIsConnectionRefused : true ,
921
+ expectedErrMessage : "" ,
922
+ }),
923
+ Entry ("connectionRefused error, port != 22, hostname error" , testCaseAnalyzeSSHOutputInstallImageOutErr {
924
+ err : sshclient .ErrConnectionRefused ,
925
+ errFromGetHostNameNil : false ,
926
+ port : 23 ,
927
+ expectedIsTimeout : false ,
928
+ expectedIsConnectionRefused : true ,
929
+ expectedErrMessage : "" ,
930
+ }),
931
+ Entry ("connectionRefused error, port != 22, no hostname error" , testCaseAnalyzeSSHOutputInstallImageOutErr {
932
+ err : sshclient .ErrConnectionRefused ,
933
+ errFromGetHostNameNil : true ,
934
+ port : 23 ,
935
+ expectedIsTimeout : false ,
936
+ expectedIsConnectionRefused : false ,
937
+ expectedErrMessage : "" ,
938
+ }),
939
+ )
940
+
805
941
type testCaseAnalyzeSSHOutputInstallImageStdErr struct {
806
942
hasNilErr bool
807
943
stdErr string
808
944
hasWrongHostName bool
809
945
expectedErrMessage string
810
946
}
811
947
948
+ DescribeTable ("analyzeSSHOutputInstallImage - StdErr not empty" ,
949
+ func (tc testCaseAnalyzeSSHOutputInstallImageStdErr ) {
950
+ var err error
951
+ if ! tc .hasNilErr {
952
+ err = errTest
953
+ }
954
+ hostName := "rescue"
955
+ if tc .hasWrongHostName {
956
+ hostName = "wrongHostName"
957
+ }
958
+
959
+ out := sshclient.Output {
960
+ StdOut : hostName ,
961
+ StdErr : tc .stdErr ,
962
+ Err : err ,
963
+ }
964
+ isTimeout , isConnectionRefused , err := analyzeSSHOutputInstallImage (out , nil , 22 )
965
+ Expect (isTimeout ).To (Equal (false ))
966
+ Expect (isConnectionRefused ).To (Equal (false ))
967
+ if tc .expectedErrMessage != "" {
968
+ Expect (err ).To (Not (BeNil ()))
969
+ Expect (err .Error ()).To (ContainSubstring (tc .expectedErrMessage ))
970
+ } else {
971
+ Expect (err ).To (BeNil ())
972
+ }
973
+ },
974
+ Entry ("stderr not empty" , testCaseAnalyzeSSHOutputInstallImageStdErr {
975
+ hasNilErr : true ,
976
+ stdErr : "command failed" ,
977
+ hasWrongHostName : false ,
978
+ expectedErrMessage : "failed to get hostname via ssh: StdErr:" ,
979
+ }),
980
+ Entry ("stderr not empty - err != nil" , testCaseAnalyzeSSHOutputInstallImageStdErr {
981
+ hasNilErr : false ,
982
+ stdErr : "command failed" ,
983
+ hasWrongHostName : false ,
984
+ expectedErrMessage : "unhandled ssh error while getting hostname" ,
985
+ }),
986
+ Entry ("stderr not empty - wrong hostName" , testCaseAnalyzeSSHOutputInstallImageStdErr {
987
+ hasNilErr : true ,
988
+ stdErr : "command failed" ,
989
+ hasWrongHostName : true ,
990
+ expectedErrMessage : "failed to get hostname via ssh: StdErr:" ,
991
+ }),
992
+ )
993
+
812
994
type testCaseAnalyzeSSHOutputInstallImageWrongHostname struct {
813
995
hasNilErr bool
814
996
stdErr string
815
997
hostName string
816
998
expectedErrMessage string
817
999
}
1000
+
1001
+ DescribeTable ("analyzeSSHOutputInstallImage - wrong hostName" ,
1002
+ func (tc testCaseAnalyzeSSHOutputInstallImageWrongHostname ) {
1003
+ var err error
1004
+ if ! tc .hasNilErr {
1005
+ err = errTest
1006
+ }
1007
+
1008
+ out := sshclient.Output {
1009
+ StdOut : tc .hostName ,
1010
+ StdErr : tc .stdErr ,
1011
+ Err : err ,
1012
+ }
1013
+ isTimeout , isConnectionRefused , err := analyzeSSHOutputInstallImage (out , nil , 22 )
1014
+ Expect (isTimeout ).To (Equal (false ))
1015
+ Expect (isConnectionRefused ).To (Equal (false ))
1016
+ if tc .expectedErrMessage != "" {
1017
+ Expect (err ).To (Not (BeNil ()))
1018
+ Expect (err .Error ()).To (ContainSubstring (tc .expectedErrMessage ))
1019
+ } else {
1020
+ Expect (err ).To (BeNil ())
1021
+ }
1022
+ },
1023
+ Entry ("empty hostname" , testCaseAnalyzeSSHOutputInstallImageWrongHostname {
1024
+ hasNilErr : true ,
1025
+ stdErr : "" ,
1026
+ hostName : "" ,
1027
+ expectedErrMessage : "hostname is empty" ,
1028
+ }),
1029
+ Entry ("empty hostname - err not empty" , testCaseAnalyzeSSHOutputInstallImageWrongHostname {
1030
+ hasNilErr : false ,
1031
+ stdErr : "" ,
1032
+ hostName : "" ,
1033
+ expectedErrMessage : "unhandled ssh error while getting hostname" ,
1034
+ }),
1035
+ Entry ("empty hostname stderr not empty" , testCaseAnalyzeSSHOutputInstallImageWrongHostname {
1036
+ hasNilErr : true ,
1037
+ stdErr : "command failed" ,
1038
+ hostName : "" ,
1039
+ expectedErrMessage : "failed to get hostname via ssh: StdErr:" ,
1040
+ }),
1041
+ Entry ("hostname == rescue" , testCaseAnalyzeSSHOutputInstallImageWrongHostname {
1042
+ hasNilErr : true ,
1043
+ stdErr : "" ,
1044
+ hostName : "rescue" ,
1045
+ expectedErrMessage : "" ,
1046
+ }),
1047
+ Entry ("hostname == otherHostName" , testCaseAnalyzeSSHOutputInstallImageWrongHostname {
1048
+ hasNilErr : true ,
1049
+ stdErr : "" ,
1050
+ hostName : "otherHostName" ,
1051
+ expectedErrMessage : "unexpected hostname" ,
1052
+ }),
1053
+ )
818
1054
})
819
1055
820
1056
var _ = Describe ("analyzeSSHOutputProvisioned" , func () {
0 commit comments