Skip to content

Commit

Permalink
Merge pull request kubevirt#11476 from akalenyu/withdatavolumeanduser…
Browse files Browse the repository at this point in the history
…datainstorageclass

tests, utils: Drop NewRandomVMWithDataVolumeAndUserDataInStorageClass
  • Loading branch information
kubevirt-bot authored Mar 22, 2024
2 parents d4112d6 + 42e8e10 commit 9bd3340
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 83 deletions.
47 changes: 27 additions & 20 deletions tests/storage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,11 +1298,7 @@ var _ = SIGDescribe("Export", func() {
Skip("Skip test when storage with snapshot is not present")
}

vm := tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
sc)
vm := newVMWithDataVolumeForExport(sc)
if libstorage.IsStorageClassBindingModeWaitForFirstConsumer(sc) {
// In WFFC need to start the VM in order for the
// dv to get populated
Expand Down Expand Up @@ -1377,11 +1373,7 @@ var _ = SIGDescribe("Export", func() {
libdv.WithPVC(libdv.PVCWithStorageClass(sc), libdv.PVCWithVolumeSize(cd.BlankVolumeSize)),
)

vm := tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
sc)
vm := newVMWithDataVolumeForExport(sc)
libstorage.AddDataVolumeTemplate(vm, blankDv)
addDataVolumeDisk(vm, "blankdisk", blankDv.Name)
if libstorage.IsStorageClassBindingModeWaitForFirstConsumer(sc) {
Expand Down Expand Up @@ -2188,11 +2180,7 @@ var _ = SIGDescribe("Export", func() {
libdv.WithPVC(libdv.PVCWithStorageClass(sc), libdv.PVCWithVolumeSize(cd.BlankVolumeSize)),
)

vm := tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
sc)
vm := newVMWithDataVolumeForExport(sc)
libstorage.AddDataVolumeTemplate(vm, blankDv)
addDataVolumeDisk(vm, "blankdisk", blankDv.Name)
if libstorage.IsStorageClassBindingModeWaitForFirstConsumer(sc) {
Expand Down Expand Up @@ -2344,11 +2332,7 @@ var _ = SIGDescribe("Export", func() {
libdv.WithBlankImageSource(),
libdv.WithPVC(libdv.PVCWithStorageClass(sc), libdv.PVCWithVolumeSize(cd.BlankVolumeSize)),
)
vm := tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
sc)
vm := newVMWithDataVolumeForExport(sc)
libstorage.AddDataVolumeTemplate(vm, blankDv)
addDataVolumeDisk(vm, "blankdisk", blankDv.Name)
if libstorage.IsStorageClassBindingModeWaitForFirstConsumer(sc) {
Expand Down Expand Up @@ -2690,3 +2674,26 @@ func (matcher *ConditionNoTimeMatcher) FailureMessage(actual interface{}) (messa
func (matcher *ConditionNoTimeMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return format.Message(actual, "not to match without time", matcher.Cond)
}

func newVMWithDataVolumeForExport(storageClass string) *virtv1.VirtualMachine {
dv := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros)),
libdv.WithPVC(
libdv.PVCWithStorageClass(storageClass),
libdv.PVCWithVolumeSize(cd.CirrosVolumeSize),
),
)
vm := libvmi.NewVirtualMachine(
libvmi.New(
libvmi.WithDataVolume("disk0", dv.Name),
libvmi.WithResourceMemory("256Mi"),
libvmi.WithCloudInitNoCloudEncodedUserData(bashHelloScript),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(virtv1.DefaultPodNetwork()),
),
libvmi.WithDataVolumeTemplate(dv),
)

return vm
}
72 changes: 32 additions & 40 deletions tests/storage/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
clonev1alpha1 "kubevirt.io/api/clone/v1alpha1"
"kubevirt.io/api/core"
v1 "kubevirt.io/api/core/v1"
virtv1 "kubevirt.io/api/core/v1"
instancetypev1beta1 "kubevirt.io/api/instancetype/v1beta1"
snapshotv1 "kubevirt.io/api/snapshot/v1alpha1"
"kubevirt.io/client-go/kubecli"
Expand Down Expand Up @@ -598,12 +597,12 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
preference, err := virtClient.VirtualMachinePreference(testsuite.GetTestNamespace(nil)).Create(context.Background(), preference, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

vm.Spec.Template.Spec.Domain.Resources = virtv1.ResourceRequirements{}
vm.Spec.Instancetype = &virtv1.InstancetypeMatcher{
vm.Spec.Template.Spec.Domain.Resources = v1.ResourceRequirements{}
vm.Spec.Instancetype = &v1.InstancetypeMatcher{
Name: instancetype.Name,
Kind: "VirtualMachineInstanceType",
}
vm.Spec.Preference = &virtv1.PreferenceMatcher{
vm.Spec.Preference = &v1.PreferenceMatcher{
Name: preference.Name,
Kind: "VirtualMachinePreference",
}
Expand Down Expand Up @@ -1069,12 +1068,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
}

It("[test_id:5259]should restore a vm multiple from the same snapshot", func() {
vm, vmi = createAndStartVM(tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
snapshotStorageClass,
))
vm, vmi = createAndStartVM(newVMWithDataVolumeForRestore(snapshotStorageClass))

By(stoppingVM)
vm = tests.StopVirtualMachine(vm)
Expand All @@ -1100,12 +1094,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
// behavior. In case of running this test with other provisioner or if ceph
// will change this behavior it will fail.
DescribeTable("should restore a vm with restore size bigger then PVC size", func(restoreToNewVM bool) {
vm = tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
snapshotStorageClass,
)
vm = newVMWithDataVolumeForRestore(snapshotStorageClass)
quantity, err := resource.ParseQuantity("1528Mi")
Expect(err).ToNot(HaveOccurred())
vm.Spec.DataVolumeTemplates[0].Spec.PVC.Resources.Requests["storage"] = quantity
Expand Down Expand Up @@ -1137,12 +1126,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
)

DescribeTable("should restore a vm that boots from a datavolumetemplate", func(restoreToNewVM bool) {
vm, vmi = createAndStartVM(tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
snapshotStorageClass,
))
vm, vmi = createAndStartVM(newVMWithDataVolumeForRestore(snapshotStorageClass))

originalDVName := vm.Spec.DataVolumeTemplates[0].Name
doRestore("", console.LoginToCirros, offlineSnaphot, getTargetVMName(restoreToNewVM, newVmName))
Expand All @@ -1153,12 +1137,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
)

DescribeTable("should restore a vm that boots from a datavolume (not template)", func(restoreToNewVM bool) {
vm = tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
snapshotStorageClass,
)
vm = newVMWithDataVolumeForRestore(snapshotStorageClass)
dv := orphanDataVolumeTemplate(vm, 0)
originalPVCName := dv.Name

Expand Down Expand Up @@ -1324,12 +1303,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
)

It("should reject vm start if restore in progress", func() {
vm, vmi = createAndStartVM(tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
snapshotStorageClass,
))
vm, vmi = createAndStartVM(newVMWithDataVolumeForRestore(snapshotStorageClass))

By(stoppingVM)
vm = tests.StopVirtualMachine(vm)
Expand Down Expand Up @@ -1428,12 +1402,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
})

DescribeTable("should restore a vm from an online snapshot", func(restoreToNewVM bool) {
vm = tests.NewRandomVMWithDataVolumeAndUserDataInStorageClass(
cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros),
testsuite.GetTestNamespace(nil),
bashHelloScript,
snapshotStorageClass,
)
vm = newVMWithDataVolumeForRestore(snapshotStorageClass)
vm.Spec.Template.Spec.Domain.Firmware = &v1.Firmware{}
vm, vmi = createAndStartVM(vm)

Expand Down Expand Up @@ -1868,3 +1837,26 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() {
})
})
})

func newVMWithDataVolumeForRestore(storageClass string) *v1.VirtualMachine {
dv := libdv.NewDataVolume(
libdv.WithRegistryURLSource(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros)),
libdv.WithPVC(
libdv.PVCWithStorageClass(storageClass),
libdv.PVCWithVolumeSize(cd.CirrosVolumeSize),
),
)
vm := libvmi.NewVirtualMachine(
libvmi.New(
libvmi.WithDataVolume("disk0", dv.Name),
libvmi.WithResourceMemory("256Mi"),
libvmi.WithCloudInitNoCloudEncodedUserData(bashHelloScript),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
),
libvmi.WithDataVolumeTemplate(dv),
)

return vm
}
23 changes: 0 additions & 23 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,29 +366,6 @@ func NewRandomVMWithDataVolume(imageUrl string, namespace string) (*v1.VirtualMa
return vm, true
}

// NewRandomVMWithDataVolumeAndUserDataInStorageClass
//
// Deprecated: Use libvmi directly
func NewRandomVMWithDataVolumeAndUserDataInStorageClass(imageUrl, namespace, userData, storageClass string) *v1.VirtualMachine {
dataVolume := libdv.NewDataVolume(
libdv.WithRegistryURLSourceAndPullMethod(imageUrl, cdiv1.RegistryPullNode),
libdv.WithPVC(libdv.PVCWithStorageClass(storageClass), libdv.PVCWithVolumeSize(cd.ContainerDiskSizeBySourceURL(imageUrl))),
)
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.WithCloudInitNoCloudEncodedUserData(userData),
),
libvmi.WithDataVolumeTemplate(dataVolume),
)

return vm
}

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

0 comments on commit 9bd3340

Please sign in to comment.