Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/platform-support/dgpu/dgpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func NewForDevice(d device.Device, opts ...Option) (discover.Discover, error) {
var errs error
nvsandboxutilsDiscoverer, err := o.newNvsandboxutilsDGPUDiscoverer(d)
if err != nil {
// TODO: Log a warning
o.logger.Warningf("Failed to create nvsandboxutils device discoverer: %v", err)
errs = errors.Join(errs, err)
} else if nvsandboxutilsDiscoverer != nil {
discoverers = append(discoverers, nvsandboxutilsDiscoverer)
}

nvmlDiscoverer, err := o.newNvmlDGPUDiscoverer(&toRequiredInfo{d})
if err != nil {
// TODO: Log a warning
o.logger.Warningf("Failed to create NVML device discoverer: %v", err)
errs = errors.Join(errs, err)
} else if nvmlDiscoverer != nil {
discoverers = append(discoverers, nvmlDiscoverer)
Expand Down Expand Up @@ -82,7 +82,7 @@ func NewForMigDevice(d device.Device, mig device.MigDevice, opts ...Option) (dis
var errs error
nvsandboxutilsDiscoverer, err := o.newNvsandboxutilsDGPUDiscoverer(mig)
if err != nil {
// TODO: Log a warning
o.logger.Warningf("Failed to create nvsandboxutils MIG device discoverer: %v", err)
errs = errors.Join(errs, err)
} else if nvsandboxutilsDiscoverer != nil {
discoverers = append(discoverers, nvsandboxutilsDiscoverer)
Expand All @@ -95,7 +95,7 @@ func NewForMigDevice(d device.Device, mig device.MigDevice, opts ...Option) (dis
},
)
if err != nil {
// TODO: Log a warning
o.logger.Warningf("Failed to create NVML MIG device discoverer: %v", err)
errs = errors.Join(errs, err)
} else if nvmlDiscoverer != nil {
discoverers = append(discoverers, nvmlDiscoverer)
Expand Down
52 changes: 52 additions & 0 deletions internal/platform-support/dgpu/nvml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml/mock"
"github.com/sirupsen/logrus"
testlog "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"

"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root"
"github.com/NVIDIA/nvidia-container-toolkit/internal/nvcaps"
mocknvsandboxutils "github.com/NVIDIA/nvidia-container-toolkit/internal/nvsandboxutils/mock"
)

// TODO: In order to properly test this, we need a mechanism to inject /
Expand Down Expand Up @@ -238,3 +240,53 @@ func newNvmlMigDiscovererTestMocks() (parent *mock.Device, mig *mock.Device) {

return parent, mig
}

func TestNewForDeviceLogsDiscovererErrors(t *testing.T) {
log, hook := testlog.NewNullLogger()
devicelib := device.New(&mock.Interface{})
dev, err := devicelib.NewDevice(&mock.Device{
GetUUIDFunc: func() (string, nvml.Return) { return "", nvml.ERROR_NOT_SUPPORTED },
GetMinorNumberFunc: func() (int, nvml.Return) { return 0, nvml.ERROR_NOT_SUPPORTED },
})
require.NoError(t, err)

_, err = NewForDevice(dev,
WithLogger(log),
WithDriver(root.New()),
WithNvsandboxuitilsLib(&mocknvsandboxutils.Interface{}),
)
require.Error(t, err)
require.Len(t, hook.Entries, 2)
require.Equal(t, logrus.WarnLevel, hook.Entries[0].Level)
require.Equal(t, logrus.WarnLevel, hook.Entries[1].Level)
require.Contains(t, hook.Entries[0].Message, "nvsandboxutils device discoverer: failed to get device UUID")
require.Contains(t, hook.Entries[1].Message, "NVML device discoverer: error getting device node path")
}

func TestNewForMigDeviceLogsDiscovererErrors(t *testing.T) {
log, hook := testlog.NewNullLogger()
devicelib := device.New(&mock.Interface{})
parentMock, migMock := newNvmlMigDiscovererTestMocks()
parentMock.GetMinorNumberFunc = func() (int, nvml.Return) { return 0, nvml.ERROR_NOT_SUPPORTED }
migMock.GetUUIDFunc = func() (string, nvml.Return) { return "", nvml.ERROR_NOT_SUPPORTED }
migMock.GetDeviceHandleFromMigDeviceHandleFunc = func() (nvml.Device, nvml.Return) {
return parentMock, nvml.SUCCESS
}
parent, err := devicelib.NewDevice(parentMock)
require.NoError(t, err)
mig, err := devicelib.NewMigDevice(migMock)
require.NoError(t, err)

_, err = NewForMigDevice(parent, mig,
WithLogger(log),
WithDriver(root.New()),
WithMIGCaps(nvcaps.MigCaps{}),
WithNvsandboxuitilsLib(&mocknvsandboxutils.Interface{}),
)
require.Error(t, err)
require.Len(t, hook.Entries, 2)
require.Equal(t, logrus.WarnLevel, hook.Entries[0].Level)
require.Equal(t, logrus.WarnLevel, hook.Entries[1].Level)
require.Contains(t, hook.Entries[0].Message, "nvsandboxutils MIG device discoverer: failed to get device UUID")
require.Contains(t, hook.Entries[1].Message, "NVML MIG device discoverer: error getting GPU device minor number")
}