@@ -162,7 +162,7 @@ var _ = Describe("VirtualMachineAffinityAndToleration", Ordered, func() {
162162 Expect (err ).NotTo (HaveOccurred ())
163163
164164 waitForFreshVMMigration (ctx , f , crclient .ObjectKeyFromObject (vmC ), startedAt , sourceNode , nodeA , false , framework .MaxTimeout )
165- util . UntilConditionStatus ( vmcondition . TypeMigrating . String (), string ( metav1 . ConditionFalse ), framework .LongTimeout , vmC )
165+ waitForVMMigrationFinished ( ctx , f , crclient . ObjectKeyFromObject ( vmC ), framework .LongTimeout )
166166 })
167167
168168 var migratedNodeC string
@@ -183,7 +183,7 @@ var _ = Describe("VirtualMachineAffinityAndToleration", Ordered, func() {
183183 Expect (err ).NotTo (HaveOccurred ())
184184
185185 waitForFreshVMMigration (ctx , f , crclient .ObjectKeyFromObject (vmC ), startedAt , migratedNodeC , nodeA , true , framework .MaxTimeout )
186- util . UntilConditionStatus ( vmcondition . TypeMigrating . String (), string ( metav1 . ConditionFalse ), framework .LongTimeout , vmC )
186+ waitForVMMigrationFinished ( ctx , f , crclient . ObjectKeyFromObject ( vmC ), framework .LongTimeout )
187187 })
188188
189189 By ("Verifying vm-c returned to vm-a node via status.nodeName" , func () {
@@ -243,7 +243,7 @@ var _ = Describe("VirtualMachineAffinityAndToleration", Ordered, func() {
243243 Expect (err ).NotTo (HaveOccurred ())
244244
245245 waitForFreshVMMigration (ctx , f , crclient .ObjectKeyFromObject (vmNodeSelector ), startedAt , sourceNode , targetNode , true , framework .MaxTimeout )
246- util . UntilConditionStatus ( vmcondition . TypeMigrating . String (), string ( metav1 . ConditionFalse ), framework .LongTimeout , vmNodeSelector )
246+ waitForVMMigrationFinished ( ctx , f , crclient . ObjectKeyFromObject ( vmNodeSelector ), framework .LongTimeout )
247247 })
248248
249249 By ("Verifying the nodeSelector migration result via status.nodeName" , func () {
@@ -306,7 +306,7 @@ var _ = Describe("VirtualMachineAffinityAndToleration", Ordered, func() {
306306 Expect (err ).NotTo (HaveOccurred ())
307307
308308 waitForFreshVMMigration (ctx , f , crclient .ObjectKeyFromObject (vmNodeAffinity ), startedAt , sourceNode , targetNode , true , framework .MaxTimeout )
309- util . UntilConditionStatus ( vmcondition . TypeMigrating . String (), string ( metav1 . ConditionFalse ), framework .LongTimeout , vmNodeAffinity )
309+ waitForVMMigrationFinished ( ctx , f , crclient . ObjectKeyFromObject ( vmNodeAffinity ), framework .LongTimeout )
310310 })
311311
312312 By ("Verifying the nodeAffinity migration result via status.nodeName" , func () {
@@ -451,6 +451,29 @@ func migrationFailureDetails(vm *v1alpha2.VirtualMachine) string {
451451 return fmt .Sprintf ("result=%s source=%s target=%s current=%s" , vm .Status .MigrationState .Result , vm .Status .MigrationState .Source .Node , vm .Status .MigrationState .Target .Node , vm .Status .Node )
452452}
453453
454+ func waitForVMMigrationFinished (
455+ ctx context.Context ,
456+ f * framework.Framework ,
457+ key crclient.ObjectKey ,
458+ timeout time.Duration ,
459+ ) {
460+ GinkgoHelper ()
461+
462+ Eventually (func (g Gomega ) {
463+ vm := getVirtualMachine (ctx , f , key .Name )
464+ state := vm .Status .MigrationState
465+ g .Expect (state ).NotTo (BeNil ())
466+ g .Expect (state .EndTimestamp .IsZero ()).To (BeFalse (), "migration is not completed" )
467+
468+ for _ , condition := range vm .Status .Conditions {
469+ if condition .Type == vmcondition .TypeMigrating .String () {
470+ g .Expect (condition .Status ).To (Equal (metav1 .ConditionFalse ))
471+ return
472+ }
473+ }
474+ }).WithTimeout (timeout ).WithPolling (time .Second ).Should (Succeed ())
475+ }
476+
454477func assertNoVMMigration (
455478 ctx context.Context ,
456479 f * framework.Framework ,
0 commit comments