Skip to content

Commit

Permalink
e2e, datavolume: Refactor NewRandomVMWithDataVolume
Browse files Browse the repository at this point in the history
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
oshoval committed Mar 26, 2024
1 parent 52242a5 commit c7f8bbf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 48 deletions.
53 changes: 32 additions & 21 deletions tests/storage/datavolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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),
Expand Down
27 changes: 0 additions & 27 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,33 +339,6 @@ func NewRandomVMWithDataVolumeWithRegistryImport(imageUrl, namespace, storageCla
return vm
}

// NewRandomVMWithDataVolume
//
// Deprecated: Use libvmi directly
func NewRandomVMWithDataVolume(imageUrl string, namespace string) (*v1.VirtualMachine, bool) {
sc, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists {
return nil, false
}

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("1Gi"),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
)
vm := libvmi.NewVirtualMachine(vmi)

libstorage.AddDataVolumeTemplate(vm, dataVolume)
return vm, true
}

// NewRandomVMIWithEphemeralDisk
//
// Deprecated: Use libvmi directly
Expand Down

0 comments on commit c7f8bbf

Please sign in to comment.