Skip to content

Commit

Permalink
Add functional test to exercise catch all pending target pod timeout
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <davidvossel@gmail.com>
  • Loading branch information
davidvossel committed Nov 18, 2021
1 parent 5731bbc commit 7a99b5a
Showing 1 changed file with 79 additions and 2 deletions.
81 changes: 79 additions & 2 deletions tests/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:cnv-qe@redhat.com][leve
})
})

Context("with an unschedualbe target pod", func() {
Context("with an pending target pod", func() {
var nodes *k8sv1.NodeList
BeforeEach(func() {
tests.BeforeTestCleanup()
Expand All @@ -793,6 +793,7 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:cnv-qe@redhat.com][leve
// execute a migration that is expected to fail
By("Starting the Migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migration.Annotations = map[string]string{v1.MigrationUnschedulablePodTimeoutSecondsAnnotation: "130"}

By("Starting a Migration")
var err error
Expand All @@ -801,6 +802,82 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:cnv-qe@redhat.com][leve
return err
}, 5, 1*time.Second).Should(Succeed(), "migration creation should succeed")

By("Migration should observe a timeout period before canceling unschedulable target pod")
Consistently(func() error {

migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
if err != nil {
return err
}

if migration.Status.Phase == v1.MigrationFailed {
return fmt.Errorf("Migration should observe timeout period before transitioning to failed state")
}
return nil

}, 1*time.Minute, 10*time.Second).Should(Succeed())

By("Migration should fail eventually due to pending target pod timeout")
Eventually(func() error {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
if err != nil {
return err
}

if migration.Status.Phase != v1.MigrationFailed {
return fmt.Errorf("Waiting on migration with phase %s to reach phase Failed", migration.Status.Phase)
}
return nil
}, 2*time.Minute, 5*time.Second).Should(Succeed(), "migration creation should fail")

// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())

By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})

It("should automatically cancel pending target pod after a catch all timeout period", func() {
vmi := tests.NewRandomFedoraVMIWithGuestAgent()
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse(fedoraVMSize)

By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)

// execute a migration that is expected to fail
By("Starting the Migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migration.Annotations = map[string]string{v1.MigrationPendingPodTimeoutSecondsAnnotation: "130"}

// Add a fake continer image to the target pod to force a image pull failure which
// keeps the target pod in pending state
// Make sure to actually use an image repository we own here so no one
// can somehow figure out a way to execute custom logic in our func tests.
migration.Annotations[v1.FuncTestMigrationTargetImageOverrideAnnotation] = "quay.io/kubevirtci/some-fake-image:" + rand.String(12)

By("Starting a Migration")
var err error
Eventually(func() error {
migration, err = virtClient.VirtualMachineInstanceMigration(migration.Namespace).Create(migration)
return err
}, 5, 1*time.Second).Should(Succeed(), "migration creation should succeed")

By("Migration should observe a timeout period before canceling pending target pod")
Consistently(func() error {

migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
if err != nil {
return err
}

if migration.Status.Phase == v1.MigrationFailed {
return fmt.Errorf("Migration should observe timeout period before transitioning to failed state")
}
return nil

}, 1*time.Minute, 10*time.Second).Should(Succeed())

By("Migration should fail eventually due to pending target pod timeout")
Eventually(func() error {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
Expand All @@ -812,7 +889,7 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:cnv-qe@redhat.com][leve
return fmt.Errorf("Waiting on migration with phase %s to reach phase Failed", migration.Status.Phase)
}
return nil
}, 400, 1*time.Second).Should(Succeed(), "migration creation should fail")
}, 2*time.Minute, 5*time.Second).Should(Succeed(), "migration creation should fail")

// delete VMI
By("Deleting the VMI")
Expand Down

0 comments on commit 7a99b5a

Please sign in to comment.