Add support to get devlink resources

- Update nl package with new netlink attribute types and consts
- Define structs to model devlink device resources
- Add DevlinkGetDeviceResources method to return device resources
- Add basic test

Signed-off-by: adrianc <adrianc@nvidia.com>
This commit is contained in:
adrianc
2023-11-13 18:12:25 +02:00
committed by Alessandro Boch
parent 2bbba08be2
commit 36b61ad22c
3 changed files with 265 additions and 30 deletions

View File

@@ -1,3 +1,4 @@
//go:build linux
// +build linux
package netlink
@@ -262,3 +263,26 @@ func areInfoStructsEqual(first *DevlinkDeviceInfo, second *DevlinkDeviceInfo) bo
}
return true
}
func TestDevlinkGetDeviceResources(t *testing.T) {
minKernelRequired(t, 5, 11)
tearDown := setUpNetlinkTestWithKModule(t, "devlink")
defer tearDown()
if bus == "" || device == "" {
//TODO: setup netdevsim device instead of getting device from flags
t.Log("devlink bus and device are empty, skipping test")
t.SkipNow()
}
res, err := DevlinkGetDeviceResources(bus, device)
if err != nil {
t.Fatalf("failed to get device(%s/%s) resources. %s", bus, device, err)
}
if res.Bus != bus || res.Device != device {
t.Fatalf("missmatching bus/device")
}
t.Logf("Resources: %+v", res)
}