feat(models): resolve CPU serial from source PPIN as common fallback
Centralize CPU identity in models.ResolveCPUSerialNumber: an explicit source serial wins, otherwise a valid source PPIN is used, placeholders rejected. Dell, H3C and Redfish apply it while parsing; canonical-device and Reanimator conversion apply it again at the output boundary. No identity is synthesized from socket/model/board serial. See ADL-058. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
9d701885da
commit
07c270cda2
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
import "strings"
|
||||
|
||||
// ResolveCPUSerialNumber returns a source-backed processor inventory identity.
|
||||
// A vendor-provided serial number has priority; PPIN is the documented CPU
|
||||
// serial identity and is used when a separate serial number is unavailable.
|
||||
func ResolveCPUSerialNumber(serialNumber, ppin string) string {
|
||||
if serial := validCPUIdentity(serialNumber); serial != "" {
|
||||
return serial
|
||||
}
|
||||
return validCPUIdentity(ppin)
|
||||
}
|
||||
|
||||
func validCPUIdentity(value string) string {
|
||||
value = strings.TrimSpace(value)
|
||||
switch strings.ToLower(value) {
|
||||
case "", "-", "n/a", "na", "none", "null", "unknown", "not available", "to be filled by o.e.m.":
|
||||
return ""
|
||||
default:
|
||||
return value
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestResolveCPUSerialNumber(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
serial string
|
||||
ppin string
|
||||
want string
|
||||
}{
|
||||
{name: "serial has priority", serial: "CPU-SERIAL", ppin: "D46E5D6B1D3E40E1", want: "CPU-SERIAL"},
|
||||
{name: "PPIN fallback", ppin: " D46E5D6B1D3E40E1 ", want: "D46E5D6B1D3E40E1"},
|
||||
{name: "placeholder serial falls back", serial: "Unknown", ppin: "D44F8D6B9155EE0E", want: "D44F8D6B9155EE0E"},
|
||||
{name: "placeholder PPIN rejected", ppin: "N/A", want: ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ResolveCPUSerialNumber(tt.serial, tt.ppin); got != tt.want {
|
||||
t.Fatalf("ResolveCPUSerialNumber(%q, %q) = %q, want %q", tt.serial, tt.ppin, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user