Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression where non-raid attached disks did not determine correct disk type #133

Merged
merged 2 commits into from
Feb 22, 2024
Merged
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
33 changes: 33 additions & 0 deletions linux/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,39 @@ func TestGetAttachType(t *testing.T) {
}))
}

func TestGetDiskType(t *testing.T) {
assert := assert.New(t)
systemVirtType = virtKvm
result, err := getDiskType(disko.UdevInfo{
Name: "vdb",
SysPath: "/devices/pci0000:00/0000:00:03.0/virtio1/block/vdb",
Properties: map[string]string{
"DEVLINKS": "/dev/disk/by-path/pci-0000:00:03.0 /dev/disk/by-path/virtio-pci-0000:00:03.0 /dev/disk/by-id/virtio-ssd-disk0-ssd",
"DEVNAME": "/dev/vdb",
"DEVPATH": "/devices/pci0000:00/0000:00:03.0/virtio1/block/vdb",
"DEVTYPE": "disk",
"DISKSEQ": "42",
"ID_PATH": "pci-0000:00:03.0",
"ID_PATH_TAG": "pci-0000_00_03_0",
"ID_SERIAL": "ssd-disk0-ssd",
"MAJOR": "253",
"MINOR": "16",
"SUBSYSTEM": "block",
"USEC_INITIALIZED": "2422574",
},
Symlinks: []string{
"disk/by-diskseq/42",
"disk/by-path/pci-0000:00:03.0",
"disk/by-path/virtio-pci-0000:00:03.0",
"disk/by-id/virtio-ssd-disk0-ssd",
},
})
if err != nil {
t.Errorf("expected err = nil, got %s", err)
}
assert.Equal(disko.SSD.String(), result.String())
}

func genTempGptDisk(tmpd string, fsize uint64) (disko.Disk, error) {
fpath := path.Join(tmpd, "mydisk")

Expand Down
8 changes: 8 additions & 0 deletions linux/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@
}
}

// check disk type if it wasn't on raid
if attachType != disko.RAID {
diskType, err = getDiskType(udInfo)
if err != nil {
return disko.Disk{}, fmt.Errorf("error while getting disk type: %s", err)

Check warning on line 183 in linux/system.go

View check run for this annotation

Codecov / codecov/patch

linux/system.go#L183

Added line #L183 was not covered by tests
}
}

ro, err = getDiskReadOnly(name)
if err != nil {
return disko.Disk{}, err
Expand Down
Loading