Skip to content

Commit

Permalink
test: enable end-to-end validator tests on s390x.
Browse files Browse the repository at this point in the history
Signed-off-by: Nestor Acuna Blanco <[email protected]>
  • Loading branch information
nestoracunablanco committed Nov 26, 2024
1 parent 9ce1906 commit 5d9489e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
28 changes: 28 additions & 0 deletions tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -366,6 +367,7 @@ var (
sspListerWatcher cache.ListerWatcher
portForwarder PortForwarder
deploymentTimedOut bool
clusterMachineType string
)

var _ = BeforeSuite(func() {
Expand Down Expand Up @@ -405,6 +407,8 @@ var _ = BeforeSuite(func() {
setupApiClient()
strategy.Init()

clusterMachineType = retrieveQemuMachineType()

// Wait to finish deployment before running any tests
waitUntilDeployed()
})
Expand Down Expand Up @@ -601,3 +605,27 @@ func TestFunctional(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Functional test suite", reporters)
}

func retrieveNodeArchitecture() string {
nodeList := &core.NodeList{}
err := apiClient.List(ctx, nodeList)
Expect(err).NotTo(HaveOccurred(), "Failed to list nodes")
nodes := nodeList.Items
Expect(nodes).NotTo(BeEmpty(), "No nodes found")
architecture := nodes[0].Status.NodeInfo.Architecture
Expect(architecture).To(BeElementOf([]string{"s390x", "amd64", "aarch64"}), "Unsupported architecture")
return architecture
}

func retrieveQemuMachineType() string {
switch retrieveNodeArchitecture() {
case "amd64":
return "q35"
case "s390x":
return "s390-ccw-virtio"
case "aarch64":
return "virt"
default:
return "virt"
}
}
52 changes: 26 additions & 26 deletions tests/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 2, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 2, clusterMachineType, "128M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand Down Expand Up @@ -492,7 +492,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRulesOptional()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 0, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 0, clusterMachineType, "128M")
vmi.Spec.Domain.CPU = nil
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
Expand All @@ -505,7 +505,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 0, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 0, clusterMachineType, "128M")
vmi.Spec.Domain.CPU = nil
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
Expand All @@ -518,7 +518,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithIncorrectRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 0, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 0, clusterMachineType, "128M")
vmi.Spec.Domain.CPU = nil
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
Expand All @@ -531,7 +531,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithIncorrectRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 0, "q35", "32M")
vmi = addDomainResourcesToVMI(vmi, 0, clusterMachineType, "32M")
vmi.Spec.Domain.CPU = nil
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
Expand All @@ -544,7 +544,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithIncorrectRulesJustWarning()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 0, "q35", "1G")
vmi = addDomainResourcesToVMI(vmi, 0, clusterMachineType, "1G")
vmi.Spec.Domain.CPU = nil
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
Expand All @@ -567,7 +567,7 @@ var _ = Describe("Template validator webhooks", func() {
}, env.ShortTimeout()).Should(BeTrue(), "Failed to find error msg in the logs")
})
It("[test_id:5591]test with partial annotations", func() {
vmi = addDomainResourcesToVMI(vmi, 2, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 2, clusterMachineType, "128M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
"vm.kubevirt.io/template-namespace": strategy.GetNamespace(),
Expand All @@ -578,7 +578,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 2, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 2, clusterMachineType, "128M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand All @@ -590,7 +590,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 2, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 2, clusterMachineType, "128M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Labels = map[string]string{
TemplateNameAnnotation: template.Name,
Expand All @@ -602,7 +602,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 0, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 0, clusterMachineType, "128M")
vmi.Spec.Domain.CPU = &kubevirtv1.CPU{
Sockets: 1,
}
Expand All @@ -620,7 +620,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithoutRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 1, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 1, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand All @@ -642,7 +642,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithoutRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 5, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 5, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand All @@ -664,7 +664,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 5, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 5, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand All @@ -686,7 +686,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).ToNot(HaveOccurred(), "Failed to create template: %s", template.Name)

vmi = addDomainResourcesToVMI(vmi, 5, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 5, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand All @@ -705,7 +705,7 @@ var _ = Describe("Template validator webhooks", func() {
eventuallyCreateVm(vm)
})
It("[test_id:5174]: VM with validations and deleted template", func() {
vmi = addDomainResourcesToVMI(vmi, 3, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 3, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: "nonexisting-vm-template",
Expand All @@ -724,7 +724,7 @@ var _ = Describe("Template validator webhooks", func() {
eventuallyCreateVm(vm)
})
It("[test_id:5046]: should override template rules and fail to create a VM based on the VM validation rules", func() {
vmi = addDomainResourcesToVMI(vmi, 5, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 5, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: "nonexisting-vm-template",
Expand All @@ -743,7 +743,7 @@ var _ = Describe("Template validator webhooks", func() {
eventuallyFailToCreateVm(vm)
})
It("[test_id:5047]: should fail to create a VM based on the VM validation rules", func() {
vmi = addDomainResourcesToVMI(vmi, 5, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 5, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
"vm.kubevirt.io/validations": `[
Expand All @@ -760,7 +760,7 @@ var _ = Describe("Template validator webhooks", func() {
eventuallyFailToCreateVm(vm)
})
It("[test_id:5175]: VM with validations without template", func() {
vmi = addDomainResourcesToVMI(vmi, 3, "q35", "64M")
vmi = addDomainResourcesToVMI(vmi, 3, clusterMachineType, "64M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
"vm.kubevirt.io/validations": `[
Expand Down Expand Up @@ -792,7 +792,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).To(Succeed())

vmi = addDomainResourcesToVMI(vmi, 2, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 2, clusterMachineType, "128M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand Down Expand Up @@ -828,7 +828,7 @@ var _ = Describe("Template validator webhooks", func() {
template = TemplateWithRules()
Expect(apiClient.Create(ctx, template)).To(Succeed())

vmi = addDomainResourcesToVMI(vmi, 2, "q35", "128M")
vmi = addDomainResourcesToVMI(vmi, 2, clusterMachineType, "128M")
vm = NewVirtualMachine(vmi)
vm.ObjectMeta.Annotations = map[string]string{
TemplateNameAnnotation: template.Name,
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func addObjectsToTemplates(genName, validation string) *templatev1.Template {
}

func TemplateWithRules() *templatev1.Template {
validations := `[
validations := fmt.Sprintf(`[
{
"name": "EnoughMemory",
"path": "jsonpath::.spec.domain.resources.requests.memory",
Expand All @@ -1099,9 +1099,9 @@ func TemplateWithRules() *templatev1.Template {
"path": "jsonpath::.spec.domain.machine.type",
"message": "Machine type is a supported value",
"rule": "enum",
"values": ["q35"]
"values": ["%s"]
}
]`
]`, clusterMachineType)
return addObjectsToTemplates("test-fedora-desktop-small-with-rules", validations)
}

Expand Down Expand Up @@ -1131,7 +1131,7 @@ func TemplateWithRulesOptional() *templatev1.Template {

func TemplateWithIncorrectRules() *templatev1.Template {
// Incorrect rule named 'value-set'
validations := `[
validations := fmt.Sprintf(`[
{
"name": "EnoughMemory",
"path": "jsonpath::.spec.domain.resources.requests.memory",
Expand All @@ -1144,9 +1144,9 @@ func TemplateWithIncorrectRules() *templatev1.Template {
"name": "SupportedChipset",
"path": "jsonpath::.spec.domain.machine.type",
"rule": "value-set",
"values": ["q35"]
"values": ["%s"]
}
]`
]`, clusterMachineType)
return addObjectsToTemplates("test-fedora-desktop-small-with-rules-incorrect", validations)
}

Expand Down

0 comments on commit 5d9489e

Please sign in to comment.