Skip to content

Commit

Permalink
tests/storage: remove newVMIWithEphemeralPVC()
Browse files Browse the repository at this point in the history
Remove `newVMIWithEphemeralPVC()` function in `tests/storage/storage.go`, and use libvmi instead.

Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad committed Mar 20, 2024
1 parent 9c3a52d commit bec3394
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions tests/storage/storage.go
Expand Up @@ -434,7 +434,11 @@ var _ = SIGDescribe("Storage", func() {
} else {
pvName = tests.DiskAlpineHostPath
}
vmi = newVMIWithEphemeralPVC(pvName)

vmi = libvmi.New(
libvmi.WithResourceMemory("256Mi"),
libvmi.WithEphemeralPersistentVolumeClaim("disk0", pvName),
)

if storageEngine == "nfs" {
vmi = tests.RunVMIAndExpectLaunchIgnoreWarnings(vmi, 120)
Expand All @@ -453,7 +457,11 @@ var _ = SIGDescribe("Storage", func() {

// Not a candidate for testing on NFS because the VMI is restarted and NFS PVC can't be re-used
It("[test_id:3137]should not persist data", func() {
vmi = newVMIWithEphemeralPVC(tests.DiskAlpineHostPath)
vmi = libvmi.New(
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
libvmi.WithResourceMemory("256Mi"),
libvmi.WithEphemeralPersistentVolumeClaim("disk0", tests.DiskAlpineHostPath),
)

By("Starting the VirtualMachineInstance")
var createdVMI *v1.VirtualMachineInstance
Expand Down Expand Up @@ -1083,10 +1091,12 @@ var _ = SIGDescribe("Storage", func() {
})

It("should generate the block backingstore disk within the domain", func() {
vmi = newVMIWithEphemeralPVC(dataVolume.Name)
vmi = libvmifact.NewGuestless(
libvmi.WithEphemeralPersistentVolumeClaim("disk0", dataVolume.Name),
)

By("Initializing the VM")
tests.RunVMIAndExpectLaunch(vmi, 90)
vmi = tests.RunVMIAndExpectLaunch(vmi, 90)

runningVMISpec, err := tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -1100,7 +1110,10 @@ var _ = SIGDescribe("Storage", func() {
Expect(disks[0].BackingStore.Source.Dev).To(Equal(converter.GetBlockDeviceVolumePath("disk0")))
})
It("should generate the pod with the volumeDevice", func() {
vmi = newVMIWithEphemeralPVC(dataVolume.Name)
vmi = libvmifact.NewGuestless(
libvmi.WithEphemeralPersistentVolumeClaim("disk0", dataVolume.Name),
)

By("Initializing the VM")

vmi = tests.RunVMIAndExpectLaunch(vmi, 60)
Expand Down Expand Up @@ -1415,31 +1428,6 @@ func createBlockDataVolume(virtClient kubecli.KubevirtClient) (*cdiv1.DataVolume
return virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
}

func newVMIWithEphemeralPVC(claimName string) *v1.VirtualMachineInstance {
vmi := tests.NewRandomVMI()

vmi.Spec.Domain.Devices.Disks = append(vmi.Spec.Domain.Devices.Disks, v1.Disk{
Name: "disk0",
DiskDevice: v1.DiskDevice{
Disk: &v1.DiskTarget{
Bus: v1.DiskBusSATA,
},
},
})
vmi.Spec.Volumes = append(vmi.Spec.Volumes, v1.Volume{
Name: "disk0",

VolumeSource: v1.VolumeSource{
Ephemeral: &v1.EphemeralVolumeSource{
PersistentVolumeClaim: &k8sv1.PersistentVolumeClaimVolumeSource{
ClaimName: claimName,
},
},
},
})
return vmi
}

func checkResultShellCommandOnVmi(vmi *v1.VirtualMachineInstance, cmd, output string, timeout int) {
res, err := console.SafeExpectBatchWithResponse(vmi, []expect.Batcher{
&expect.BSnd{S: fmt.Sprintf("%s\n", cmd)},
Expand Down

0 comments on commit bec3394

Please sign in to comment.