20
20
defaultBmHostSecretName = "testsecret"
21
21
defaultBmHostMacAddress = "AA:BB:CC:11:22:33"
22
22
defaultBmHostBootMode = "UEFISecureBoot"
23
+ defaultBmHostAnnotation = "annotation.openshift.io/test-annotation"
23
24
testSchemes = []clients.SchemeAttacher {
24
25
bmhv1alpha1 .AddToScheme ,
25
26
}
@@ -966,6 +967,86 @@ func TestBareMetalHostDeleteAndWaitUntilDeleted(t *testing.T) {
966
967
}
967
968
}
968
969
970
+ func TestBareMetalHostWaitUntilAnnotationExists (t * testing.T ) {
971
+ testCases := []struct {
972
+ annotation string
973
+ exists bool
974
+ valid bool
975
+ annotated bool
976
+ expectedError error
977
+ }{
978
+ {
979
+ annotation : defaultBmHostAnnotation ,
980
+ exists : true ,
981
+ valid : true ,
982
+ annotated : true ,
983
+ expectedError : nil ,
984
+ },
985
+ {
986
+ annotation : "" ,
987
+ exists : true ,
988
+ valid : true ,
989
+ annotated : true ,
990
+ expectedError : fmt .Errorf ("bmh annotation key cannot be empty" ),
991
+ },
992
+ {
993
+ annotation : defaultBmHostAnnotation ,
994
+ exists : false ,
995
+ valid : true ,
996
+ annotated : true ,
997
+ expectedError : fmt .Errorf (
998
+ "baremetalhost object %s does not exist in namespace %s" , defaultBmHostName , defaultBmHostNsName ),
999
+ },
1000
+ {
1001
+ annotation : defaultBmHostAnnotation ,
1002
+ exists : true ,
1003
+ valid : false ,
1004
+ annotated : true ,
1005
+ expectedError : fmt .Errorf ("not acceptable 'bootMode' value" ),
1006
+ },
1007
+ {
1008
+ annotation : defaultBmHostAnnotation ,
1009
+ exists : true ,
1010
+ valid : true ,
1011
+ annotated : false ,
1012
+ expectedError : context .DeadlineExceeded ,
1013
+ },
1014
+ }
1015
+
1016
+ for _ , testCase := range testCases {
1017
+ var (
1018
+ runtimeObjects []runtime.Object
1019
+ builder * BmhBuilder
1020
+ )
1021
+
1022
+ if testCase .exists {
1023
+ bmh := buildDummyBmHost (bmhv1alpha1 .StateProvisioned , bmhv1alpha1 .OperationalStatusOK )
1024
+
1025
+ if testCase .annotated {
1026
+ bmh .Annotations = map [string ]string {
1027
+ defaultBmHostAnnotation : "" ,
1028
+ }
1029
+ }
1030
+
1031
+ runtimeObjects = append (runtimeObjects , bmh )
1032
+ }
1033
+
1034
+ testSettings := clients .GetTestClients (clients.TestClientParams {
1035
+ K8sMockObjects : runtimeObjects ,
1036
+ SchemeAttachers : testSchemes ,
1037
+ })
1038
+
1039
+ if testCase .valid {
1040
+ builder = buildValidBmHostBuilder (testSettings )
1041
+ } else {
1042
+ builder = buildInValidBmHostBuilder (testSettings )
1043
+ }
1044
+
1045
+ _ , err := builder .WaitUntilAnnotationExists (testCase .annotation , time .Second )
1046
+ assert .Equal (t , testCase .expectedError , err )
1047
+ }
1048
+ }
1049
+
969
1050
func TestBareMetalHostWaitUntilDeleted (t * testing.T ) {
970
1051
testCases := []struct {
971
1052
testBmHost * BmhBuilder
@@ -1026,19 +1107,14 @@ func buildBareMetalHostTestClientWithDummyObject(state ...bmhv1alpha1.Provisioni
1026
1107
}
1027
1108
1028
1109
return clients .GetTestClients (clients.TestClientParams {
1029
- K8sMockObjects : buildDummyBmHost (provisionState ),
1110
+ K8sMockObjects : buildDummyBmHostObject (provisionState ),
1030
1111
SchemeAttachers : testSchemes ,
1031
1112
})
1032
1113
}
1033
1114
1034
1115
func buildDummyBmHost (
1035
- state bmhv1alpha1.ProvisioningState , operationalStatus ... bmhv1alpha1.OperationalStatus ) []runtime.Object {
1036
- operState := bmhv1alpha1 .OperationalStatusOK
1037
- if len (operationalStatus ) > 0 {
1038
- operState = operationalStatus [0 ]
1039
- }
1040
-
1041
- return append ([]runtime.Object {}, & bmhv1alpha1.BareMetalHost {
1116
+ state bmhv1alpha1.ProvisioningState , operState bmhv1alpha1.OperationalStatus ) * bmhv1alpha1.BareMetalHost {
1117
+ return & bmhv1alpha1.BareMetalHost {
1042
1118
Spec : bmhv1alpha1.BareMetalHostSpec {
1043
1119
BMC : bmhv1alpha1.BMCDetails {
1044
1120
Address : defaultBmHostAddress ,
@@ -1061,5 +1137,15 @@ func buildDummyBmHost(
1061
1137
State : state ,
1062
1138
},
1063
1139
},
1064
- })
1140
+ }
1141
+ }
1142
+
1143
+ func buildDummyBmHostObject (
1144
+ state bmhv1alpha1.ProvisioningState , operationalStatus ... bmhv1alpha1.OperationalStatus ) []runtime.Object {
1145
+ operState := bmhv1alpha1 .OperationalStatusOK
1146
+ if len (operationalStatus ) > 0 {
1147
+ operState = operationalStatus [0 ]
1148
+ }
1149
+
1150
+ return append ([]runtime.Object {}, buildDummyBmHost (state , operState ))
1065
1151
}
0 commit comments