Skip to content

Commit

Permalink
Merge pull request kubevirt#11056 from fossedihelm/utils_cleanup
Browse files Browse the repository at this point in the history
refactor: tests/utils.go cleanup
  • Loading branch information
kubevirt-bot authored Jan 30, 2024
2 parents fbc4ecb + 4576119 commit 9ddfeaa
Show file tree
Hide file tree
Showing 32 changed files with 324 additions and 402 deletions.
5 changes: 3 additions & 2 deletions tests/container_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ var _ = Describe("[rfe_id:588][crit:medium][vendor:cnv-qe@redhat.com][level:comp
Describe("[rfe_id:273][crit:medium][vendor:cnv-qe@redhat.com][level:component]Starting with virtio-win", func() {
Context("with virtio-win as secondary disk", func() {
It("[test_id:1467]should boot and have the virtio as sata CDROM", func() {
vmi := libvmi.NewAlpine()
tests.AddEphemeralCdrom(vmi, "disk4", v1.DiskBusSATA, cd.ContainerDiskFor(cd.ContainerDiskVirtio))
vmi := libvmi.NewAlpine(
libvmi.WithEphemeralCDRom("disk4", v1.DiskBusSATA, cd.ContainerDiskFor(cd.ContainerDiskVirtio)),
)
vmi = tests.RunVMIAndExpectLaunch(vmi, 60)

By("Checking whether the second disk really contains virtio drivers")
Expand Down
3 changes: 2 additions & 1 deletion tests/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"kubevirt.io/kubevirt/tests/decorators"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/libmigration"
"kubevirt.io/kubevirt/tests/libvmi"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -233,7 +234,7 @@ var _ = Describe("[sig-compute]Dry-Run requests", decorators.SigCompute, func()
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())
vmim = tests.NewRandomMigration(vmi.Name, vmi.Namespace)
vmim = libmigration.New(vmi.Name, vmi.Namespace)
})

It("[test_id:7635]create a migration", func() {
Expand Down
2 changes: 1 addition & 1 deletion tests/hotplug/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ var _ = Describe("[sig-compute][Serial]CPU Hotplug", decorators.SigCompute, deco
}))

By("starting the migration")
migration := tests.NewRandomMigration(vm.Name, vm.Namespace)
migration := libmigration.New(vm.Name, vm.Namespace)
migration, err = virtClient.VirtualMachineInstanceMigration(vm.Namespace).Create(migration, &metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Expand Down
2 changes: 1 addition & 1 deletion tests/hyperv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var _ = Describe("[Serial][sig-compute] Hyper-V enlightenments", Serial, decorat
reEnlightenmentVMI = libwait.WaitForSuccessfulVMIStart(reEnlightenmentVMI)

By("Migrating the VM")
migration := tests.NewRandomMigration(reEnlightenmentVMI.Name, reEnlightenmentVMI.Namespace)
migration := libmigration.New(reEnlightenmentVMI.Name, reEnlightenmentVMI.Namespace)
migrationUID := libmigration.RunMigrationAndExpectToCompleteWithDefaultTimeout(virtClient, migration)

By("Checking VMI, confirm migration state")
Expand Down
2 changes: 1 addition & 1 deletion tests/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var _ = Describe("[sig-compute]oc/kubectl integration", decorators.SigCompute, f
Expect(console.LoginToCirros(vmi)).To(Succeed())

By("creating the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migration := libmigration.New(vmi.Name, vmi.Namespace)

var migrationCreated *v1.VirtualMachineInstanceMigration
By("starting migration")
Expand Down
16 changes: 16 additions & 0 deletions tests/libmigration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ import (

const MigrationWaitTime = 240

func New(vmiName string, namespace string) *v1.VirtualMachineInstanceMigration {
return &v1.VirtualMachineInstanceMigration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.GroupVersion.String(),
Kind: "VirtualMachineInstanceMigration",
},
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-migration-",
Namespace: namespace,
},
Spec: v1.VirtualMachineInstanceMigrationSpec{
VMIName: vmiName,
},
}
}

func ExpectMigrationToSucceed(virtClient kubecli.KubevirtClient, migration *v1.VirtualMachineInstanceMigration, timeout int) *v1.VirtualMachineInstanceMigration {
return ExpectMigrationToSucceedWithOffset(2, virtClient, migration, timeout)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/libvmi/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ func WithCDRom(cdRomName string, bus v1.DiskBus, claimName string) Option {
}
}

// WithEphemeralCDRom specifies a CDRom drive to be used.
func WithEphemeralCDRom(cdRomName string, bus v1.DiskBus, claimName string) Option {
return func(vmi *v1.VirtualMachineInstance) {
addDisk(vmi, newCDRom(cdRomName, bus))
addVolume(vmi, newContainerVolume(cdRomName, claimName))
}
}

// WithFilesystemPVC specifies a filesystem backed by a PVC to be used.
func WithFilesystemPVC(claimName string) Option {
return func(vmi *v1.VirtualMachineInstance) {
Expand Down
3 changes: 2 additions & 1 deletion tests/migration/eviction_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"kubevirt.io/kubevirt/tests/framework/cleanup"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/framework/matcher"
"kubevirt.io/kubevirt/tests/libmigration"
"kubevirt.io/kubevirt/tests/libnet"
"kubevirt.io/kubevirt/tests/libnode"
"kubevirt.io/kubevirt/tests/libvmi"
Expand Down Expand Up @@ -242,7 +243,7 @@ var _ = SIGMigrationDescribe("Live Migration", func() {

// execute a migration, wait for finalized state
By("Starting the Migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migration := libmigration.New(vmi.Name, vmi.Namespace)
migration, err := virtClient.VirtualMachineInstanceMigration(vmi.Namespace).Create(migration, &metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Expand Down
Loading

0 comments on commit 9ddfeaa

Please sign in to comment.