Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported check #388

Merged
merged 7 commits into from
Apr 18, 2024
4 changes: 4 additions & 0 deletions providers/asrockrack/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const (

// bmc client interface implementations methods
func (a *ASRockRack) FirmwareInstallSteps(ctx context.Context, component string) ([]constants.FirmwareInstallStep, error) {
if err := a.supported(ctx); err != nil {
return nil, bmclibErrs.NewErrUnsupportedHardware(err.Error())
}

switch strings.ToUpper(component) {
case common.SlugBMC:
return []constants.FirmwareInstallStep{
Expand Down
10 changes: 3 additions & 7 deletions providers/dell/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ import (
"github.com/stmcginnis/gofish/redfish"
)

var (
ErrUnsupportedHardware = errors.New("hardware not supported")
)

// bmc client interface implementations methods
func (c *Conn) FirmwareInstallSteps(ctx context.Context, component string) ([]constants.FirmwareInstallStep, error) {
if err := c.deviceSupported(ctx); err != nil {
return nil, errors.Wrap(ErrUnsupportedHardware, err.Error())
return nil, bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

return []constants.FirmwareInstallStep{
Expand All @@ -35,7 +31,7 @@ func (c *Conn) FirmwareInstallSteps(ctx context.Context, component string) ([]co

func (c *Conn) FirmwareInstallUploadAndInitiate(ctx context.Context, component string, file *os.File) (taskID string, err error) {
if err := c.deviceSupported(ctx); err != nil {
return "", errors.Wrap(ErrUnsupportedHardware, err.Error())
return "", bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

// // expect atleast 5 minutes left in the deadline to proceed with the upload
Expand Down Expand Up @@ -102,7 +98,7 @@ 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 "", "", errors.Wrap(ErrUnsupportedHardware, err.Error())
return "", "", bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

// Dell jobs are turned into Redfish tasks on the idrac
Expand Down
25 changes: 25 additions & 0 deletions providers/dell/idrac.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"strings"

bmcliberrs "github.com/bmc-toolbox/bmclib/v2/errors"
"github.com/bmc-toolbox/bmclib/v2/internal/httpclient"
"github.com/bmc-toolbox/bmclib/v2/internal/redfishwrapper"
"github.com/bmc-toolbox/bmclib/v2/providers"
Expand Down Expand Up @@ -204,21 +205,37 @@ func (c *Conn) Compatible(ctx context.Context) bool {

// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This provider already has this check in Open. I'm not following the value add for putting this in all these individual methods. As far as I can tell deviceSupported doesnt do any method specific checks either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out, you're right the dell, openbmc checks were redundant.

I noticed dell showing up as a successfulProvider on another device - which was odd, but I haven't been able to reproduce the case, and theres no way it should end up in there. Changes reverted.

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)
}

Expand All @@ -239,6 +256,10 @@ func (c *Conn) ResetBiosConfiguration(ctx context.Context) (err error) {

// 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)
}

Expand All @@ -259,6 +280,10 @@ func (c *Conn) deviceManufacturer(ctx context.Context) (vendor string, err error
}

func (c *Conn) Screenshot(ctx context.Context) (image []byte, fileType string, err error) {
if err := c.deviceSupported(ctx); err != nil {
return nil, "", bmcliberrs.NewErrUnsupportedHardware(err.Error())
}

fileType = "png"

resp, err := c.redfishwrapper.PostWithHeaders(
Expand Down
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)
}
Loading