rdma: fix flaky tests that assume hardcoded device name

TestRdmaGetRdmaLink, TestRdmaSetRdmaLinkName, and TestRdmaLinkSetNsFd
hardcode the RDMA device name "foo". When ib_core is loaded but no
device named "foo" exists, these tests fail instead of skipping.

Replace the hardcoded name with a helper that lists available RDMA
devices and uses the first one, or skips the test if none are found.

Also skip TestRdmaLinkSetNsFd when switching to exclusive netns mode
fails with "device or resource busy", which happens when RDMA devices
are actively in use on the CI runner.

Signed-off-by: Ihar Hrachyshka <ihrachyshka@nvidia.com>
Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ihar Hrachyshka
2026-02-25 10:35:42 -05:00
committed by Alessandro Boch
parent 4e69fae463
commit c909b3a66f
+20 -16
View File
@@ -27,10 +27,23 @@ func setupRdmaKModule(t *testing.T, name string) {
t.Skipf("Test requires kmodule %q.", name)
}
func firstRdmaDevice(t *testing.T) *RdmaLink {
t.Helper()
links, err := RdmaLinkList()
if err != nil {
t.Fatal(err)
}
if len(links) == 0 {
t.Skip("No RDMA devices available")
}
return links[0]
}
func TestRdmaGetRdmaLink(t *testing.T) {
minKernelRequired(t, 4, 16)
setupRdmaKModule(t, "ib_core")
_, err := RdmaLinkByName("foo")
link := firstRdmaDevice(t)
_, err := RdmaLinkByName(link.Attrs.Name)
if err != nil {
t.Fatal(err)
}
@@ -39,17 +52,15 @@ func TestRdmaGetRdmaLink(t *testing.T) {
func TestRdmaSetRdmaLinkName(t *testing.T) {
minKernelRequired(t, 4, 19)
setupRdmaKModule(t, "ib_core")
link, err := RdmaLinkByName("foo")
if err != nil {
t.Fatal(err)
}
link := firstRdmaDevice(t)
origName := link.Attrs.Name
// Set new name
err = RdmaLinkSetName(link, "bar")
err := RdmaLinkSetName(link, "bar")
if err != nil {
t.Fatal(err)
}
// Revert back to old name
err = RdmaLinkSetName(link, "foo")
err = RdmaLinkSetName(link, origName)
if err != nil {
t.Fatal(err)
}
@@ -114,7 +125,7 @@ func TestRdmaLinkSetNsFd(t *testing.T) {
t.Log("current rdma netns mode", mode)
err = RdmaSystemSetNetnsMode("exclusive")
if err != nil {
t.Fatal(err)
t.Skipf("Failed to set RDMA netns mode to exclusive: %v", err)
}
basens, err := netns.Get()
if err != nil {
@@ -130,14 +141,7 @@ func TestRdmaLinkSetNsFd(t *testing.T) {
}
netns.Set(basens)
link, err := RdmaLinkByName("foo")
if err != nil {
// Remove the namespace as RDMA subsystem requires
// no namespace to exist when changing net namespace mode
newns.Close()
RdmaSystemSetNetnsMode(mode)
t.Fatal(err)
}
link := firstRdmaDevice(t)
t.Log("rdma link: ", link)
err = RdmaLinkSetNsFd(link, uint32(newns))