Add unit tests for migration abortion
@@ -235,6 +235,24 @@ var _ = Describe("Migration watcher", func() {
vmiInterface.EXPECT().Patch(vmi.Name, types.JSONPatchType, []byte(patch), &metav1.PatchOptions{}).Return(vmi, nil)
}
+ shouldExpectMigrationCondition := func(migration *virtv1.VirtualMachineInstanceMigration, conditionType virtv1.VirtualMachineInstanceMigrationConditionType) {
+ migrationInterface.EXPECT().UpdateStatus(gomock.Any()).Do(func(arg interface{}) (interface{}, interface{}) {
+ vmim := arg.(*virtv1.VirtualMachineInstanceMigration)
+ ExpectWithOffset(1, vmim.Name).To(Equal(migration.Name))
+
+ foundConditionType := false
+ for _, cond := range vmim.Status.Conditions {
+ if cond.Type == conditionType {
+ foundConditionType = true
+ break
+ }
+ }
+ ExpectWithOffset(1, foundConditionType).To(BeTrue(), fmt.Sprintf("condition of type %s is expected but cannot be found in migration %s", string(conditionType), migration.Name))
+
+ return arg, nil
+ })
+ }
+
syncCaches := func(stop chan struct{}) {
go vmiInformer.Run(stop)
go podInformer.Run(stop)
@@ -1756,6 +1774,35 @@ var _ = Describe("Migration watcher", func() {
expectCounterValue(migrations.MigrationsFailedTotal, labels, failed+1)
})
})
+
+ Context("Migration abortion before hand-off to virt-handler", func() {
+
+ var vmi *virtv1.VirtualMachineInstance
+ var migration *virtv1.VirtualMachineInstanceMigration
+
+ BeforeEach(func() {
+ vmi = newVirtualMachine("testvmi", virtv1.Running)
+ migration = newMigration("testmigration", vmi.Name, virtv1.MigrationPending)
+ migration.DeletionTimestamp = now()
+
+ Expect(controller.isMigrationHandedOff(migration, vmi)).To(BeFalse(), "this test assumes migration was not handed off yet")
+ addMigration(migration)
+ addVirtualMachineInstance(vmi)
+ })
+
+ AfterEach(func() {
+ controller.Execute()
+ testutils.ExpectEvent(recorder, FailedMigrationReason)
+ })
+
+ It("expect abort condition", func() {
+ shouldExpectMigrationCondition(migration, virtv1.VirtualMachineInstanceMigrationAbortRequested)
+ })
+
+ It("expect failure phase", func() {
+ shouldExpectMigrationFailedState(migration)
+ })
+ })
})
func newPDB(name string, vmi *virtv1.VirtualMachineInstance, pods int) *policyv1.PodDisruptionBudget {
