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

[controller] Ensure partUUID is used in Block Device name generation #20

Merged
merged 1 commit into from
Feb 1, 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
9 changes: 9 additions & 0 deletions images/agent/pkg/controller/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,18 @@ func GetBlockDeviceCandidates(log logger.Logger, cfg config.Options, metrics mon
log.Warning(fmt.Sprintf("[GetBlockDeviceCandidates] Type = part and cannot get PartUUID; skipping this device, path: %s", candidate.Path))
continue
}
log.Info(fmt.Sprintf("[GetBlockDeviceCandidates] Type = part and PartUUID is not empty; using PartUUID as serial number, path: %s", candidate.Path))
candidate.Serial = candidate.PartUUID
} else {
serial, err := GetSerial(log, candidate)
if err != nil {
log.Warning(fmt.Sprintf("[GetBlockDeviceCandidates] Unable to obtain serial number or its equivalent; skipping device: %s. Error: %s", candidate.Path, err))
continue
}
log.Info(fmt.Sprintf("[GetBlockDeviceCandidates] Successfully obtained serial number or its equivalent: %s for device: %s", serial, candidate.Path))
candidate.Serial = serial
}
log.Trace(fmt.Sprintf("[GetBlockDeviceCandidates] Serial number is now: %s", candidate.Serial))
}

candidate.Name = CreateUniqDeviceName(candidate)
Expand Down Expand Up @@ -453,8 +457,10 @@ func GetSerial(log logger.Logger, candidate internal.BlockDeviceCandidate) (stri
log.Error(err, "[GetSerial] unable to regexp.MatchString. Trying to get serial from device")
serial, err = readSerialBlockDevice(candidate.Path)
} else if matched {
log.Trace("[GetSerial] device is mdraid")
serial, err = readUUIDmdRaidBlockDevice(candidate.Path)
} else {
log.Trace("[GetSerial] device is not mdraid")
serial, err = readSerialBlockDevice(candidate.Path)
}

Expand Down Expand Up @@ -491,6 +497,9 @@ func readUUIDmdRaidBlockDevice(deviceName string) (string, error) {
if err != nil {
return "", fmt.Errorf("unable to read uuid from mdraid block device: %s, error: %s", deviceName, err)
}
if len(uuid) == 0 {
return "", fmt.Errorf("uuid of mdraid block device is empty")
}
return string(uuid), nil
}

Expand Down
98 changes: 96 additions & 2 deletions images/agent/pkg/controller/block_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestBlockDeviceCtrl(t *testing.T) {
testLsblkOutputBytes := []byte(testLsblkOutput)
devices, err := utils.UnmarshalDevices(testLsblkOutputBytes)
if assert.NoError(t, err) {
assert.Equal(t, 19, len(devices))
assert.Equal(t, 26, len(devices))
}
filteredDevices, err := FilterDevices(*log, devices)

Expand All @@ -231,11 +231,14 @@ func TestBlockDeviceCtrl(t *testing.T) {
case 3:
assert.Equal(t, "/dev/nvme5n1", device.Name)
assert.True(t, CheckConsumable(device))
case 4:
assert.Equal(t, "/dev/sda4", device.Name)
assert.False(t, CheckConsumable(device))
}

}
if assert.NoError(t, err) {
assert.Equal(t, 4, len(filteredDevices))
assert.Equal(t, 5, len(filteredDevices))
}
})

Expand Down Expand Up @@ -492,6 +495,97 @@ var (
"wwn": "0x6006",
"kname": "/dev/sda1",
"pkname": "/dev/sda"
},{
"name": "/dev/sda",
"mountpoint": null,
"partuuid": null,
"hotplug": false,
"model": "INTEL SSDSC2KB48",
"serial": "PHYS729000AS480BGN",
"size": "447.1G",
"fstype": null,
"type": "disk",
"wwn": "0x55cd2e414e193b8c",
"kname": "/dev/sda",
"pkname": null
},{
"name": "/dev/sda1",
"mountpoint": "/boot/efi",
"partuuid": "e2ac92cc-6a34-4402-a253-40533a3fc877",
"hotplug": false,
"model": null,
"serial": null,
"size": "1G",
"fstype": "vfat",
"type": "part",
"wwn": "0x55cd2e414e193b8c",
"kname": "/dev/sda1",
"pkname": "/dev/sda"
},{
"name": "/dev/sda2",
"mountpoint": null,
"partuuid": "e95db4fa-99b4-42c4-9dc4-ff5459557801",
"hotplug": false,
"model": null,
"serial": null,
"size": "1G",
"fstype": "linux_raid_member",
"type": "part",
"wwn": "0x55cd2e414e193b8c",
"kname": "/dev/sda2",
"pkname": "/dev/sda"
},{
"name": "/dev/sda3",
"mountpoint": null,
"partuuid": "ed7633b6-f3ef-4b4a-86f8-48c0180de78f",
"hotplug": false,
"model": null,
"serial": null,
"size": "55G",
"fstype": "linux_raid_member",
"type": "part",
"wwn": "0x55cd2e414e193b8c",
"kname": "/dev/sda3",
"pkname": "/dev/sda"
},{
"name": "/dev/sda4",
"mountpoint": null,
"partuuid": "6f1d599d-9f91-41c5-9616-69709cf30b9d",
"hotplug": false,
"model": null,
"serial": null,
"size": "390.1G",
"fstype": "LVM2_member",
"type": "part",
"wwn": "0x55cd2e414e193b8c",
"kname": "/dev/sda4",
"pkname": "/dev/sda"
},{
"name": "/dev/mapper/data--linstor-pvc--9671a7f4--8997--4630--a728--2cd6f915c19b_00000",
"mountpoint": null,
"partuuid": null,
"hotplug": false,
"model": null,
"serial": null,
"size": "30G",
"fstype": null,
"type": "lvm",
"wwn": null,
"kname": "/dev/dm-18",
"pkname": "/dev/sda4"
},{
"name": "/dev/drbd1028",
"mountpoint": null,
"partuuid": null,
"hotplug": false,
"model": null,
"serial": null,
"size": "50G",
"fstype": null,
"type": "disk",
"wwn": null,
"kname": "/dev/drbd1028",
"pkname": "/dev/dm-10"
}
]
}`
Expand Down
Loading