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

fine tune logic to filter disks #857

Merged
merged 1 commit into from
Oct 9, 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
4 changes: 3 additions & 1 deletion pkg/console/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,11 @@ func identifyUniqueDisks(output []byte) ([]string, error) {
if !ok {
dedupMap[disk.Serial] = disk
}
continue
}

// disks may have same serial number but different wwn when used with a raid array
// as evident in test data from a host with a raid array
// in this case if serial number is same, we still check for unique wwn
if disk.WWN != "" {
_, ok := dedupMap[disk.WWN]
if !ok {
Expand Down
129 changes: 129 additions & 0 deletions pkg/console/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,128 @@ const (
]
}
`
raidDisks = `{
"blockdevices": [
{
"name": "loop0",
"size": "780.5M",
"type": "loop",
"wwn": null,
"serial": null
},{
"name": "sda",
"size": "447.1G",
"type": "disk",
"wwn": "0x600508b1001cec28a12a38168f7bb195",
"serial": "PDNMF0ARH1614W",
"children": [
{
"name": "3600508b1001cec28a12a38168f7bb195",
"size": "447.1G",
"type": "mpath",
"wwn": null,
"serial": null
}
]
},{
"name": "sdb",
"size": "447.1G",
"type": "disk",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": "PDNMF0ARH1614W",
"children": [
{
"name": "sdb1",
"size": "1M",
"type": "part",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": null
},{
"name": "sdb2",
"size": "50M",
"type": "part",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": null
},{
"name": "sdb3",
"size": "8G",
"type": "part",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": null
},{
"name": "sdb4",
"size": "15G",
"type": "part",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": null
},{
"name": "sdb5",
"size": "170G",
"type": "part",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": null
},{
"name": "sdb6",
"size": "254G",
"type": "part",
"wwn": "0x600508b1001c3e956986e526698cd830",
"serial": null
},{
"name": "3600508b1001c3e956986e526698cd830",
"size": "447.1G",
"type": "mpath",
"wwn": null,
"serial": null,
"children": [
{
"name": "3600508b1001c3e956986e526698cd830-part1",
"size": "1M",
"type": "part",
"wwn": null,
"serial": null
},{
"name": "3600508b1001c3e956986e526698cd830-part2",
"size": "50M",
"type": "part",
"wwn": null,
"serial": null
},{
"name": "3600508b1001c3e956986e526698cd830-part3",
"size": "8G",
"type": "part",
"wwn": null,
"serial": null
},{
"name": "3600508b1001c3e956986e526698cd830-part4",
"size": "15G",
"type": "part",
"wwn": null,
"serial": null
},{
"name": "3600508b1001c3e956986e526698cd830-part5",
"size": "170G",
"type": "part",
"wwn": null,
"serial": null
},{
"name": "3600508b1001c3e956986e526698cd830-part6",
"size": "254G",
"type": "part",
"wwn": null,
"serial": null
}
]
}
]
},{
"name": "sr0",
"size": "1024M",
"type": "rom",
"wwn": null,
"serial": "475652914613"
}
]
}`
)

func Test_identifyUniqueDisksWithSerialNumber(t *testing.T) {
Expand All @@ -609,3 +731,10 @@ func Test_identifyUniqueDisksOnExistingInstalls(t *testing.T) {
assert.NoError(err, "expected no error while parsing disk data")
assert.Len(result, 1, "expected to find 1 disk only")
}

func Test_identifyUniqueDisks(t *testing.T) {
assert := require.New(t)
out, err := identifyUniqueDisks([]byte(raidDisks))
assert.NoError(err, "expected no error while parsing disk data")
t.Log(out)
}
Loading