Skip to content

Commit

Permalink
Fix VMSnapshot + Manual RunStrategy
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Henriksen <[email protected]>
  • Loading branch information
mhenriks committed Jun 23, 2023
1 parent f73d6ce commit 8928c00
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ func checkVMRunning(vm *kubevirtv1.VirtualMachine) (bool, error) {
return false, err
}

return rs != kubevirtv1.RunStrategyHalted, nil
return rs == kubevirtv1.RunStrategyAlways || rs == kubevirtv1.RunStrategyRerunOnFailure, nil
}

func updateSnapshotCondition(ss *snapshotv1.VirtualMachineSnapshot, c snapshotv1.Condition) {
Expand Down
26 changes: 26 additions & 0 deletions pkg/storage/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,32 @@ var _ = Describe("Snapshot controlleer", func() {
controller.processVMSnapshotWorkItem()
})

It("should (partial) lock source manual runstrategy", func() {
vmSnapshot := createVMSnapshotInProgress()
vm := createVM()
vm.Spec.Running = nil
rs := v1.RunStrategyManual
vm.Spec.RunStrategy = &rs
vmUpdate := vm.DeepCopy()
vmUpdate.ResourceVersion = "1"
vmUpdate.Status.SnapshotInProgress = &vmSnapshotName

vmSource.Add(vm)
vmInterface.EXPECT().UpdateStatus(context.Background(), vmUpdate).Return(vmUpdate, nil).Times(1)

updatedSnapshot := vmSnapshot.DeepCopy()
updatedSnapshot.ResourceVersion = "1"
updatedSnapshot.Status.Conditions = []snapshotv1.Condition{
newProgressingCondition(corev1.ConditionFalse, "Source not locked"),
newReadyCondition(corev1.ConditionFalse, "Not ready"),
}
updatedSnapshot.Status.Indications = []snapshotv1.Indication{}
expectVMSnapshotUpdate(vmSnapshotClient, updatedSnapshot)

addVirtualMachineSnapshot(vmSnapshot)
controller.processVMSnapshotWorkItem()
})

It("should (finish) lock source", func() {
vmSnapshot := createVMSnapshotInProgress()
vm := createVM()
Expand Down
12 changes: 11 additions & 1 deletion tests/storage/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var _ = SIGDescribe("VirtualMachineSnapshot Tests", func() {
Expect(*snapshot.Status.SourceUID).To(Equal(vm.UID))

contentName := *snapshot.Status.VirtualMachineSnapshotContentName
if *vm.Spec.Running {
if vm.Spec.Running != nil && *vm.Spec.Running {
expectedIndications := []snapshotv1.Indication{snapshotv1.VMSnapshotOnlineSnapshotIndication, snapshotv1.VMSnapshotNoGuestAgentIndication}
Expect(snapshot.Status.Indications).To(Equal(expectedIndications))
checkOnlineSnapshotExpectedContentSource(vm, contentName, false)
Expand Down Expand Up @@ -275,6 +275,16 @@ var _ = SIGDescribe("VirtualMachineSnapshot Tests", func() {
createAndVerifyVMSnapshot(vm)
})

It("should create a snapshot when VM runStrategy is Manual", func() {
patch := []byte("[{ \"op\": \"remove\", \"path\": \"/spec/running\"}, { \"op\": \"add\", \"path\": \"/spec/runStrategy\", \"value\": \"Manual\"}]")
vm, err = virtClient.VirtualMachine(vm.Namespace).Patch(context.Background(), vm.Name, types.JSONPatchType, patch, &metav1.PatchOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(vm.Spec.RunStrategy).ToNot(BeNil())
Expect(*vm.Spec.RunStrategy).Should(Equal(v1.RunStrategyManual))

createAndVerifyVMSnapshot(vm)
})

It("VM should contain snapshot status for all volumes", func() {
patch := []byte("[{ \"op\": \"replace\", \"path\": \"/spec/running\", \"value\": true }]")
vm, err := virtClient.VirtualMachine(vm.Namespace).Patch(context.Background(), vm.Name, types.JSONPatchType, patch, &metav1.PatchOptions{})
Expand Down

0 comments on commit 8928c00

Please sign in to comment.