Skip to content

Commit

Permalink
MGMT-19150: publish md devices (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
giladravid16 authored Nov 17, 2024
1 parent a8a3349 commit a0b1057
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/inventory/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func (d *disks) isLVM(disk *ghw.Disk) bool {
return d.dmUUIDHasPrefix(disk, "LVM-")
}

func isMultipleDevices(disk *ghw.Disk) bool {
return strings.HasPrefix(disk.Name, "md")
}

// Return true if the specified disk belongs
// to an openshift-appliance node
func (d *disks) isAppliance(disk *ghw.Disk) bool {
Expand Down Expand Up @@ -334,7 +338,7 @@ func (d *disks) isHiddenDevice(disk *ghw.Disk) bool {
// be eligible. Also returns whether the disk appears to be an installation
// media or not.
func (d *disks) checkEligibility(disk *ghw.Disk) (notEligibleReasons []string, isInstallationMedia bool) {
if disk.StorageController == ghw.STORAGE_CONTROLLER_UNKNOWN && !d.isMultipath(disk) && !d.isLVM(disk) && !d.isDASD(disk) {
if disk.StorageController == ghw.STORAGE_CONTROLLER_UNKNOWN && !d.isMultipath(disk) && !d.isLVM(disk) && !d.isDASD(disk) && !isMultipleDevices(disk) {
notEligibleReasons = append(notEligibleReasons, "Disk has unknown storage controller")
}

Expand Down Expand Up @@ -396,8 +400,7 @@ func (d *disks) shouldReturnDisk(disk *block.Disk) bool {
return !(d.isHiddenDevice(disk) || // Disk is marked as hidden by sysfs
(strings.HasPrefix(disk.Name, "dm-") && !(d.isMultipath(disk) || d.isLVM(disk))) || // Device mapper devices, except multipath/LVM
strings.HasPrefix(disk.Name, "loop") || // Loop devices (see `man loop`)
strings.HasPrefix(disk.Name, "zram") || // Default name usually assigned to "swap on ZRAM" block devices
strings.HasPrefix(disk.Name, "md")) // Linux multiple-device-driver block devices
strings.HasPrefix(disk.Name, "zram")) // Default name usually assigned to "swap on ZRAM" block devices
}

func (d *disks) getDriveType(disk *block.Disk) models.DriveType {
Expand All @@ -414,6 +417,8 @@ func (d *disks) getDriveType(disk *block.Disk) models.DriveType {
driveType = models.DriveTypeMultipath
} else if d.isLVM(disk) {
driveType = models.DriveTypeLVM
} else if isMultipleDevices(disk) {
driveType = models.DriveTypeRAID
} else if diskString == ghw.DRIVE_TYPE_FDD.String() {
driveType = models.DriveTypeFDD
} else if diskString == ghw.DRIVE_TYPE_HDD.String() {
Expand Down
61 changes: 57 additions & 4 deletions src/inventory/disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ func createDeviceMapperDisk() *ghw.Disk {
}
}

func createMultipleDevicesDisk() *ghw.Disk {
return &ghw.Disk{
Name: "md-0",
SizeBytes: 21474836480,
DriveType: ghw.DRIVE_TYPE_UNKNOWN,
BusPath: "unknown",
Vendor: "unknown",
Model: "unknown",
SerialNumber: "unknown",
WWN: "unknown",
IsRemovable: false,
NUMANodeID: 0,
PhysicalBlockSizeBytes: 512,
StorageController: ghw.STORAGE_CONTROLLER_UNKNOWN,
}
}

const devDiskByIdLocation = "/dev/disk/by-id"
const sdaWwn = "wwn-0x6141877064533b0020adf3bb03167694"
const sdaPath = "/dev/sda"
Expand Down Expand Up @@ -476,12 +493,11 @@ var _ = Describe("Disks test", func() {

It("Invalid disks", func() {
zramDisk := createDisk("zram0", 4, "6141877064533b0020adf3bc0325d665", "0x6141877064533b0020adf3bc0325d665")
mdDisk := createDisk("md-1", 5, "6141877064533b0020adf3bc0325d667", "0x6141877064533b0020adf3bc0325d667")
loopDisk := createDisk("loop5", 6, "6141877064533b0020adf3bc0325d668", "0x6141877064533b0020adf3bc0325d668")
hiddenDisk := createDisk("hidden", 7, "6141877064533b0020adf3bc0325d668", "0x6141877064533b0020adf3bc0325d669")
loopDisk := createDisk("loop5", 5, "6141877064533b0020adf3bc0325d668", "0x6141877064533b0020adf3bc0325d668")
hiddenDisk := createDisk("hidden", 6, "6141877064533b0020adf3bc0325d668", "0x6141877064533b0020adf3bc0325d669")

mockReadDir(dependencies, "/dev/disk/by-id", "fetching the by-id disk failed")
mockAllForSuccess(dependencies, createSDADisk(), createSDBDisk(), zramDisk, mdDisk, loopDisk, hiddenDisk)
mockAllForSuccess(dependencies, createSDADisk(), createSDBDisk(), zramDisk, loopDisk, hiddenDisk)

ret := GetDisks(&config.SubprocessConfig{}, dependencies)
Expect(ret).Should(HaveLen(2))
Expand Down Expand Up @@ -1167,6 +1183,43 @@ var _ = Describe("Disks test", func() {
}))
})

It("MultipleDevices device", func() {
mockGetWWNCallForSuccess(dependencies, make(map[string]string))
path := "/dev/md-0"
disk := createMultipleDevicesDisk()
mockFetchDisks(dependencies, nil, disk)
mockGetPathFromDev(dependencies, disk.Name, "")
mockGetHctl(dependencies, disk.Name, "error")
mockGetBootable(dependencies, path, true, "")
mockNoUUID(dependencies, path)
mockReadDir(dependencies, fmt.Sprintf("/sys/block/%s/holders", disk.Name), "")
dependencies.On("ReadFile", fmt.Sprintf("/sys/block/%s/hidden", disk.Name)).Return([]byte("0\n"), nil)

ret := GetDisks(&config.SubprocessConfig{}, dependencies)

Expect(ret).To(Equal([]*models.Disk{
{
ID: "/dev/md-0",
ByPath: "",
DriveType: models.DriveTypeRAID,
Hctl: "",
Model: "",
Name: "md-0",
Path: "/dev/md-0",
Serial: "",
SizeBytes: 21474836480,
Vendor: "",
Wwn: "",
Bootable: true,
Smart: "",
Holders: "",
InstallationEligibility: models.DiskInstallationEligibility{
Eligible: true,
},
},
}))
})

It("LVM device", func() {
mockGetWWNCallForSuccess(dependencies, make(map[string]string))
path := "/dev/dm-2"
Expand Down

0 comments on commit a0b1057

Please sign in to comment.