/
datavolume.go
1497 lines (1276 loc) · 57.8 KB
/
datavolume.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the KubeVirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2017 Red Hat, Inc.
*
*/
package storage
import (
"context"
"fmt"
"math"
"strings"
"time"
"kubevirt.io/kubevirt/tests/decorators"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
expect "github.com/google/goexpect"
storagev1 "k8s.io/api/storage/v1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/utils/pointer"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
instancetypeapi "kubevirt.io/api/instancetype"
instanceType "kubevirt.io/api/instancetype/v1beta1"
"kubevirt.io/kubevirt/pkg/apimachinery/patch"
"kubevirt.io/kubevirt/pkg/libvmi"
virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/clientcmd"
"kubevirt.io/kubevirt/tests/console"
cd "kubevirt.io/kubevirt/tests/containerdisk"
"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/flags"
"kubevirt.io/kubevirt/tests/framework/checks"
. "kubevirt.io/kubevirt/tests/framework/matcher"
"kubevirt.io/kubevirt/tests/libdv"
"kubevirt.io/kubevirt/tests/libpod"
"kubevirt.io/kubevirt/tests/libstorage"
"kubevirt.io/kubevirt/tests/libwait"
"kubevirt.io/kubevirt/tests/testsuite"
)
const (
checkingVMInstanceConsoleExpectedOut = "Checking that the VirtualMachineInstance console has expected output"
creatingVMInvalidDataVolume = "Creating a VM with an invalid DataVolume"
creatingVMDataVolumeTemplateEntry = "Creating VM with DataVolumeTemplate entry with k8s client binary"
verifyingDataVolumeSuccess = "Verifying DataVolume succeeded and is created with VM owner reference"
verifyingPVCCreated = "Verifying PVC is created"
verifyingVMICreated = "Verifying VMI is created with VM owner reference"
syncName = "sync\n"
)
const InvalidDataVolumeUrl = "docker://127.0.0.1/invalid:latest"
var _ = SIGDescribe("DataVolume Integration", func() {
var virtClient kubecli.KubevirtClient
var err error
BeforeEach(func() {
virtClient = kubevirt.Client()
if !libstorage.HasCDI() {
Skip("Skip DataVolume tests when CDI is not present")
}
})
Context("[storage-req]PVC expansion", decorators.StorageReq, func() {
DescribeTable("PVC expansion is detected by VM and can be fully used", func(volumeMode k8sv1.PersistentVolumeMode) {
checks.SkipTestIfNoFeatureGate(virtconfig.ExpandDisksGate)
if !libstorage.HasCDI() {
Skip("Skip DataVolume tests when CDI is not present")
}
var sc string
exists := false
if volumeMode == k8sv1.PersistentVolumeBlock {
sc, exists = libstorage.GetRWOBlockStorageClass()
if !exists {
Skip("Skip test when Block storage is not present")
}
} else {
sc, exists = libstorage.GetRWOFileSystemStorageClass()
if !exists {
Skip("Skip test when Filesystem storage is not present")
}
}
volumeExpansionAllowed := volumeExpansionAllowed(sc)
if !volumeExpansionAllowed {
Skip("Skip when volume expansion storage class not available")
}
imageUrl := cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros)
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSourceAndPullMethod(imageUrl, cdiv1.RegistryPullNode),
libdv.WithPVC(
libdv.PVCWithStorageClass(sc),
libdv.PVCWithVolumeSize(cd.CirrosVolumeSize),
libdv.PVCWithAccessMode(k8sv1.ReadWriteOnce),
libdv.PVCWithVolumeMode(volumeMode),
),
)
dataVolume, err := virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
vmi := libvmi.New(
libvmi.WithDataVolume("disk0", dataVolume.Name),
libvmi.WithResourceMemory("1Gi"),
libvmi.WithCloudInitNoCloudEncodedUserData("#!/bin/bash\necho hello\n"),
)
vmi = tests.RunVMIAndExpectLaunch(vmi, 500)
By("Expecting the VirtualMachineInstance console")
Expect(console.LoginToCirros(vmi)).To(Succeed())
By("Expanding PVC")
patchData, err := patch.GeneratePatchPayload(patch.PatchOperation{
Op: patch.PatchAddOp,
Path: "/spec/resources/requests/storage",
Value: resource.MustParse("2Gi"),
})
Expect(err).ToNot(HaveOccurred())
_, err = virtClient.CoreV1().PersistentVolumeClaims(testsuite.GetTestNamespace(nil)).Patch(context.Background(), dataVolume.Name, types.JSONPatchType, patchData, metav1.PatchOptions{})
Expect(err).ToNot(HaveOccurred())
By("Waiting for notification about size change")
Eventually(func() error {
err := console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: "dmesg |grep 'new size'\n"},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: "dmesg |grep -c 'new size: [34]'\n"},
&expect.BExp{R: "1"},
}, 10)
return err
}, 360).Should(BeNil())
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "sudo /sbin/resize-filesystem /dev/root /run/resize.rootfs /dev/console && echo $?\n"},
&expect.BExp{R: "0"},
}, 30)).To(Succeed(), "failed to resize root")
By("Writing a 1.5G file after expansion, should succeed")
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: "dd if=/dev/zero of=largefile count=1500 bs=1M; echo $?\n"},
&expect.BExp{R: "0"},
}, 360)).To(Succeed(), "can use more space after expansion and resize")
},
Entry("with Block PVC", k8sv1.PersistentVolumeBlock),
Entry("with Filesystem PVC", k8sv1.PersistentVolumeFilesystem),
)
})
Describe("[rfe_id:3188][crit:high][vendor:cnv-qe@redhat.com][level:system] Starting a VirtualMachineInstance with a DataVolume as a volume source", func() {
Context("[Serial]without fsgroup support", Serial, func() {
size := "1Gi"
It("should succesfully start", func() {
// Create DV and alter permission of disk.img
sc, foundSC := libstorage.GetRWXFileSystemStorageClass()
if !foundSC {
Skip("Skip test when Filesystem storage is not present")
}
dv := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine)),
libdv.WithPVC(
libdv.PVCWithStorageClass(sc),
libdv.PVCWithVolumeSize(size),
libdv.PVCWithReadWriteManyAccessMode(),
),
libdv.WithForceBindAnnotation(),
)
dv, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.NamespacePrivileged).Create(context.Background(), dv, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
var pvc *k8sv1.PersistentVolumeClaim
Eventually(func() *k8sv1.PersistentVolumeClaim {
pvc, err = virtClient.CoreV1().PersistentVolumeClaims(testsuite.NamespacePrivileged).Get(context.Background(), dv.Name, metav1.GetOptions{})
if err != nil {
return nil
}
return pvc
}, 30*time.Second).Should(Not(BeNil()))
By("waiting for the dv import to pvc to finish")
libstorage.EventuallyDV(dv, 180, HaveSucceeded())
tests.ChangeImgFilePermissionsToNonQEMU(pvc)
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume("disk0", dv.Name),
libvmi.WithResourceMemory("1Gi"),
libvmi.WithNamespace(testsuite.NamespacePrivileged),
)
By("Starting the VirtualMachineInstance")
vmi = tests.RunVMIAndExpectLaunch(vmi, 120)
By(checkingVMInstanceConsoleExpectedOut)
Expect(console.LoginToAlpine(vmi)).To(Succeed())
})
})
Context("Alpine import", func() {
BeforeEach(func() {
cdis, err := virtClient.CdiClient().CdiV1beta1().CDIs().List(context.Background(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(cdis.Items).To(HaveLen(1))
hasWaitForFirstConsumerGate := false
for _, feature := range cdis.Items[0].Spec.Config.FeatureGates {
if feature == "HonorWaitForFirstConsumer" {
hasWaitForFirstConsumerGate = true
break
}
}
if !hasWaitForFirstConsumerGate {
Skip("HonorWaitForFirstConsumer is disabled in CDI, skipping tests relying on it")
}
})
It("[test_id:3189]should be successfully started and stopped multiple times", func() {
sc, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists {
Skip("Skip test when Filesystem storage is not present")
}
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine)),
libdv.WithPVC(libdv.PVCWithStorageClass(sc)),
)
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume("disk0", dataVolume.Name),
libvmi.WithResourceMemory("1Gi"),
)
dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
// This will only work on storage with binding mode WaitForFirstConsumer,
if libstorage.IsStorageClassBindingModeWaitForFirstConsumer(libstorage.Config.StorageRWOFileSystem) {
Eventually(ThisDV(dataVolume), 40).Should(WaitForFirstConsumer())
}
num := 2
By("Starting and stopping the VirtualMachineInstance a number of times")
for i := 1; i <= num; i++ {
vmi := tests.RunVMIAndExpectLaunchWithDataVolume(vmi, dataVolume, 500)
// Verify console on last iteration to verify the VirtualMachineInstance is still booting properly
// after being restarted multiple times
if i == num {
By(checkingVMInstanceConsoleExpectedOut)
Expect(console.LoginToAlpine(vmi)).To(Succeed())
}
err = virtClient.VirtualMachineInstance(vmi.Namespace).Delete(context.Background(), vmi.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
libwait.WaitForVirtualMachineToDisappearWithTimeout(vmi, 120)
}
libstorage.DeleteDataVolume(&dataVolume)
})
It("[test_id:6686]should successfully start multiple concurrent VMIs", func() {
sc, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists {
Skip("Skip test when Filesystem storage is not present")
}
imageUrl := cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine)
const numVmis = 5
vmis := make([]*v1.VirtualMachineInstance, 0, numVmis)
dvs := make([]*cdiv1.DataVolume, 0, numVmis)
for idx := 0; idx < numVmis; idx++ {
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSource(imageUrl),
libdv.WithPVC(libdv.PVCWithStorageClass(sc)),
)
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume("disk0", dataVolume.Name),
libvmi.WithResourceMemory("128Mi"),
)
dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
vmi, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
vmis = append(vmis, vmi)
dvs = append(dvs, dataVolume)
}
for idx := 0; idx < numVmis; idx++ {
libwait.WaitForSuccessfulVMIStart(vmis[idx],
libwait.WithFailOnWarnings(false),
libwait.WithTimeout(500),
)
By(checkingVMInstanceConsoleExpectedOut)
Expect(console.LoginToAlpine(vmis[idx])).To(Succeed())
err := virtClient.VirtualMachineInstance(vmis[idx].Namespace).Delete(context.Background(), vmis[idx].Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
libstorage.DeleteDataVolume(&dvs[idx])
}
})
It("[test_id:5252]should be successfully started when using a PVC volume owned by a DataVolume", func() {
sc, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists {
Skip("Skip test when Filesystem storage is not present")
}
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine)),
libdv.WithPVC(libdv.PVCWithStorageClass(sc)),
)
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithPersistentVolumeClaim("disk0", dataVolume.Name),
libvmi.WithResourceMemory("128Mi"),
)
dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
// This will only work on storage with binding mode WaitForFirstConsumer,
if libstorage.IsStorageClassBindingModeWaitForFirstConsumer(libstorage.Config.StorageRWOFileSystem) {
Eventually(ThisDV(dataVolume), 40).Should(WaitForFirstConsumer())
}
// with WFFC the run actually starts the import and then runs VM, so the timeout has to include both
// import and start
vmi = tests.RunVMIAndExpectLaunchWithDataVolume(vmi, dataVolume, 500)
By(checkingVMInstanceConsoleExpectedOut)
Expect(console.LoginToAlpine(vmi)).To(Succeed())
err = virtClient.VirtualMachineInstance(vmi.Namespace).Delete(context.Background(), vmi.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
libwait.WaitForVirtualMachineToDisappearWithTimeout(vmi, 120)
libstorage.DeleteDataVolume(&dataVolume)
})
It("should accurately aggregate DataVolume conditions from many DVs", func() {
dataVolume1 := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine)),
libdv.WithPVC(),
)
dataVolume2 := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine)),
libdv.WithPVC(),
)
By("requiring a VM with 2 DataVolumes")
vmi := libvmi.New(
libvmi.WithResourceMemory("128Mi"),
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume(dataVolume1.Name, dataVolume1.Name),
libvmi.WithDataVolume(dataVolume2.Name, dataVolume2.Name),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
)
vmSpec := libvmi.NewVirtualMachine(vmi, libvmi.WithRunning())
vm, err := virtClient.VirtualMachine(vmSpec.Namespace).Create(context.Background(), vmSpec, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(ThisVM(vm), 180*time.Second, 2*time.Second).Should(HavePrintableStatus(v1.VirtualMachineStatusPvcNotFound))
By("creating the first DataVolume")
dataVolume1, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(vmSpec.Namespace).Create(context.Background(), dataVolume1, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By("ensuring that VMI and VM are reporting VirtualMachineInstanceDataVolumesReady=False")
Eventually(ThisVMI(vmi), 180*time.Second, 2*time.Second).Should(HaveConditionFalse(v1.VirtualMachineInstanceDataVolumesReady))
Eventually(ThisVM(vm), 180*time.Second, 2*time.Second).Should(HaveConditionFalse(v1.VirtualMachineInstanceDataVolumesReady))
By("creating the second DataVolume")
dataVolume2, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(vmSpec.Namespace).Create(context.Background(), dataVolume2, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By("ensuring that VMI and VM are reporting VirtualMachineInstanceDataVolumesReady=True")
Eventually(ThisVMI(vmi), 240*time.Second, 2*time.Second).Should(HaveConditionTrue(v1.VirtualMachineInstanceDataVolumesReady))
Eventually(ThisVM(vm), 240*time.Second, 2*time.Second).Should(HaveConditionTrue(v1.VirtualMachineInstanceDataVolumesReady))
})
})
Context("with a PVC from a Datavolume", func() {
var storageClass *storagev1.StorageClass
var vmi *v1.VirtualMachineInstance
var dv *cdiv1.DataVolume
BeforeEach(func() {
// ensure that we always use a storage class which binds immediately,
// otherwise we will never see a PVC appear for the datavolume
bindMode := storagev1.VolumeBindingImmediate
storageClass = &storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "fake",
},
Provisioner: "afakeone",
VolumeBindingMode: &bindMode,
}
storageClass, err = virtClient.StorageV1().StorageClasses().Create(context.Background(), storageClass, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
dv = libdv.NewDataVolume(
libdv.WithNamespace(testsuite.GetTestNamespace(nil)), // need it for deletion. Reading it from Create() does not work here
libdv.WithRegistryURLSourceAndPullMethod(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), cdiv1.RegistryPullNode),
libdv.WithPVC(libdv.PVCWithStorageClass(storageClass.Name)),
)
vmi = libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithResourceMemory("32Mi"),
libvmi.WithPersistentVolumeClaim(diskName, dv.ObjectMeta.Name),
)
})
AfterEach(func() {
if storageClass != nil && storageClass.Name != "" {
err := virtClient.StorageV1().StorageClasses().Delete(context.Background(), storageClass.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
}
libstorage.DeleteDataVolume(&dv)
})
It("[test_id:4643]should NOT be rejected when VM template lists a DataVolume, but VM lists PVC VolumeSource", func() {
_, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dv, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
_, err := virtClient.CoreV1().PersistentVolumeClaims(testsuite.GetTestNamespace(dv)).Get(context.Background(), dv.Name, metav1.GetOptions{})
return err
}, 30*time.Second, 1*time.Second).Should(Succeed())
vm := libvmi.NewVirtualMachine(vmi, libvmi.WithRunning())
dvt := &v1.DataVolumeTemplateSpec{
ObjectMeta: dv.ObjectMeta,
Spec: dv.Spec,
}
vm.Spec.DataVolumeTemplates = append(vm.Spec.DataVolumeTemplates, *dvt)
_, err = virtClient.VirtualMachine(testsuite.GetTestNamespace(nil)).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
})
})
})
Describe("[rfe_id:3188][crit:high][vendor:cnv-qe@redhat.com][level:system] Starting a VirtualMachine with an invalid DataVolume", func() {
Context("using DataVolume with invalid URL", func() {
It("should be possible to stop VM if datavolume is crashing", func() {
sc, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists {
Skip("Skip test when Filesystem storage is not present")
}
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSourceAndPullMethod(InvalidDataVolumeUrl, cdiv1.RegistryPullPod),
libdv.WithPVC(libdv.PVCWithStorageClass(sc)),
)
vm := libvmi.NewVirtualMachine(
libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume("disk0", dataVolume.Name),
libvmi.WithResourceMemory("1Gi"),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
), libvmi.WithRunning(), libvmi.WithDataVolumeTemplate(dataVolume))
By(creatingVMInvalidDataVolume)
vm, err := virtClient.VirtualMachine(vm.Namespace).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By("Waiting for DV to start crashing")
Eventually(ThisDVWith(vm.Namespace, dataVolume.Name), 60).Should(BeInPhase(cdiv1.ImportInProgress))
By("Stop VM")
tests.StopVirtualMachineWithTimeout(vm, time.Second*30)
})
It("[test_id:3190]should correctly handle invalid DataVolumes", func() {
// Don't actually create the DataVolume since it's invalid.
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSource(InvalidDataVolumeUrl),
libdv.WithPVC(libdv.PVCWithStorageClass("fakeStorageClass")),
)
// Add the invalid DataVolume to a VMI
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume("disk0", dataVolume.Name),
libvmi.WithResourceMemory("1Gi"),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
)
// Create a VM for this VMI
vm := libvmi.NewVirtualMachine(vmi, libvmi.WithRunning())
By(creatingVMInvalidDataVolume)
vm, err = virtClient.VirtualMachine(vm.Namespace).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By("Waiting for VMI to be created")
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 100).Should(BeInPhase(v1.Pending))
})
It("[test_id:3190]should correctly handle eventually consistent DataVolumes", func() {
sc, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists {
Skip("Skip test when Filesystem storage is not present")
}
realRegistryName := flags.KubeVirtUtilityRepoPrefix
realRegistryPort := ""
if strings.Contains(flags.KubeVirtUtilityRepoPrefix, ":") {
realRegistryName = strings.Split(flags.KubeVirtUtilityRepoPrefix, ":")[0]
realRegistryPort = strings.Split(flags.KubeVirtUtilityRepoPrefix, ":")[1]
}
if realRegistryPort == "" {
Skip("Skip when no port, CDI will always try to reach dockerhub/fakeregistry instead of just fakeregistry")
}
fakeRegistryName := "fakeregistry"
fakeRegistryWithPort := fakeRegistryName
if realRegistryPort != "" {
fakeRegistryWithPort = fmt.Sprintf("%s:%s", fakeRegistryName, realRegistryPort)
}
imageUrl := cd.DataVolumeImportUrlFromRegistryForContainerDisk(fakeRegistryWithPort, cd.ContainerDiskCirros)
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSourceAndPullMethod(imageUrl, cdiv1.RegistryPullPod),
libdv.WithPVC(libdv.PVCWithStorageClass(sc)),
)
defer libstorage.DeleteDataVolume(&dataVolume)
By("Creating DataVolume with invalid URL")
dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By(creatingVMInvalidDataVolume)
// Add the invalid DataVolume to a VMI
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithDataVolume("disk0", dataVolume.Name),
libvmi.WithResourceMemory("1Gi"),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
)
// Create a VM for this VMI
vm := libvmi.NewVirtualMachine(vmi, libvmi.WithRunning())
vm, err = virtClient.VirtualMachine(vm.Namespace).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 100).Should(Or(BeInPhase(v1.Pending), BeInPhase(v1.Scheduling)))
By("Creating a service which makes the registry reachable")
_, err = virtClient.CoreV1().Services(vm.Namespace).Create(context.Background(), &k8sv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: fakeRegistryName,
},
Spec: k8sv1.ServiceSpec{
Type: k8sv1.ServiceTypeExternalName,
ExternalName: realRegistryName,
},
}, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By("Wait for DataVolume to complete")
libstorage.EventuallyDV(dataVolume, 160, HaveSucceeded())
By("Waiting for VMI to be created")
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 100).Should(BeInPhase(v1.Running))
})
})
})
Describe("[rfe_id:896][crit:high][vendor:cnv-qe@redhat.com][level:system] with oc/kubectl", func() {
var vm *v1.VirtualMachine
var err error
var vmJson string
var dataVolumeName string
var pvcName string
k8sClient := clientcmd.GetK8sCmdClient()
BeforeEach(func() {
running := true
var foundSC bool
vm, foundSC = newRandomVMWithDataVolume()
if !foundSC {
Skip("Skip test when Filesystem storage is not present")
}
vm.Spec.Running = &running
dataVolumeName = vm.Spec.DataVolumeTemplates[0].Name
pvcName = dataVolumeName
vmJson, err = tests.GenerateVMJson(vm, GinkgoT().TempDir())
Expect(err).ToNot(HaveOccurred())
})
It("[test_id:836] Creating a VM with DataVolumeTemplates should succeed.", func() {
By(creatingVMDataVolumeTemplateEntry)
_, _, err = clientcmd.RunCommand(k8sClient, "create", "-f", vmJson)
Expect(err).ToNot(HaveOccurred())
By(verifyingDataVolumeSuccess)
libstorage.EventuallyDVWith(vm.Namespace, dataVolumeName, 100, And(HaveSucceeded(), BeOwned()))
By(verifyingPVCCreated)
Eventually(ThisPVCWith(vm.Namespace, pvcName), 160).Should(Exist())
By(verifyingVMICreated)
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 160).Should(And(BeRunning(), BeOwned()))
})
It("[test_id:837]deleting VM with cascade=true should automatically delete DataVolumes and VMI owned by VM.", func() {
By(creatingVMDataVolumeTemplateEntry)
_, _, err = clientcmd.RunCommand(k8sClient, "create", "-f", vmJson)
Expect(err).ToNot(HaveOccurred())
By(verifyingDataVolumeSuccess)
libstorage.EventuallyDVWith(vm.Namespace, dataVolumeName, 100, And(HaveSucceeded(), BeOwned()))
By(verifyingPVCCreated)
Eventually(ThisPVCWith(vm.Namespace, pvcName), 160).Should(Exist())
By(verifyingVMICreated)
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 160).Should(And(BeRunning(), BeOwned()))
By("Deleting VM with cascade=true")
_, _, err = clientcmd.RunCommand("kubectl", "delete", "vm", vm.Name, "--cascade=true")
Expect(err).ToNot(HaveOccurred())
By("Waiting for the VM to be deleted")
Eventually(ThisVM(vm), 100).Should(BeGone())
By("Waiting for the VMI to be deleted")
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 100).Should(BeGone())
By("Waiting for the DataVolume to be deleted")
Eventually(ThisDVWith(vm.Namespace, dataVolumeName), 100).Should(BeGone())
By("Waiting for the PVC to be deleted")
Eventually(ThisPVCWith(vm.Namespace, pvcName), 100).Should(BeGone())
})
It("[test_id:838]deleting VM with cascade=false should orphan DataVolumes and VMI owned by VM.", func() {
_, _, err = clientcmd.RunCommand(k8sClient, "create", "-f", vmJson)
By(creatingVMDataVolumeTemplateEntry)
Expect(err).ToNot(HaveOccurred())
By(verifyingDataVolumeSuccess)
libstorage.EventuallyDVWith(vm.Namespace, dataVolumeName, 100, And(HaveSucceeded(), BeOwned()))
By(verifyingPVCCreated)
Eventually(ThisPVCWith(vm.Namespace, pvcName), 160).Should(Exist())
By(verifyingVMICreated)
Eventually(ThisVMIWith(vm.Namespace, vm.Name), 160).Should(And(BeRunning(), BeOwned()))
By("Deleting VM with cascade=false")
_, _, err = clientcmd.RunCommand("kubectl", "delete", "vm", vm.Name, "--cascade=false")
Expect(err).ToNot(HaveOccurred())
By("Waiting for the VM to be deleted")
Eventually(ThisVM(vm), 100).Should(BeGone())
By("Verifying DataVolume still exists with owner references removed")
libstorage.EventuallyDVWith(vm.Namespace, dataVolumeName, 100, And(HaveSucceeded(), Not(BeOwned())))
By("Verifying VMI still exists with owner references removed")
Consistently(ThisVMIWith(vm.Namespace, vm.Name), 60, 1).Should(And(BeRunning(), Not(BeOwned())))
})
})
Describe("[rfe_id:3188][crit:high][vendor:cnv-qe@redhat.com][level:system] Starting a VirtualMachine with a DataVolume", func() {
Context("using Alpine http import", func() {
It("a DataVolume with preallocation shouldn't have discard=unmap", func() {
vm, foundSC := newRandomVMWithDataVolume()
if !foundSC {
Skip("Skip test when Filesystem storage is not present")
}
preallocation := true
vm.Spec.DataVolumeTemplates[0].Spec.Preallocation = &preallocation
vm, err = virtClient.VirtualMachine(testsuite.GetTestNamespace(nil)).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
vm = tests.StartVirtualMachine(vm)
vmi, err := virtClient.VirtualMachineInstance(vm.Namespace).Get(context.Background(), vm.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).ToNot(ContainSubstring("discard='unmap'"))
vm = tests.StopVirtualMachine(vm)
Expect(virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, metav1.DeleteOptions{})).To(Succeed())
})
It("[test_id:3191]should be successfully started and stopped multiple times", func() {
vm, foundSC := newRandomVMWithDataVolume()
if !foundSC {
Skip("Skip test when Filesystem storage is not present")
}
vm, err = virtClient.VirtualMachine(testsuite.GetTestNamespace(nil)).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
num := 2
By("Starting and stopping the VirtualMachine number of times")
for i := 0; i < num; i++ {
By(fmt.Sprintf("Doing run: %d", i))
vm = tests.StartVirtualMachine(vm)
// Verify console on last iteration to verify the VirtualMachineInstance is still booting properly
// after being restarted multiple times
if i == num {
By(checkingVMInstanceConsoleExpectedOut)
vmi, err := virtClient.VirtualMachineInstance(vm.Namespace).Get(context.Background(), vm.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(console.LoginToAlpine(vmi)).To(Succeed())
}
vm = tests.StopVirtualMachine(vm)
}
})
It("[test_id:3192]should remove owner references on DataVolume if VM is orphan deleted.", func() {
vm, foundSC := newRandomVMWithDataVolume()
if !foundSC {
Skip("Skip test when Filesystem storage is not present")
}
vm, err = virtClient.VirtualMachine(testsuite.GetTestNamespace(nil)).Create(context.Background(), vm, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
// Check for owner reference
Eventually(ThisDVWith(vm.Namespace, vm.Spec.DataVolumeTemplates[0].Name), 100).Should(BeOwned())
// Delete the VM with orphan Propagation
orphanPolicy := metav1.DeletePropagationOrphan
Expect(virtClient.VirtualMachine(vm.Namespace).
Delete(context.Background(), vm.Name, metav1.DeleteOptions{PropagationPolicy: &orphanPolicy})).To(Succeed())
// Wait for the owner reference to disappear
Eventually(ThisDVWith(vm.Namespace, vm.Spec.DataVolumeTemplates[0].Name), 100).Should(Not(BeOwned()))
})
})
})
Describe("[rfe_id:3188][crit:high][vendor:cnv-qe@redhat.com][level:system] DataVolume clone permission checking", func() {
Context("using Alpine import/clone", func() {
var dataVolume *cdiv1.DataVolume
var cloneRole *rbacv1.Role
var cloneRoleBinding *rbacv1.RoleBinding
var storageClass string
var vm *v1.VirtualMachine
BeforeEach(func() {
storageClass, err = libstorage.GetSnapshotStorageClass(virtClient)
Expect(err).ToNot(HaveOccurred())
if storageClass == "" {
Skip("Skiping test, no VolumeSnapshot support")
}
dataVolume = libdv.NewDataVolume(
libdv.WithRegistryURLSourceAndPullMethod(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), cdiv1.RegistryPullNode),
libdv.WithPVC(libdv.PVCWithStorageClass(storageClass)),
libdv.WithForceBindAnnotation(),
)
dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.NamespaceTestAlternative).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
libstorage.EventuallyDV(dataVolume, 90, HaveSucceeded())
vm = newRandomVMWithCloneDataVolume(testsuite.NamespaceTestAlternative, dataVolume.Name, testsuite.GetTestNamespace(nil), storageClass)
const volumeName = "sa"
saVol := v1.Volume{
Name: volumeName,
VolumeSource: v1.VolumeSource{
ServiceAccount: &v1.ServiceAccountVolumeSource{
ServiceAccountName: testsuite.AdminServiceAccountName,
},
},
}
vm.Spec.DataVolumeTemplates[0].Spec.PVC.StorageClassName = pointer.String(storageClass)
vm.Spec.Template.Spec.Volumes = append(vm.Spec.Template.Spec.Volumes, saVol)
vm.Spec.Template.Spec.Domain.Devices.Disks = append(vm.Spec.Template.Spec.Domain.Devices.Disks, v1.Disk{Name: volumeName})
})
AfterEach(func() {
if cloneRole != nil {
err := virtClient.RbacV1().Roles(cloneRole.Namespace).Delete(context.Background(), cloneRole.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
cloneRole = nil
}
if cloneRoleBinding != nil {
err := virtClient.RbacV1().RoleBindings(cloneRoleBinding.Namespace).Delete(context.Background(), cloneRoleBinding.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
cloneRoleBinding = nil
}
})
createVMSuccess := func() {
// sometimes it takes a bit for permission to actually be applied so eventually
Eventually(func() bool {
_, err = virtClient.VirtualMachine(vm.Namespace).Create(context.Background(), vm, metav1.CreateOptions{})
if err != nil {
fmt.Printf("command should have succeeded maybe new permissions not applied yet\nerror\n%s\n", err)
return false
}
return true
}, 90*time.Second, 1*time.Second).Should(BeTrue())
// start vm and check dv clone succeeded
vm = tests.StartVirtualMachine(vm)
targetDVName := vm.Spec.DataVolumeTemplates[0].Name
libstorage.EventuallyDVWith(vm.Namespace, targetDVName, 90, HaveSucceeded())
}
createPVCDataSource := func() *cdiv1.DataSource {
dvt := &vm.Spec.DataVolumeTemplates[0]
return &cdiv1.DataSource{
ObjectMeta: metav1.ObjectMeta{
Name: "ds-" + rand.String(12),
},
Spec: cdiv1.DataSourceSpec{
Source: cdiv1.DataSourceSource{
PVC: dvt.Spec.Source.PVC,
},
},
}
}
snapshotCloneMutateFunc := func() {
snapshotClassName, err := libstorage.GetSnapshotClass(storageClass, virtClient)
Expect(err).ToNot(HaveOccurred())
if snapshotClassName == "" {
Fail("The clone permission suite uses a snapshot-capable storage class, must have associated snapshot class")
}
dvt := &vm.Spec.DataVolumeTemplates[0]
snap := libstorage.NewVolumeSnapshot(dvt.Spec.Source.PVC.Name, dvt.Spec.Source.PVC.Namespace, dvt.Spec.Source.PVC.Name, &snapshotClassName)
snap, err = virtClient.KubernetesSnapshotClient().
SnapshotV1().
VolumeSnapshots(snap.Namespace).
Create(context.Background(), snap, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
dvt.Spec.Source = &cdiv1.DataVolumeSource{
Snapshot: &cdiv1.DataVolumeSourceSnapshot{
Namespace: snap.Namespace,
Name: snap.Name,
},
}
}
createSnapshotDataSource := func() *cdiv1.DataSource {
snapshotClassName, err := libstorage.GetSnapshotClass(storageClass, virtClient)
Expect(err).ToNot(HaveOccurred())
if snapshotClassName == "" {
Fail("The clone permission suite uses a snapshot-capable storage class, must have associated snapshot class")
}
dvt := &vm.Spec.DataVolumeTemplates[0]
snap := libstorage.NewVolumeSnapshot(dvt.Spec.Source.PVC.Name, dvt.Spec.Source.PVC.Namespace, dvt.Spec.Source.PVC.Name, &snapshotClassName)
snap, err = virtClient.KubernetesSnapshotClient().
SnapshotV1().
VolumeSnapshots(snap.Namespace).
Create(context.Background(), snap, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
return &cdiv1.DataSource{
ObjectMeta: metav1.ObjectMeta{
Name: "ds-" + rand.String(12),
},
Spec: cdiv1.DataSourceSpec{
Source: cdiv1.DataSourceSource{
Snapshot: &cdiv1.DataVolumeSourceSnapshot{
Namespace: snap.Namespace,
Name: snap.Name,
},
},
},
}
}
DescribeTable("should resolve DataVolume sourceRef", func(createDataSourceFunc func() *cdiv1.DataSource) {
// convert DV to use datasource
dvt := &vm.Spec.DataVolumeTemplates[0]
ds := createDataSourceFunc()
ds, err := virtClient.CdiClient().CdiV1beta1().DataSources(vm.Namespace).Create(context.TODO(), ds, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
defer func() {
err := virtClient.CdiClient().CdiV1beta1().DataSources(ds.Namespace).Delete(context.TODO(), ds.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
}()
dvt.Spec.Source = nil
dvt.Spec.SourceRef = &cdiv1.DataVolumeSourceRef{
Kind: "DataSource",
Name: ds.Name,
}
cloneRole, cloneRoleBinding = addClonePermission(
virtClient,
explicitCloneRole,
testsuite.AdminServiceAccountName,
testsuite.GetTestNamespace(nil),
testsuite.NamespaceTestAlternative,
)
createVMSuccess()
dv, err := virtClient.CdiClient().CdiV1beta1().DataVolumes(vm.Namespace).Get(context.TODO(), dvt.Name, metav1.GetOptions{})
if libstorage.IsDataVolumeGC(virtClient) {
Expect(err).To(MatchError(errors.IsNotFound, "k8serrors.IsNotFound"))
return
}
Expect(err).ToNot(HaveOccurred())
Expect(dv.Spec.SourceRef).To(BeNil())
switch {
case dv.Spec.Source.PVC != nil:
Expect(dv.Spec.Source.PVC.Namespace).To(Equal(ds.Spec.Source.PVC.Namespace))
Expect(dv.Spec.Source.PVC.Name).To(Equal(ds.Spec.Source.PVC.Name))
case dv.Spec.Source.Snapshot != nil:
Expect(dv.Spec.Source.Snapshot.Namespace).To(Equal(ds.Spec.Source.Snapshot.Namespace))
Expect(dv.Spec.Source.Snapshot.Name).To(Equal(ds.Spec.Source.Snapshot.Name))
default:
Fail(fmt.Sprintf("wrong dv source %+v", dv))
}
},
Entry("with PVC source", createPVCDataSource),
Entry("with Snapshot source", createSnapshotDataSource),
)
It("should report DataVolume without source PVC", func() {
cloneRole, cloneRoleBinding = addClonePermission(
virtClient,
explicitCloneRole,
testsuite.AdminServiceAccountName,
testsuite.GetTestNamespace(nil),
testsuite.NamespaceTestAlternative,
)
// We first delete the source PVC and DataVolume to force a clone without source
err := virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.NamespaceTestAlternative).Delete(context.Background(), dataVolume.Name, metav1.DeleteOptions{})
if !errors.IsNotFound(err) {
Expect(err).ToNot(HaveOccurred())
}
err = virtClient.CoreV1().PersistentVolumeClaims(testsuite.NamespaceTestAlternative).Delete(context.Background(), dataVolume.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
// We check if the VM is succesfully created
By("Creating VM")