diff --git a/test/util/cluster/cluster.go b/test/util/cluster/cluster.go index d5b9895ca..adbc19537 100644 --- a/test/util/cluster/cluster.go +++ b/test/util/cluster/cluster.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "io" + "os" + "regexp" "strings" "time" @@ -92,33 +94,48 @@ func DiscoverSriov(clients *testclient.ClientSet, operatorNamespace string) (*En // FindOneSriovDevice retrieves a valid sriov device for the given node. func (n *EnabledNodes) FindOneSriovDevice(node string) (*sriovv1.InterfaceExt, error) { - s, ok := n.States[node] + ret, err := n.FindSriovDevices(node) + if err != nil { + return nil, err + } + + if len(ret) == 0 { + return nil, fmt.Errorf("unable to find sriov devices in node %s", node) + } + + return ret[0], nil +} + +// FindSriovDevices retrieves all valid sriov devices for the given node, filtered by `SRIOV_DEVICE_NAME_FILTER` environment variable. +func (n *EnabledNodes) FindSriovDevices(node string) ([]*sriovv1.InterfaceExt, error) { + devices, err := n.FindSriovDevicesIgnoreFilters(node) + if err != nil { + return nil, err + } + + sriovDeviceNameFilter, ok := os.LookupEnv("SRIOV_DEVICE_NAME_FILTER") if !ok { - return nil, fmt.Errorf("node %s not found", node) + return devices, nil } - for _, itf := range s.Status.Interfaces { - if IsPFDriverSupported(itf.Driver) && sriovv1.IsSupportedDevice(itf.DeviceID) { - // Skip mlx interfaces if secure boot is enabled - // TODO: remove this when mlx support secure boot/lockdown mode - if itf.Vendor == mlxVendorID && n.IsSecureBootEnabled[node] { - continue - } - // if the sriov is not enable in the kernel for intel nic the totalVF will be 0 so we skip the device - // That is not the case for Mellanox devices that will report 0 until we configure the sriov interfaces - // with the mstconfig package - if itf.Vendor == intelVendorID && itf.TotalVfs == 0 { - continue - } + filteredDevices := []*sriovv1.InterfaceExt{} + for _, device := range devices { - return &itf, nil + match, err := regexp.MatchString(sriovDeviceNameFilter, device.Name) + if err != nil { + return nil, err + } + + if match { + filteredDevices = append(filteredDevices, device) } } - return nil, fmt.Errorf("unable to find sriov devices in node %s", node) + + return filteredDevices, nil } // FindSriovDevices retrieves all valid sriov devices for the given node. -func (n *EnabledNodes) FindSriovDevices(node string) ([]*sriovv1.InterfaceExt, error) { +func (n *EnabledNodes) FindSriovDevicesIgnoreFilters(node string) ([]*sriovv1.InterfaceExt, error) { devices := []*sriovv1.InterfaceExt{} s, ok := n.States[node] if !ok {