From efdf3e5fa33602f0a78b97238b54adfe64db526e Mon Sep 17 00:00:00 2001 From: Tobias Giese Date: Fri, 19 Jul 2024 17:01:33 +0200 Subject: [PATCH] e2e: fix e2e test for the sriovnetworknodepolicy We have to verify only the VF range we have specified. If not we will expect VFs to have certain values that have not been synced by the controller. --- test/e2e/sriovoperatornodepolicy_test.go | 38 ++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/test/e2e/sriovoperatornodepolicy_test.go b/test/e2e/sriovoperatornodepolicy_test.go index 10eb86589..ccd965708 100644 --- a/test/e2e/sriovoperatornodepolicy_test.go +++ b/test/e2e/sriovoperatornodepolicy_test.go @@ -215,6 +215,29 @@ var _ = Describe("Operator", func() { }, }, } + policy3 := &sriovnetworkv1.SriovNetworkNodePolicy{ + TypeMeta: metav1.TypeMeta{ + Kind: "SriovNetworkNodePolicy", + APIVersion: "sriovnetwork.openshift.io/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "policy-1", + Namespace: testNamespace, + }, + Spec: sriovnetworkv1.SriovNetworkNodePolicySpec{ + ResourceName: "resource_1", + NodeSelector: map[string]string{ + "feature.node.kubernetes.io/network-sriov.capable": "true", + }, + Priority: 99, + Mtu: 9000, + NumVfs: 6, + NicSelector: sriovnetworkv1.SriovNetworkNicSelector{ + PfNames: []string{"#2-4"}, + }, + DeviceType: "vfio-pci", + }, + } JustBeforeEach(func() { By("wait for the node state ready") @@ -257,6 +280,9 @@ var _ = Describe("Operator", func() { err = WaitForDaemonSetReady(dpDaemonSet, k8sClient, testNamespace, "sriov-device-plugin", RetryInterval, Timeout) Expect(err).NotTo(HaveOccurred()) + pfName, rngStart, rngEnd, err := sriovnetworkv1.ParseVfRange(policy.Spec.NicSelector.PfNames[0]) + Expect(err).NotTo(HaveOccurred()) + By("update the spec of SriovNetworkNodeState CR") found := false for _, address := range policy.Spec.NicSelector.RootDevices { @@ -268,8 +294,6 @@ var _ = Describe("Operator", func() { Expect(iface.VfGroups[0].DeviceType).To(Equal(policy.Spec.DeviceType)) Expect(iface.VfGroups[0].ResourceName).To(Equal(policy.Spec.ResourceName)) - pfName, rngStart, rngEnd, err := sriovnetworkv1.ParseVfRange(policy.Spec.NicSelector.PfNames[0]) - Expect(err).NotTo(HaveOccurred()) rng := strconv.Itoa(rngStart) + "-" + strconv.Itoa(rngEnd) Expect(iface.Name).To(Equal(pfName)) Expect(iface.VfGroups[0].VfRange).To(Equal(rng)) @@ -287,7 +311,10 @@ var _ = Describe("Operator", func() { Expect(iface.NumVfs).To(Equal(policy.Spec.NumVfs)) Expect(iface.Mtu).To(Equal(policy.Spec.Mtu)) Expect(len(iface.VFs)).To(Equal(policy.Spec.NumVfs)) - for _, vf := range iface.VFs { + for i, vf := range iface.VFs { + if i < rngStart || rngEnd < i { + continue + } if policy.Spec.DeviceType == "netdevice" || policy.Spec.DeviceType == "" { Expect(vf.Mtu).To(Equal(policy.Spec.Mtu)) } @@ -301,8 +328,9 @@ var _ = Describe("Operator", func() { } Expect(found).To(BeTrue()) }, - Entry("Set one PF with VF range", policy1), - Entry("Set one PF with VF range", policy2), + Entry("Set one vfio PF with VF range #0-5", policy1), + Entry("Set one netdevice PF with VF range #0-0", policy2), + Entry("Set one vfio PF with VF range #2-4", policy3), ) })