From 902ddd166b09206235070846d50a5624732fea8d Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Wed, 17 Apr 2024 18:29:56 +0200 Subject: [PATCH] providers/openbmc: verify hardware support in all methods This is to ensure the Openbmc provider executes code only on hardware identified to be Openbmc --- providers/openbmc/firmware.go | 4 ++++ providers/openbmc/openbmc.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/providers/openbmc/firmware.go b/providers/openbmc/firmware.go index d5fd492a..851ce040 100644 --- a/providers/openbmc/firmware.go +++ b/providers/openbmc/firmware.go @@ -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) } diff --git a/providers/openbmc/openbmc.go b/providers/openbmc/openbmc.go index 8e9cde11..556f698a 100644 --- a/providers/openbmc/openbmc.go +++ b/providers/openbmc/openbmc.go @@ -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 ( @@ -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) }