forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e, datavolume: Refactor NewRandomVMWithDataVolume
Move the function from utils. Remove unrequired parameters because they are the same that are used all over. Remove unrequired table that does the same on both cases. Signed-off-by: Or Shoval <[email protected]>
- Loading branch information
Showing
2 changed files
with
32 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -610,7 +610,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { | |
running := true | ||
|
||
var foundSC bool | ||
vm, foundSC = tests.NewRandomVMWithDataVolume(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil)) | ||
vm, foundSC = newRandomVMWithDataVolume() | ||
if !foundSC { | ||
Skip("Skip test when Filesystem storage is not present") | ||
} | ||
|
@@ -703,7 +703,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { | |
Describe("[rfe_id:3188][crit:high][vendor:[email protected]][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 := tests.NewRandomVMWithDataVolume(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil)) | ||
vm, foundSC := newRandomVMWithDataVolume() | ||
if !foundSC { | ||
Skip("Skip test when Filesystem storage is not present") | ||
} | ||
|
@@ -725,17 +725,8 @@ var _ = SIGDescribe("DataVolume Integration", func() { | |
Expect(virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{})).To(Succeed()) | ||
}) | ||
|
||
DescribeTable("[test_id:3191]should be successfully started and stopped multiple times", func(isHTTP bool) { | ||
var ( | ||
vm *v1.VirtualMachine | ||
foundSC bool | ||
) | ||
if isHTTP { | ||
vm, foundSC = tests.NewRandomVMWithDataVolume(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil)) | ||
} else { | ||
url := cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine) | ||
vm, foundSC = tests.NewRandomVMWithDataVolume(url, testsuite.GetTestNamespace(nil)) | ||
} | ||
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") | ||
} | ||
|
@@ -757,14 +748,10 @@ var _ = SIGDescribe("DataVolume Integration", func() { | |
} | ||
vm = tests.StopVirtualMachine(vm) | ||
} | ||
}, | ||
|
||
Entry("with http import", true), | ||
Entry("with registry import", false), | ||
) | ||
}) | ||
|
||
It("[test_id:3192]should remove owner references on DataVolume if VM is orphan deleted.", func() { | ||
vm, foundSC := tests.NewRandomVMWithDataVolume(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil)) | ||
vm, foundSC := newRandomVMWithDataVolume() | ||
if !foundSC { | ||
Skip("Skip test when Filesystem storage is not present") | ||
} | ||
|
@@ -1081,7 +1068,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { | |
DescribeTable("Verify DV of VM with DataVolumeTemplates is garbage collected when", func(ttlBefore, ttlAfter *int32, gcAnnotation string) { | ||
libstorage.SetDataVolumeGC(virtClient, ttlBefore) | ||
|
||
vm, foundSC := tests.NewRandomVMWithDataVolume(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil)) | ||
vm, foundSC := newRandomVMWithDataVolume() | ||
if !foundSC { | ||
Skip("Skip test when Filesystem storage is not present") | ||
} | ||
|
@@ -1282,7 +1269,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { | |
var virtualMachinePreference *instanceType.VirtualMachinePreference | ||
|
||
BeforeEach(func() { | ||
vm, _ = tests.NewRandomVMWithDataVolume(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil)) | ||
vm, _ = newRandomVMWithDataVolume() | ||
|
||
storageClass = &storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -1446,6 +1433,30 @@ func volumeExpansionAllowed(sc string) bool { | |
*storageClass.AllowVolumeExpansion | ||
} | ||
|
||
func newRandomVMWithDataVolume() (*v1.VirtualMachine, bool) { | ||
sc, exists := libstorage.GetRWOFileSystemStorageClass() | ||
if !exists { | ||
return nil, false | ||
} | ||
|
||
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"), | ||
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)), | ||
) | ||
vm := libvmi.NewVirtualMachine(vmi) | ||
|
||
libstorage.AddDataVolumeTemplate(vm, dataVolume) | ||
return vm, true | ||
} | ||
|
||
func newRandomVMWithCloneDataVolume(sourceNamespace, sourceName, targetNamespace, sc string) *v1.VirtualMachine { | ||
dataVolume := libdv.NewDataVolume( | ||
libdv.WithPVCSource(sourceNamespace, sourceName), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters