Skip to content

Commit

Permalink
Add test to verify reconciliation when VF status changes
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Guerrero <marguerr@redhat.com>
  • Loading branch information
mlguerrero12 committed Nov 2, 2023
1 parent 98150f5 commit c668226
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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))
})
})
})

Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c668226

Please sign in to comment.