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
5 changes: 4 additions & 1 deletion container/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ func (m deviceIdentifierMap) Find(major, minor uint64, namer DeviceNamer) string
if s, ok := m[d]; ok {
return s
}
s, _ := namer.DeviceName(major, minor)
s, ok := namer.DeviceName(major, minor)
if !ok || s == "" {
s = fmt.Sprintf("%d:%d", major, minor)
}
m[d] = s
return s
}
Expand Down
37 changes: 37 additions & 0 deletions container/common/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,43 @@ func (m *mockInfoProvider) GetMachineInfo() (*info.MachineInfo, error) {
}, nil
}

type mockDeviceNamer map[deviceIdentifier]string

func (m mockDeviceNamer) DeviceName(major, minor uint64) (string, bool) {
name, ok := m[deviceIdentifier{major: major, minor: minor}]
return name, ok
}

func TestAssignDeviceNamesToDiskStatsFallsBackToMajorMinor(t *testing.T) {
diskIo := info.DiskIoStats{
IoServiced: []info.PerDiskStats{
{Major: 8, Minor: 1},
{Major: 253, Minor: 0},
{Major: 253, Minor: 1},
{Major: 1, Minor: 2},
},
}
namer := mockDeviceNamer{
{major: 8, minor: 1}: "sda1",
{major: 1, minor: 2}: "",
}

AssignDeviceNamesToDiskStats(namer, &diskIo)

if got, want := diskIo.IoServiced[0].Device, "sda1"; got != want {
t.Errorf("resolved device = %q, want %q", got, want)
}
if got, want := diskIo.IoServiced[1].Device, "253:0"; got != want {
t.Errorf("unresolved device = %q, want %q", got, want)
}
if got, want := diskIo.IoServiced[2].Device, "253:1"; got != want {
t.Errorf("unresolved device = %q, want %q", got, want)
}
if got, want := diskIo.IoServiced[3].Device, "1:2"; got != want {
t.Errorf("empty resolved device = %q, want %q", got, want)
}
}

func TestGetSpecCgroupV1(t *testing.T) {
root, err := os.Getwd()
if err != nil {
Expand Down