From 487d0feaf1cf37788af444dfed31728c89b87219 Mon Sep 17 00:00:00 2001 From: Aleksandr Zimin Date: Thu, 1 Feb 2024 17:57:29 +0300 Subject: [PATCH] [controller] Ensure partUUID is used in Block Device name generation (#20) Signed-off-by: Aleksandr Zimin --- images/agent/pkg/controller/block_device.go | 9 ++ .../agent/pkg/controller/block_device_test.go | 98 ++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/images/agent/pkg/controller/block_device.go b/images/agent/pkg/controller/block_device.go index dd739da8..9322ffd6 100644 --- a/images/agent/pkg/controller/block_device.go +++ b/images/agent/pkg/controller/block_device.go @@ -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) @@ -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) } @@ -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 } diff --git a/images/agent/pkg/controller/block_device_test.go b/images/agent/pkg/controller/block_device_test.go index 8df14375..c11d7dd9 100644 --- a/images/agent/pkg/controller/block_device_test.go +++ b/images/agent/pkg/controller/block_device_test.go @@ -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) @@ -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)) } }) @@ -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" } ] }`