Skip to content

Commit

Permalink
Merge pull request #11595 from oshoval/cosmetics1
Browse files Browse the repository at this point in the history
e2e, datavolume: Refactor NewRandomVMWithDataVolume
  • Loading branch information
kubevirt-bot committed Mar 29, 2024
2 parents c39e6cb + c7f8bbf commit 055c6e0
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
Expand Up @@ -627,7 +627,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 @@ -720,7 +720,7 @@ var _ = SIGDescribe("DataVolume Integration", func() {
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 := 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 @@ -742,17 +742,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 @@ -774,14 +765,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 @@ -1098,7 +1085,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 @@ -1299,7 +1286,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 @@ -1463,6 +1450,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
Expand Up @@ -296,33 +296,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 055c6e0

Please sign in to comment.