Skip to content

Commit

Permalink
providers/openbmc: verify hardware support in all methods
Browse files Browse the repository at this point in the history
This is to ensure the Openbmc provider executes code only on hardware
identified to be Openbmc
  • Loading branch information
joelrebel committed Apr 17, 2024
1 parent 82d4c11 commit 902ddd1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions providers/openbmc/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ func (c *Conn) checkQueueability(component string, tasks []*redfish.Task) error

// FirmwareTaskStatus returns the status of a firmware related task queued on the BMC.
func (c *Conn) FirmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string) (state constants.TaskState, status string, err error) {
if err := c.deviceSupported(ctx); err != nil {
return "", "", bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return c.redfishwrapper.TaskStatus(ctx, taskID)
}
22 changes: 22 additions & 0 deletions providers/openbmc/openbmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/go-logr/logr"
"github.com/jacobweinstock/registrar"
"github.com/pkg/errors"

bmcliberrs "github.com/bmc-toolbox/bmclib/v2/errors"
)

const (
Expand Down Expand Up @@ -167,25 +169,45 @@ func (c *Conn) Name() string {

// PowerStateGet gets the power state of a BMC machine
func (c *Conn) PowerStateGet(ctx context.Context) (state string, err error) {
if err := c.deviceSupported(ctx); err != nil {
return "", bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return c.redfishwrapper.SystemPowerStatus(ctx)
}

// PowerSet sets the power state of a server
func (c *Conn) PowerSet(ctx context.Context, state string) (ok bool, err error) {
if err := c.deviceSupported(ctx); err != nil {
return false, bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return c.redfishwrapper.PowerSet(ctx, state)
}

// Inventory collects hardware inventory and install firmware information
func (c *Conn) Inventory(ctx context.Context) (device *common.Device, err error) {
if err := c.deviceSupported(ctx); err != nil {
return nil, bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return c.redfishwrapper.Inventory(ctx, false)
}

// BmcReset power cycles the BMC
func (c *Conn) BmcReset(ctx context.Context, resetType string) (ok bool, err error) {
if err := c.deviceSupported(ctx); err != nil {
return false, bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return c.redfishwrapper.BMCReset(ctx, resetType)
}

// SendNMI tells the BMC to issue an NMI to the device
func (c *Conn) SendNMI(ctx context.Context) error {
if err := c.deviceSupported(ctx); err != nil {
return bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return c.redfishwrapper.SendNMI(ctx)
}

0 comments on commit 902ddd1

Please sign in to comment.