Unit test covering case of missing DataVolume annotation
@@ -280,6 +280,60 @@ var _ = Describe("VirtualMachine", func() {
testutils.ExpectEvent(recorder, FailedDataVolumeImportReason)
})
+ It("should handle failed DataVolume without Annotations", func() {
+ vm, _ := DefaultVirtualMachine(true)
+ vm.Spec.Template.Spec.Volumes = append(vm.Spec.Template.Spec.Volumes, v1.Volume{
+ Name: "test1",
+ VolumeSource: v1.VolumeSource{
+ DataVolume: &v1.DataVolumeSource{
+ Name: "dv1",
+ },
+ },
+ })
+ vm.Spec.Template.Spec.Volumes = append(vm.Spec.Template.Spec.Volumes, v1.Volume{
+ Name: "test1",
+ VolumeSource: v1.VolumeSource{
+ DataVolume: &v1.DataVolumeSource{
+ Name: "dv2",
+ },
+ },
+ })
+
+ vm.Spec.DataVolumeTemplates = append(vm.Spec.DataVolumeTemplates, cdiv1.DataVolume{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "dv1",
+ },
+ })
+ vm.Spec.DataVolumeTemplates = append(vm.Spec.DataVolumeTemplates, cdiv1.DataVolume{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "dv2",
+ },
+ })
+ addVirtualMachine(vm)
+
+ existingDataVolume1 := createDataVolumeManifest(&vm.Spec.DataVolumeTemplates[0], vm)
+ existingDataVolume1.Namespace = "default"
+ existingDataVolume1.Status.Phase = cdiv1.Failed
+ // explicitly delete the annotations field
+ existingDataVolume1.Annotations = nil
+
+ existingDataVolume2 := createDataVolumeManifest(&vm.Spec.DataVolumeTemplates[1], vm)
+ existingDataVolume2.Namespace = "default"
+ existingDataVolume2.Status.Phase = cdiv1.Succeeded
+ existingDataVolume2.Annotations = nil
+
+ dataVolumeFeeder.Add(existingDataVolume1)
+ dataVolumeFeeder.Add(existingDataVolume2)
+
+ shouldExpectDataVolumeUpdate(vm.UID, existingDataVolume1.Name)
+
+ vmInterface.EXPECT().Update(gomock.Any()).Times(1).Return(vm, nil)
+
+ controller.Execute()
+
+ testutils.ExpectEvent(recorder, FailedDataVolumeImportReason)
+ })
+
It("should only start VMI once DataVolumes are complete", func() {
vm, vmi := DefaultVirtualMachine(true)
