From 8261babae297eff119c6113c9a1904c3b5a067d9 Mon Sep 17 00:00:00 2001 From: Andrea Panattoni Date: Mon, 29 Jan 2024 10:18:15 +0100 Subject: [PATCH] e2e: Skip tests when no VF-IO devices are available Test cases in ``` ... Create vfio-pci node policy Should be possible to create a vfio-pci resource ... PF Partitioning Should be possible to partition the pf's vfs ``` should be skipped if there are no available SR-IOV devices in the cluster that support vfio-pci mode. Make `ExternallyManaged Validation` test cases don't need vfio-pci devices. Use a the function `FindOneSriovNodeAndDevice()` to less striclty discover NICs. Refs: - https://github.com/k8snetworkplumbingwg/sriov-network-operator/commit/aeb60e2f64aa6f61d74613c68a3f7ba7cc520e3d Signed-off-by: Andrea Panattoni --- test/conformance/tests/test_sriov_operator.go | 24 +++++++++++-------- test/util/cluster/cluster.go | 19 +++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/test/conformance/tests/test_sriov_operator.go b/test/conformance/tests/test_sriov_operator.go index 444ae259d..98b608dc6 100644 --- a/test/conformance/tests/test_sriov_operator.go +++ b/test/conformance/tests/test_sriov_operator.go @@ -983,7 +983,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) }) @@ -1020,20 +1022,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()) @@ -1938,14 +1940,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) }) diff --git a/test/util/cluster/cluster.go b/test/util/cluster/cluster.go index fdf06bdf7..0a439185b 100644 --- a/test/util/cluster/cluster.go +++ b/test/util/cluster/cluster.go @@ -2,6 +2,7 @@ package cluster import ( "context" + "errors" "fmt" "io" "os" @@ -180,6 +181,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 {