From c668226576a8328f61013876deb90707512756f4 Mon Sep 17 00:00:00 2001 From: Marcelo Guerrero Date: Thu, 2 Nov 2023 13:28:54 +0100 Subject: [PATCH] Add test to verify reconciliation when VF status changes Signed-off-by: Marcelo Guerrero --- test/conformance/tests/test_sriov_operator.go | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/test/conformance/tests/test_sriov_operator.go b/test/conformance/tests/test_sriov_operator.go index a206bf4d9..d6f86f092 100644 --- a/test/conformance/tests/test_sriov_operator.go +++ b/test/conformance/tests/test_sriov_operator.go @@ -200,10 +200,13 @@ var _ = Describe("[sriov] operator", func() { discoveryFailed = node == "" || resourceName == "" || numVfs < 5 } else { node = sriovInfos.Nodes[0] - createVanillaNetworkPolicy(node, sriovInfos, numVfs, resourceName) + sriovDevice = createVanillaNetworkPolicy(node, sriovInfos, numVfs, resourceName) WaitForSRIOVStable() - sriovDevice, err = sriovInfos.FindOneSriovDevice(node) + + // Update info + sriovInfos, err = cluster.DiscoverSriov(clients, operatorNamespace) Expect(err).ToNot(HaveOccurred()) + sriovDevice = findInterface(sriovInfos, node) Eventually(func() int64 { testedNode, err := clients.CoreV1Interface.Nodes().Get(context.Background(), node, metav1.GetOptions{}) @@ -912,6 +915,24 @@ var _ = Describe("[sriov] operator", func() { return runningPodB.Status.Phase }, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning)) }) + + It("should reconcile managed VF if status changes", func() { + vf := sriovDevice.VFs[0] + mtu := vf.Mtu + + By("manually changing the MTU") + _, errOutput, err := runCommandOnConfigDaemon(node, "/bin/bash", "-c", fmt.Sprintf("echo 2000 > /sys/bus/pci/devices/%s/net/%s/mtu", vf.PciAddress, vf.Name)) + Expect(err).ToNot(HaveOccurred()) + Expect(errOutput).To(Equal("")) + + WaitForSRIOVStable() + + By("checking the virtual functions don't exist anymore on the system") + output, errOutput, err := runCommandOnConfigDaemon(node, "/bin/bash", "-c", fmt.Sprintf("cat /sys/bus/pci/devices/%s/net/%s/mtu", vf.PciAddress, vf.Name)) + Expect(err).ToNot(HaveOccurred()) + Expect(errOutput).To(Equal("")) + Expect(output).To(Equal(mtu)) + }) }) }) @@ -2288,7 +2309,7 @@ func WaitForSRIOVStable() { }, waitingTime, 1*time.Second).Should(BeTrue()) } -func createVanillaNetworkPolicy(node string, sriovInfos *cluster.EnabledNodes, numVfs int, resourceName string) { +func findInterface(sriovInfos *cluster.EnabledNodes, node string) *sriovv1.InterfaceExt { // For the context of tests is better to use a Mellanox card // as they support all the virtual function flags // if we don't find a Mellanox card we fall back to any sriov @@ -2299,6 +2320,12 @@ func createVanillaNetworkPolicy(node string, sriovInfos *cluster.EnabledNodes, n Expect(err).ToNot(HaveOccurred()) } + return intf +} + +func createVanillaNetworkPolicy(node string, sriovInfos *cluster.EnabledNodes, numVfs int, resourceName string) *sriovv1.InterfaceExt { + intf := findInterface(sriovInfos, node) + config := &sriovv1.SriovNetworkNodePolicy{ ObjectMeta: metav1.ObjectMeta{ GenerateName: "test-policy", @@ -2332,6 +2359,8 @@ func createVanillaNetworkPolicy(node string, sriovInfos *cluster.EnabledNodes, n "Name": Equal(intf.Name), "NumVfs": Equal(numVfs), }))) + + return intf } func runCommandOnConfigDaemon(nodeName string, command ...string) (string, string, error) {