Skip to content

Commit

Permalink
Add powersupply failures to machine issues
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Oct 4, 2024
1 parent 5c5411d commit ebd27f6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cmd/metal-api/internal/issues/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,39 @@ func TestFindIssues(t *testing.T) {
}
},
},
{
name: "powersupply failure",
only: []Type{TypePowerSupplyFailure},
machines: func() metal.Machines {
noPartitionMachine := machineTemplate("power-supply-failure")
noPartitionMachine.IPMI = metal.IPMI{
PowerSupplies: metal.PowerSupplies{
{Status: metal.PowerSupplyStatus{Health: "NO-OK", State: "Absent"}},
},
}

return metal.Machines{
noPartitionMachine,
machineTemplate("good"),
}
},
eventContainers: func() metal.ProvisioningEventContainers {
return metal.ProvisioningEventContainers{
eventContainerTemplate("power-supply-failure"),
eventContainerTemplate("good"),
}
},
want: func(machines metal.Machines) MachineIssues {
return MachineIssues{
{
Machine: &machines[0],
Issues: Issues{
toIssue(&issuePowerSupplyFailure{details: "Health:NO-OK State:Absent"}),
},
},
}
},
},
{
name: "liveliness dead",
only: []Type{TypeLivelinessDead},
Expand Down
40 changes: 40 additions & 0 deletions cmd/metal-api/internal/issues/powersupply-failure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package issues

import (
"fmt"

"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"
)

const (
TypePowerSupplyFailure Type = "powersupply-failure"
)

type (
issuePowerSupplyFailure struct {
details string
}
)

func (i *issuePowerSupplyFailure) Spec() *spec {
return &spec{
Type: TypePowerSupplyFailure,
Severity: SeverityMajor,
Description: "machine has power supply failures",
RefURL: "https://docs.metal-stack.io/stable/installation/troubleshoot/#power-supply-failure",
}
}

func (i *issuePowerSupplyFailure) Evaluate(m metal.Machine, ec metal.ProvisioningEventContainer, c *Config) bool {
for _, ps := range m.IPMI.PowerSupplies {
if ps.Status.Health != "OK" || ps.Status.State != "Enabled" {
i.details = fmt.Sprintf("Health:%s State:%s", ps.Status.Health, ps.Status.State)
return true
}
}
return false
}

func (i *issuePowerSupplyFailure) Details() string {
return i.details
}
3 changes: 3 additions & 0 deletions cmd/metal-api/internal/issues/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func AllIssueTypes() []Type {
TypeASNUniqueness,
TypeNonDistinctBMCIP,
TypeNoEventContainer,
TypePowerSupplyFailure,
}
}

Expand Down Expand Up @@ -52,6 +53,8 @@ func NewIssueFromType(t Type) (issue, error) {
return &issueNonDistinctBMCIP{}, nil
case TypeNoEventContainer:
return &issueNoEventContainer{}, nil
case TypePowerSupplyFailure:
return &issuePowerSupplyFailure{}, nil
default:
return nil, fmt.Errorf("unknown issue type: %s", t)
}
Expand Down

0 comments on commit ebd27f6

Please sign in to comment.