Skip to content

Commit

Permalink
Merge pull request kubevirt#11605 from dankenigsberg/sysprep-less-New…
Browse files Browse the repository at this point in the history
…RandomVMI

tests: drop the deprecated NewRandomVMI
  • Loading branch information
kubevirt-bot authored Apr 10, 2024
2 parents 8f6d150 + de01a53 commit 3f46669
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 40 deletions.
20 changes: 10 additions & 10 deletions tests/sysprep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ import (
"strings"
"time"

"kubevirt.io/kubevirt/tests/libvmifact"

"kubevirt.io/kubevirt/tests/decorators"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/framework/checks"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/testsuite"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
Expand All @@ -46,10 +37,18 @@ import (
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/pkg/libvmi"

"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/decorators"
"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/flags"
"kubevirt.io/kubevirt/tests/framework/checks"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/libstorage"
"kubevirt.io/kubevirt/tests/libvmifact"
"kubevirt.io/kubevirt/tests/libwait"
"kubevirt.io/kubevirt/tests/testsuite"
"kubevirt.io/kubevirt/tests/util"
)

Expand Down Expand Up @@ -226,6 +225,7 @@ func addExplicitPodNetworkInterface(vmi *v1.VirtualMachineInstance) {
vmi.Spec.Networks = []v1.Network{*v1.DefaultPodNetwork()}
}

// Deprecated: Use libvmi
func getWindowsSysprepVMISpec() v1.VirtualMachineInstanceSpec {
gracePeriod := int64(0)
spinlocks := uint32(8191)
Expand Down Expand Up @@ -315,7 +315,7 @@ var _ = Describe("[Serial][Sysprep][sig-compute]Syspreped VirtualMachineInstance
checks.SkipIfMissingRequiredImage(virtClient, tests.DiskWindowsSysprep)
libstorage.CreatePVC(OSWindowsSysprep, testsuite.GetTestNamespace(nil), "35Gi", libstorage.Config.StorageClassWindows, true)
answerFileWithKey := insertProductKeyToAnswerFileTemplate(answerFileTemplate)
windowsVMI = tests.NewRandomVMI()
windowsVMI = libvmi.New()
windowsVMI.Spec = getWindowsSysprepVMISpec()
tests.CreateConfigMap("sysprepautounattend", windowsVMI.Namespace, map[string]string{"Autounattend.xml": answerFileWithKey, "Unattend.xml": answerFileWithKey})
addExplicitPodNetworkInterface(windowsVMI)
Expand Down
50 changes: 20 additions & 30 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -246,30 +245,6 @@ func NewRandomVirtualMachineInstanceWithBlockDisk(imageUrl, namespace string, ac
return NewRandomVirtualMachineInstanceWithDisk(imageUrl, namespace, sc, accessMode, k8sv1.PersistentVolumeBlock)
}

// NewRandomVMI
//
// Deprecated: Use libvmi directly
func NewRandomVMI() *v1.VirtualMachineInstance {
// To avoid mac address issue in the tests change the pod interface binding to masquerade
// https://github.com/kubevirt/kubevirt/issues/1494
vmi := libvmi.New(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
)
vmi.ObjectMeta.Namespace = testsuite.GetTestNamespace(vmi)
vmi.Spec.Domain.Resources.Requests = k8sv1.ResourceList{}

if checks.IsARM64(testsuite.Arch) {
// Cirros image need 256M to boot on ARM64,
// this issue is traced in https://github.com/kubevirt/kubevirt/issues/6363
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("256Mi")
} else {
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("128Mi")
}

return vmi
}

// NewRandomVMWithDataVolumeWithRegistryImport
//
// Deprecated: Use libvmi directly
Expand All @@ -296,17 +271,32 @@ func NewRandomVMWithDataVolumeWithRegistryImport(imageUrl, namespace, storageCla
return vm
}

func cirrosMemory() string {
// Cirros image need 256M to boot on ARM64,
// this issue is traced in https://github.com/kubevirt/kubevirt/issues/6363
if checks.IsARM64(testsuite.Arch) {
return "256Mi"
}
return "128Mi"
}

// NewRandomVMIWithEphemeralDisk
//
// Deprecated: Use libvmi directly
func NewRandomVMIWithEphemeralDisk(containerImage string) *v1.VirtualMachineInstance {
vmi := NewRandomVMI()

AddEphemeralDisk(vmi, "disk0", v1.DiskBusVirtio, containerImage)
opts := []libvmi.Option{
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
libvmi.WithResourceMemory(cirrosMemory()),
libvmi.WithContainerDisk("disk0", containerImage),
}
if containerImage == cd.ContainerDiskFor(cd.ContainerDiskFedoraTestTooling) {
vmi.Spec.Domain.Devices.Rng = &v1.Rng{} // newer fedora kernels may require hardware RNG to boot
opts = append(
[]libvmi.Option{libvmi.WithRng()},
opts...)
}
return vmi
return libvmi.New(opts...)
}

// AddEphemeralDisk
Expand Down

0 comments on commit 3f46669

Please sign in to comment.