Skip to content

Commit

Permalink
Merge pull request kubevirt#10925 from dankenigsberg/less-utils-storage
Browse files Browse the repository at this point in the history
tests/utils: move NewRandomVMIWithEphemeralPVC next to its users
  • Loading branch information
kubevirt-bot authored Dec 26, 2023
2 parents e270a2d + 3d3a1d4 commit 71893af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
41 changes: 33 additions & 8 deletions tests/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ var _ = SIGDescribe("Storage", func() {
})

// The following case is mostly similar to the alpine PVC test above, except using different VirtualMachineInstance.
DescribeTable("started", func(newVMI VMICreationFunc, storageEngine string, family k8sv1.IPFamily) {
DescribeTable("started", func(storageEngine string, family k8sv1.IPFamily) {
libnet.SkipWhenClusterNotSupportIPFamily(family)

// Start the VirtualMachineInstance with the PVC attached
Expand All @@ -432,7 +432,7 @@ var _ = SIGDescribe("Storage", func() {
} else {
pvName = tests.DiskAlpineHostPath
}
vmi = newVMI(pvName)
vmi = newVMIWithEphemeralPVC(pvName)

if storageEngine == "nfs" {
vmi = tests.RunVMIAndExpectLaunchIgnoreWarnings(vmi, 120)
Expand All @@ -443,15 +443,15 @@ var _ = SIGDescribe("Storage", func() {
By(checkingVMInstanceConsoleOut)
Expect(console.LoginToAlpine(vmi)).To(Succeed())
},
Entry("[test_id:3136]with Ephemeral PVC", tests.NewRandomVMIWithEphemeralPVC, "", nil),
Entry("[test_id:4619]with Ephemeral PVC from NFS using ipv4 address of the NFS pod", tests.NewRandomVMIWithEphemeralPVC, "nfs", k8sv1.IPv4Protocol),
Entry("with Ephemeral PVC from NFS using ipv6 address of the NFS pod", tests.NewRandomVMIWithEphemeralPVC, "nfs", k8sv1.IPv6Protocol),
Entry("[test_id:3136]with Ephemeral PVC", "", nil),
Entry("[test_id:4619]with Ephemeral PVC from NFS using ipv4 address of the NFS pod", "nfs", k8sv1.IPv4Protocol),
Entry("with Ephemeral PVC from NFS using ipv6 address of the NFS pod", "nfs", k8sv1.IPv6Protocol),
)
})

// 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 = tests.NewRandomVMIWithEphemeralPVC(tests.DiskAlpineHostPath)
vmi = newVMIWithEphemeralPVC(tests.DiskAlpineHostPath)

By("Starting the VirtualMachineInstance")
var createdVMI *virtv1.VirtualMachineInstance
Expand Down Expand Up @@ -1020,7 +1020,7 @@ var _ = SIGDescribe("Storage", func() {
})

It("should generate the block backingstore disk within the domain", func() {
vmi = tests.NewRandomVMIWithEphemeralPVC(dataVolume.Name)
vmi = newVMIWithEphemeralPVC(dataVolume.Name)

By("Initializing the VM")
tests.RunVMIAndExpectLaunch(vmi, 90)
Expand All @@ -1037,7 +1037,7 @@ 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 = tests.NewRandomVMIWithEphemeralPVC(dataVolume.Name)
vmi = newVMIWithEphemeralPVC(dataVolume.Name)
By("Initializing the VM")

tests.RunVMIAndExpectLaunch(vmi, 60)
Expand Down Expand Up @@ -1344,3 +1344,28 @@ 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
}
25 changes: 0 additions & 25 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,31 +893,6 @@ func DeletePvAndPvc(name string) {
}
}

func NewRandomVMIWithEphemeralPVC(claimName string) *v1.VirtualMachineInstance {
vmi := 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 AddHostDisk(vmi *v1.VirtualMachineInstance, path string, diskType v1.HostDiskType, name string) {
hostDisk := v1.HostDisk{
Path: path,
Expand Down

0 comments on commit 71893af

Please sign in to comment.