Skip to content

Commit

Permalink
est for switchdev mode
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Panattoni <[email protected]>
  • Loading branch information
zeeke committed Aug 12, 2024
1 parent 9f861e3 commit 2cbd67a
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ func createVanillaNetworkPolicy(node string, sriovInfos *cluster.EnabledNodes, n
})))
}

func runCommandOnConfigDaemon(nodeName string, command ...string) (string, string, error) {
func getConfigDaemonPod(nodeName string) *corev1.Pod {
pods := &corev1.PodList{}
label, err := labels.Parse("app=sriov-network-config-daemon")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -2020,8 +2020,13 @@ func runCommandOnConfigDaemon(nodeName string, command ...string) (string, strin
err = clients.List(context.Background(), pods, &runtimeclient.ListOptions{Namespace: operatorNamespace, LabelSelector: label, FieldSelector: field})
Expect(err).ToNot(HaveOccurred())
Expect(len(pods.Items)).To(Equal(1))
return &pods.Items[0]
}

func runCommandOnConfigDaemon(nodeName string, command ...string) (string, string, error) {

Check failure on line 2026 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

unnecessary leading newline (whitespace)

Check failure on line 2027 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

File is not `gofmt`-ed with `-s` (gofmt)

output, errOutput, err := pod.ExecCommand(clients, &pods.Items[0], command...)
output, errOutput, err := pod.ExecCommand(clients, getConfigDaemonPod(nodeName), command...)
return output, errOutput, err
}

Expand Down
88 changes: 88 additions & 0 deletions test/conformance/tests/test_switchdev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package tests

import (
"context"
"time"

Check failure on line 6 in test/conformance/tests/test_switchdev.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

File is not `goimports`-ed with -local github.com/k8snetworkplumbingwg/sriov-network-operator (goimports)
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/network"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("[sriov] Switchdev", Ordered, func() {

BeforeAll(func() {
if cluster.VirtualCluster() {
Skip("IGB driver does not support VF statistics")
}

err := namespaces.Create(namespaces.Test, clients)
Expect(err).ToNot(HaveOccurred())

err = namespaces.Clean(operatorNamespace, namespaces.Test, clients, discovery.Enabled())
Expect(err).ToNot(HaveOccurred())

WaitForSRIOVStable()
})

It("create switchdev policies on supported devices", func() {
sriovInfos, err := cluster.DiscoverSriov(clients, operatorNamespace)
Expect(err).ToNot(HaveOccurred())
Expect(len(sriovInfos.Nodes)).ToNot(BeZero())

testNode, interfaces, err := sriovInfos.FindSriovDevicesAndNode()
Expect(err).ToNot(HaveOccurred())

By("Testing on node " + testNode)

mainDevice := findMainSriovDevice(getConfigDaemonPod(testNode), interfaces)
Expect(mainDevice).ToNot(BeNil())

for _, intf := range interfaces {
if !doesInterfaceSupportSwitchdev(intf) {
continue
}

if intf.Name == mainDevice.Name {
// Avoid testing switchdev on main NIC
continue
}

By("Testing device " + intf.Name + " on node " + testNode)
resourceName := "swtichdev" + intf.Name
_, err = network.CreateSriovPolicy(clients, "test-switchdev-policy-", operatorNamespace, intf.Name, testNode, 8, resourceName, "netdevice", func(snnp *sriovv1.SriovNetworkNodePolicy) {
snnp.Spec.EswitchMode = "switchdev"
})
Expect(err).ToNot(HaveOccurred())

WaitForSRIOVStable()

Eventually(func() int64 {
testedNode, err := clients.CoreV1Interface.Nodes().Get(context.Background(), testNode, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
capacity, _ := resNum.AsInt64()
return capacity
}, 10*time.Minute, time.Second).Should(Equal(int64(8)))
}
})
})

func doesInterfaceSupportSwitchdev(intf *sriovv1.InterfaceExt) bool {
if intf.Driver == "mlx5_core" {
return true
}

if intf.Driver == "ice" {
return true
}

return false
}
28 changes: 28 additions & 0 deletions test/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ func (n *EnabledNodes) FindSriovDevices(node string) ([]*sriovv1.InterfaceExt, e
return filteredDevices, nil
}

// FindSriovDevicesAndNode retrieves the node with the most number of SRIOV devices after filtering by `SRIOV_NODE_AND_DEVICE_NAME_FILTER` environment variable.
func (n *EnabledNodes) FindSriovDevicesAndNode() (string, []*sriovv1.InterfaceExt, error ){

Check failure on line 157 in test/util/cluster/cluster.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

File is not `gofmt`-ed with `-s` (gofmt)
errs := []error{}

retNode := ""
retDevices := []*sriovv1.InterfaceExt{}


for _, node := range n.Nodes {
devices, err := n.FindSriovDevices(node)
if err != nil {
errs = append(errs, err)
continue
}

if len(devices) > len(retDevices) {
retNode = node
retDevices = devices
}
}

if len(retDevices) == 0 {
return "", nil, fmt.Errorf("can't find any SR-IOV devices in cluster's nodes: %w", errors.Join(errs...))
}

return retNode, retDevices, nil
}

// FindSriovDevicesIgnoreFilters retrieves all valid sriov devices for the given node.
func (n *EnabledNodes) FindSriovDevicesIgnoreFilters(node string) ([]*sriovv1.InterfaceExt, error) {
devices := []*sriovv1.InterfaceExt{}
Expand Down

0 comments on commit 2cbd67a

Please sign in to comment.