Skip to content

Commit

Permalink
cdi-1.4.1: implement check to ensure datavolume has succeeded and rem…
Browse files Browse the repository at this point in the history
…oved redundant check for stopped VMI.
  • Loading branch information
dylanzr committed Dec 26, 2018
1 parent 37b8770 commit c3968ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ var _ = Describe("DataVolume Integration", func() {
obj, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
return err
}, timeout, 1*time.Second).ShouldNot(HaveOccurred())

By("Checking that the DataVolume has succeeded")
tests.WaitForSuccessfulDataVolumeImport(obj, timeout)

By("Waiting until the VirtualMachineInstance will start")
tests.WaitForSuccessfulVMIStartWithTimeout(obj, timeout)
return obj
Expand Down
20 changes: 19 additions & 1 deletion tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ func NewRandomDataVolumeWithHttpImport(imageUrl string, namespace string) *cdiv1
APIVersion: "cdi.kubevirt.io/v1alpha1",
Kind: "DataVolume",
}

return dataVolume
}

Expand Down Expand Up @@ -1731,6 +1732,24 @@ func NewRandomVMIWithCustomMacAddress() *v1.VirtualMachineInstance {
return vmi
}

// Block until DataVolume succeeds.
func WaitForSuccessfulDataVolumeImport(obj runtime.Object, seconds int) {
vmi, ok := obj.(*v1.VirtualMachineInstance)
ExpectWithOffset(1, ok).To(BeTrue(), "Object is not of type *v1.VMI")

virtClient, err := kubecli.GetKubevirtClient()
ExpectWithOffset(1, err).ToNot(HaveOccurred())

EventuallyWithOffset(1, func() cdiv1.DataVolumePhase {
dv, err := virtClient.CdiClient().CdiV1alpha1().DataVolumes(vmi.Namespace).Get(vmi.Spec.Volumes[0].DataVolume.Name, metav1.GetOptions{})
ExpectWithOffset(1, err).ToNot(HaveOccurred())

return dv.Status.Phase
}, time.Duration(seconds)*time.Second, 1*time.Second).Should(Equal(cdiv1.Succeeded), "Timed out waiting for DataVolume to enter Succeeded phase")

return
}

// Block until the specified VirtualMachineInstance started and return the target node name.
func waitForVMIStart(obj runtime.Object, seconds int, ignoreWarnings bool) (nodeName string) {
vmi, ok := obj.(*v1.VirtualMachineInstance)
Expand Down Expand Up @@ -1766,7 +1785,6 @@ func waitForVMIStart(obj runtime.Object, seconds int, ignoreWarnings bool) (node
ExpectWithOffset(1, err).ToNot(HaveOccurred())

nodeName = vmi.Status.NodeName
Expect(vmi.IsFinal()).To(BeFalse(), "VMI unexpectedly stopped. State: %s", vmi.Status.Phase)
return vmi.Status.Phase
}, time.Duration(seconds)*time.Second, 1*time.Second).Should(Equal(v1.Running), "Timed out waiting for VMI to enter Running phase")

Expand Down

0 comments on commit c3968ed

Please sign in to comment.