@@ -161,10 +161,11 @@ func setReconcileNormalExpectations(ctrl *gomock.Controller,
161161}
162162
163163type reconcileDeleteTestCase struct {
164- ExpectError bool
165- ExpectRequeue bool
166- DeleteFails bool
167- DeleteRequeue bool
164+ ExpectError bool
165+ ExpectRequeue bool
166+ DeleteFails bool
167+ DissociateM3MetadataFails bool
168+ DeleteRequeue bool
168169}
169170
170171func setReconcileDeleteExpectations (ctrl * gomock.Controller ,
@@ -173,19 +174,28 @@ func setReconcileDeleteExpectations(ctrl *gomock.Controller,
173174 m := baremetal_mocks .NewMockMachineManagerInterface (ctrl )
174175 m .EXPECT ().SetConditionMetal3MachineToFalse (infrav1 .KubernetesNodeReadyCondition , infrav1 .DeletingReason , clusterv1 .ConditionSeverityInfo , "" )
175176
177+ if tc .DissociateM3MetadataFails {
178+ m .EXPECT ().DissociateM3Metadata (context .TODO ()).Return (errors .New ("failed" ))
179+ m .EXPECT ().SetConditionMetal3MachineToFalse (infrav1 .KubernetesNodeReadyCondition , infrav1 .DisassociateM3MetaDataFailedReason , clusterv1 .ConditionSeverityWarning , gomock .Any ())
180+ m .EXPECT ().Delete (context .TODO ()).MaxTimes (0 )
181+ m .EXPECT ().UnsetFinalizer ().MaxTimes (0 )
182+ return m
183+ }
176184 if tc .DeleteFails {
177- m .EXPECT ().SetConditionMetal3MachineToFalse ( infrav1 . KubernetesNodeReadyCondition , infrav1 . DeletionFailedReason , clusterv1 . ConditionSeverityWarning , gomock . Any ())
185+ m .EXPECT ().DissociateM3Metadata ( context . TODO ())
178186 m .EXPECT ().Delete (context .TODO ()).Return (errors .New ("failed" ))
187+ m .EXPECT ().SetConditionMetal3MachineToFalse (infrav1 .KubernetesNodeReadyCondition , infrav1 .DeletionFailedReason , clusterv1 .ConditionSeverityWarning , gomock .Any ())
179188 m .EXPECT ().UnsetFinalizer ().MaxTimes (0 )
180- m .EXPECT ().DissociateM3Metadata (context .TODO ()).MaxTimes (0 )
181189 return m
182- } else if tc .DeleteRequeue {
183- m .EXPECT ().SetConditionMetal3MachineToFalse (infrav1 .KubernetesNodeReadyCondition , infrav1 .DeletionFailedReason , clusterv1 .ConditionSeverityWarning , gomock .Any ())
190+ }
191+ if tc .DeleteRequeue {
192+ m .EXPECT ().DissociateM3Metadata (context .TODO ())
184193 m .EXPECT ().Delete (context .TODO ()).Return (baremetal .WithTransientError (errors .New ("failed" ), requeueAfter ))
194+ m .EXPECT ().SetConditionMetal3MachineToFalse (infrav1 .KubernetesNodeReadyCondition , infrav1 .DeletionFailedReason , clusterv1 .ConditionSeverityWarning , gomock .Any ())
185195 m .EXPECT ().UnsetFinalizer ().MaxTimes (0 )
186- m .EXPECT ().DissociateM3Metadata (context .TODO ()).MaxTimes (0 )
187196 return m
188197 }
198+
189199 m .EXPECT ().DissociateM3Metadata (context .TODO ())
190200 m .EXPECT ().Delete (context .TODO ()).Return (nil )
191201 m .EXPECT ().UnsetFinalizer ()
@@ -336,6 +346,12 @@ var _ = Describe("Metal3Machine manager", func() {
336346 ExpectRequeue : true ,
337347 DeleteRequeue : true ,
338348 }),
349+ Entry ("DissociateM3Metadata failure" , reconcileDeleteTestCase {
350+ ExpectError : true ,
351+ ExpectRequeue : false ,
352+ DeleteRequeue : false ,
353+ DissociateM3MetadataFails : true ,
354+ }),
339355 )
340356 })
341357
0 commit comments