Skip to content

Commit

Permalink
Unit test that verifies fix for null dereference in migration controller
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <davidvossel@gmail.com>
  • Loading branch information
davidvossel committed May 21, 2021
1 parent 875f61d commit 2d0896c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/virt-controller/watch/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,18 @@ var _ = Describe("Migration watcher", func() {
controller.Execute()
testutils.ExpectEvent(recorder, SuccessfulAbortMigrationReason)
})
table.DescribeTable("should finalize migration on VMI if target pod fails before migration starts", func(phase v1.VirtualMachineInstanceMigrationPhase, hasPod bool, podPhase k8sv1.PodPhase) {
table.DescribeTable("should finalize migration on VMI if target pod fails before migration starts", func(phase v1.VirtualMachineInstanceMigrationPhase, hasPod bool, podPhase k8sv1.PodPhase, initializeMigrationState bool) {
vmi := newVirtualMachine("testvmi", v1.Running)
vmi.Status.NodeName = "node02"
migration := newMigration("testmigration", vmi.Name, phase)

vmi.Status.MigrationState = &v1.VirtualMachineInstanceMigrationState{
MigrationUID: migration.UID,
TargetNode: "node01",
SourceNode: "node02",
vmi.Status.MigrationState = nil
if initializeMigrationState {
vmi.Status.MigrationState = &v1.VirtualMachineInstanceMigrationState{
MigrationUID: migration.UID,
TargetNode: "node01",
SourceNode: "node02",
}
}
addMigration(migration)
addVirtualMachineInstance(vmi)
Expand All @@ -794,15 +797,18 @@ var _ = Describe("Migration watcher", func() {
controller.Execute()

// in this case, we have two failed events. one for the VMI and one on the Migration object.
testutils.ExpectEvent(recorder, FailedMigrationReason)
if initializeMigrationState {
testutils.ExpectEvent(recorder, FailedMigrationReason)
}
if phase != v1.MigrationFailed {
testutils.ExpectEvent(recorder, FailedMigrationReason)
}
},
table.Entry("in preparing target state", v1.MigrationPreparingTarget, true, k8sv1.PodFailed),
table.Entry("in target ready state", v1.MigrationTargetReady, true, k8sv1.PodFailed),
table.Entry("in failed state", v1.MigrationFailed, true, k8sv1.PodFailed),
table.Entry("in failed state and pod does not exist", v1.MigrationFailed, false, k8sv1.PodFailed),
table.Entry("in preparing target state", v1.MigrationPreparingTarget, true, k8sv1.PodFailed, true),
table.Entry("in target ready state", v1.MigrationTargetReady, true, k8sv1.PodFailed, true),
table.Entry("in failed state", v1.MigrationFailed, true, k8sv1.PodFailed, true),
table.Entry("in failed state before pod is created", v1.MigrationFailed, false, k8sv1.PodFailed, false),
table.Entry("in failed state and pod does not exist", v1.MigrationFailed, false, k8sv1.PodFailed, false),
)
})
})
Expand Down

0 comments on commit 2d0896c

Please sign in to comment.