v0.171.0: disk-health card device-model label (pairs with agent v0.95.0)

agentapi.SmartSummary.ModelName mirrors the agent's model_name; the card row label
prefers the device model over the raw name/UUID, falling back to Name(+hint) on an
old agent. Additive. Test + red-proof (drop fallback -> A4 fails).
This commit is contained in:
2026-07-25 08:23:30 +02:00
parent de14eedb9f
commit f6a8249593
4 changed files with 42 additions and 3 deletions
+5
View File
@@ -75,6 +75,11 @@ func isPhysicalDisk(d agentapi.DiskInfo) bool {
// diskDisplayLabel is the customer-facing disk label (PVE name + a Hungarian speed hint when known).
func diskDisplayLabel(d agentapi.DiskInfo) string {
// Prefer the device model (agent v0.95.0) over the raw storage name/UUID — a customer reads
// "TOSHIBA MQ04ABF100", not "47a3361a-…". Falls back to Name (+ speed hint) on an older agent.
if d.Smart != nil && d.Smart.ModelName != nil && *d.Smart.ModelName != "" {
return *d.Smart.ModelName
}
switch d.Class {
case "fast":
return d.Name + " (gyors)"
@@ -167,3 +167,27 @@ func TestCachedDisks_TTL(t *testing.T) {
t.Errorf("two fetches within the TTL should call the agent once, got %d", calls)
}
}
func sptr(s string) *string { return &s }
// v0.171.0: the card label prefers the device model (agent v0.95.0) over the raw name/UUID; it falls
// back to Name (+ speed hint) on an older agent or a modelless disk.
// Red-proof: drop the fallback (always return ModelName) → the nil-model/old-agent cases return "" and
// TestDiskDisplayLabel_PrefersModel fails (A4 — old-payload tolerance).
func TestDiskDisplayLabel_PrefersModel(t *testing.T) {
withModel := agentapi.DiskInfo{Name: "47a3361a-uuid", Class: "slow",
Smart: &agentapi.SmartSummary{Health: agentapi.SmartPassed, ModelName: sptr("TOSHIBA MQ04ABF100")}}
if got := diskDisplayLabel(withModel); got != "TOSHIBA MQ04ABF100" {
t.Errorf("label = %q, want the model name", got)
}
// A4: an old (v0.94.0) agent carries no model → Name (+ speed hint), byte-identical to before.
oldAgent := agentapi.DiskInfo{Name: "local", Class: "fast",
Smart: &agentapi.SmartSummary{Health: agentapi.SmartUnknown}}
if got := diskDisplayLabel(oldAgent); got != "local (gyors)" {
t.Errorf("old-agent label = %q, want 'local (gyors)'", got)
}
// No SMART at all → bare Name.
if got := diskDisplayLabel(agentapi.DiskInfo{Name: "sdb"}); got != "sdb" {
t.Errorf("nil-smart label = %q, want 'sdb'", got)
}
}