Skip to content
Closed
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
17 changes: 14 additions & 3 deletions pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,26 @@ func GetMigUUIDFromSmiOutput(output string, uuid string, idx int) string {
continue
}
klog.Infoln("inspecting", val)
num := strings.Split(val, "Device")[1]
deviceParts := strings.Split(val, "Device")
if len(deviceParts) < 2 {
klog.Warningf("unexpected MIG output format, missing Device delimiter: %q", val)
continue
}
num := deviceParts[1]
num = strings.Split(num, ":")[0]
num = strings.TrimSpace(num)
index, err := strconv.Atoi(num)
if err != nil {
klog.Fatal("atoi failed num=", num)
klog.Warningf("failed to parse MIG device index %q: %v", num, err)
continue
}
if index == idx {
outputStr := strings.Split(val, ":")[2]
colonParts := strings.Split(val, ":")
if len(colonParts) < 3 {
klog.Warningf("unexpected MIG output format, missing colon fields: %q", val)
continue
}
outputStr := colonParts[2]
Comment on lines +178 to +183

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Parse and test the actual UUID field.

The parser selects the MIG profile field instead of the UUID field. The malformed fixture also exits during device-index parsing, so it cannot detect this defect.

  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go#L178-L183: extract the value after "UUID:", or validate four colon fields and select the UUID field.
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go#L993-L998: use a numeric device index with a missing UUID field so the test reaches the UUID-field validation.
📍 Affects 2 files
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go#L178-L183 (this comment)
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go#L993-L998
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go` around lines 178 -
183, Update the MIG output parsing around colonParts in
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go:178-183 to extract and
validate the actual UUID field after “UUID:” (or require four colon-separated
fields and select the UUID field), rather than using the profile field. Update
the malformed fixture in
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go:993-998 to use a
numeric device index with the UUID field missing, ensuring the test reaches UUID
validation.

outputStr = strings.TrimSpace(outputStr)
outputStr = strings.TrimRight(outputStr, ")")
return outputStr
Expand Down
91 changes: 91 additions & 0 deletions pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,94 @@ func TestWriteMigConfig_RemovesStaleFileOnFailure(t *testing.T) {
t.Errorf("expected stale config to be removed, stat err: %v", err)
}
}

func Test_GetMigUUIDFromSmiOutput(t *testing.T) {
tests := []struct {
name string
output string
uuid string
idx int
want string
}{
{
name: "valid MIG output",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Instance ID 0: (Device 0, Name: MIG 3g.20gb, UUID: MIG-uuid-0)
MIG 3g.20gb, Instance ID 1: (Device 1, Name: MIG 3g.20gb, UUID: MIG-uuid-1)`,
uuid: "GPU-abc123",
idx: 0,
want: "MIG-uuid-0",
},
{
name: "valid MIG output, second instance",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Instance ID 0: (Device 0, Name: MIG 3g.20gb, UUID: MIG-uuid-0)
MIG 3g.20gb, Instance ID 1: (Device 1, Name: MIG 3g.20gb, UUID: MIG-uuid-1)`,
uuid: "GPU-abc123",
idx: 1,
want: "MIG-uuid-1",
},
{
name: "empty output",
output: "",
uuid: "GPU-abc123",
idx: 0,
want: "",
},
{
name: "no MIG lines",
output: "GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)\n",
uuid: "GPU-abc123",
idx: 0,
want: "",
},
{
name: "MIG line without Device delimiter",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Instance ID 0: malformed line without Device`,
uuid: "GPU-abc123",
idx: 0,
want: "",
},
{
name: "MIG line without enough colons",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Device 0 only two colons`,
uuid: "GPU-abc123",
idx: 0,
want: "",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
{
name: "MIG line with non-numeric index",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Instance ID 0: (Device abc, Name: MIG 3g.20gb, UUID: MIG-uuid-0)`,
uuid: "GPU-abc123",
idx: 0,
want: "",
},
{
name: "uuid mismatch skips lines",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Instance ID 0: (Device 0, Name: MIG 3g.20gb, UUID: MIG-uuid-0)`,
uuid: "GPU-other",
idx: 0,
want: "",
},
{
name: "target index not found",
output: `GPU 0: NVIDIA A100-PCIE-40GB (UUID: GPU-abc123)
MIG 3g.20gb, Instance ID 0: (Device 0, Name: MIG 3g.20gb, UUID: MIG-uuid-0)`,
uuid: "GPU-abc123",
idx: 5,
want: "",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := GetMigUUIDFromSmiOutput(test.output, test.uuid, test.idx)
if got != test.want {
t.Errorf("GetMigUUIDFromSmiOutput() = %q, want %q", got, test.want)
}
})
}
}
Loading