From 3de63d6fe666b0402c2411f3441112cb479b1790 Mon Sep 17 00:00:00 2001 From: Andrea Panattoni Date: Tue, 18 Jun 2024 17:22:04 +0200 Subject: [PATCH] e2e: Verify removing partial policy works Add an end-to-end test to verify removing a partial SriovNetworkNodePolicy does not trigger any issue in the operator's deployment. Refs: - https://issues.redhat.com/browse/OCPBUGS-34934 - https://github.com/k8snetworkplumbingwg/sriov-network-operator/pull/710 Signed-off-by: Andrea Panattoni --- .../tests/test_policy_configuration.go | 45 ++++++++++++++++++- test/conformance/tests/test_sriov_operator.go | 22 +++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/test/conformance/tests/test_policy_configuration.go b/test/conformance/tests/test_policy_configuration.go index b2159d88c..d01ec3a0a 100644 --- a/test/conformance/tests/test_policy_configuration.go +++ b/test/conformance/tests/test_policy_configuration.go @@ -23,7 +23,7 @@ import ( "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/pod" ) -var _ = Describe("[sriov] operator", func() { +var _ = Describe("[sriov] operator", Ordered, func() { var sriovInfos *cluster.EnabledNodes BeforeAll(func() { @@ -387,7 +387,50 @@ var _ = Describe("[sriov] operator", func() { err = clients.Create(context.Background(), secondConfig) Expect(err).To(HaveOccurred()) }) + + // https://issues.redhat.com/browse/OCPBUGS-34934 + It("Should be possible to delete a vfio-pci policy", func() { + vfioNode, vfioNic := sriovInfos.FindOneVfioSriovDevice() + if vfioNode == "" { + Skip("skip test as no vfio-pci capable PF was found") + } + By("Using device " + vfioNic.Name + " on node " + vfioNode) + + By("Creating a vfio-pci policy") + vfiopolicy, err := network.CreateSriovPolicy(clients, "test-policy-", operatorNamespace, vfioNic.Name+"#0-1", vfioNode, 5, "resvfiopci", "vfio-pci") + Expect(err).ToNot(HaveOccurred()) + + By("Creating a netdevice policy") + _, err = network.CreateSriovPolicy(clients, "test-policy-", operatorNamespace, vfioNic.Name+"#2-4", vfioNode, 5, "resnetdevice", "netdevice") + Expect(err).ToNot(HaveOccurred()) + + By("Checking the SriovNetworkNodeState is correctly configured") + assertNodeStateHasVFMatching(vfioNode, + Fields{"VfID": Equal(0), "Driver": Equal("vfio-pci")}) + assertNodeStateHasVFMatching(vfioNode, + Fields{"VfID": Equal(1), "Driver": Equal("vfio-pci")}) + assertNodeStateHasVFMatching(vfioNode, + Fields{"VfID": Equal(2), "Name": Not(BeEmpty())}) + + By("Deleting the vfio-pci policy") + err = clients.Delete(context.Background(), vfiopolicy) + Expect(err).ToNot(HaveOccurred()) + + By("Checking the SriovNetworkNodeState is consistently stable") + Eventually(cluster.SriovStable). + WithTimeout(10*time.Second). + WithPolling(1*time.Second). + WithArguments(operatorNamespace, clients). + Should(BeTrue()) + + Eventually(cluster.SriovStable). + WithTimeout(5*time.Second). + WithPolling(1*time.Second). + WithArguments(operatorNamespace, clients). + Should(BeTrue()) + }) }) + Context("Main PF", func() { It("should work when vfs are used by pods", func() { if !discovery.Enabled() { diff --git a/test/conformance/tests/test_sriov_operator.go b/test/conformance/tests/test_sriov_operator.go index 6c99df9a0..f7f236035 100644 --- a/test/conformance/tests/test_sriov_operator.go +++ b/test/conformance/tests/test_sriov_operator.go @@ -2269,3 +2269,25 @@ func waitForNetAttachDef(name, namespace string) { return clients.Get(context.Background(), runtimeclient.ObjectKey{Name: name, Namespace: namespace}, netAttDef) }, (10+snoTimeoutMultiplier*110)*time.Second, 1*time.Second).ShouldNot(HaveOccurred()) } + +// assertNodeStateHasVFMatching asserts that the given node state has at least one VF matching the given fields +func assertNodeStateHasVFMatching(nodeName string, fields Fields) { + EventuallyWithOffset(1, func(g Gomega) sriovv1.InterfaceExts { + nodeState, err := clients.SriovNetworkNodeStates(operatorNamespace).Get(context.Background(), nodeName, metav1.GetOptions{}) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(nodeState.Status.SyncStatus).To(Equal("Succeeded")) + return nodeState.Status.Interfaces + }, 3*time.Minute, 1*time.Second). + Should( + ContainElement( + MatchFields( + IgnoreExtras, + Fields{ + "VFs": ContainElement( + MatchFields(IgnoreExtras, fields), + ), + }, + ), + ), + ) +}