Skip to content

Commit

Permalink
Merge pull request #596 from zeeke/us-28248
Browse files Browse the repository at this point in the history
e2e: Skip tests when no VF-IO devices are available
  • Loading branch information
adrianchiris authored Feb 1, 2024
2 parents 0eb0a14 + 9026a2d commit a3a5ba9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
24 changes: 14 additions & 10 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,9 @@ var _ = Describe("[sriov] operator", func() {
}

vfioNode, vfioNic = sriovInfos.FindOneVfioSriovDevice()
Expect(vfioNode).ToNot(Equal(""))
if vfioNode == "" {
Skip("skip test as no vfio-pci capable PF was found")
}
By("Using device " + vfioNic.Name + " on node " + vfioNode)
})

Expand Down Expand Up @@ -1108,20 +1110,20 @@ var _ = Describe("[sriov] operator", func() {
})

Context("PF Partitioning", func() {
var vfioNode string
var vfioNic sriovv1.InterfaceExt

// 27633
BeforeEach(func() {
if discovery.Enabled() {
Skip("Test unsuitable to be run in discovery mode")
}
vfioNode, vfioNic = sriovInfos.FindOneVfioSriovDevice()
Expect(vfioNode).ToNot(Equal(""))
By("Using device " + vfioNic.Name + " on node " + vfioNode)
})

It("Should be possible to partition the pf's vfs", 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)

_, err := network.CreateSriovPolicy(clients, "test-policy-", operatorNamespace, vfioNic.Name+"#2-4", vfioNode, 5, testResourceName, "netdevice")
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -2026,14 +2028,16 @@ var _ = Describe("[sriov] operator", func() {
Context("ExternallyManaged Validation", func() {
numVfs := 5
var node string
var nic sriovv1.InterfaceExt
var nic *sriovv1.InterfaceExt
externallyManage := func(policy *sriovv1.SriovNetworkNodePolicy) {
policy.Spec.ExternallyManaged = true
}

execute.BeforeAll(func() {
node, nic = sriovInfos.FindOneVfioSriovDevice()
Expect(node).ToNot(Equal(""))
var err error
node, nic, err = sriovInfos.FindOneSriovNodeAndDevice()
Expect(err).ToNot(HaveOccurred())

By("Using device " + nic.Name + " on node " + node)
})

Expand Down
19 changes: 19 additions & 0 deletions test/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cluster

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -181,6 +182,24 @@ func (n *EnabledNodes) FindSriovDevicesIgnoreFilters(node string) ([]*sriovv1.In
return devices, nil
}

// FindOneSriovNodeAndDevice finds a cluster node with one SR-IOV devices respecting the `SRIOV_NODE_AND_DEVICE_NAME_FILTER` filter.
func (n *EnabledNodes) FindOneSriovNodeAndDevice() (string, *sriovv1.InterfaceExt, error) {
errs := []error{}
for _, node := range n.Nodes {
devices, err := n.FindSriovDevices(node)
if err != nil {
errs = append(errs, err)
continue
}

if len(devices) > 0 {
return node, devices[0], nil
}
}

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

// FindOneVfioSriovDevice retrieves a node with a valid sriov device for vfio
func (n *EnabledNodes) FindOneVfioSriovDevice() (string, sriovv1.InterfaceExt) {
for _, node := range n.Nodes {
Expand Down

0 comments on commit a3a5ba9

Please sign in to comment.