From 0fd08d48fe500f66818e3861c2ddb42798fce157 Mon Sep 17 00:00:00 2001 From: Tony Nguyen <91400591+truongbo17@users.noreply.github.com> Date: Fri, 2 Oct 2026 11:12:51 +0700 Subject: [PATCH] fix: log dGPU discoverer initialization errors Signed-off-by: Tony Nguyen <91400591+truongbo17@users.noreply.github.com> --- internal/platform-support/dgpu/dgpu.go | 8 ++-- internal/platform-support/dgpu/nvml_test.go | 52 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/internal/platform-support/dgpu/dgpu.go b/internal/platform-support/dgpu/dgpu.go index 190154662..192ec84b9 100644 --- a/internal/platform-support/dgpu/dgpu.go +++ b/internal/platform-support/dgpu/dgpu.go @@ -39,7 +39,7 @@ 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) @@ -47,7 +47,7 @@ func NewForDevice(d device.Device, opts ...Option) (discover.Discover, error) { 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) @@ -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) @@ -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) diff --git a/internal/platform-support/dgpu/nvml_test.go b/internal/platform-support/dgpu/nvml_test.go index db0a299a4..7d2598379 100644 --- a/internal/platform-support/dgpu/nvml_test.go +++ b/internal/platform-support/dgpu/nvml_test.go @@ -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 / @@ -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") +}