Skip to content

Commit

Permalink
providers/supermicro: define a bmcQueryor interface and implement for…
Browse files Browse the repository at this point in the history
… x11, x12

based on feedback recieved this approach made more sense
  • Loading branch information
joelrebel committed Nov 10, 2023
1 parent 3a43b92 commit 370e066
Show file tree
Hide file tree
Showing 11 changed files with 585 additions and 516 deletions.
1 change: 1 addition & 0 deletions providers/supermicro/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var (
ErrQueryFRUInfo = errors.New("FRU information query returned error")
ErrXMLAPIUnsupported = errors.New("XML API is unsupported")
ErrModelUnknown = errors.New("Model number unknown")
ErrModelUnsupported = errors.New("Model not supported")
)

type UnexpectedResponseError struct {
Expand Down
62 changes: 10 additions & 52 deletions providers/supermicro/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,16 @@ var (
)

// bmc client interface implementations methods

func (c *Client) FirmwareInstallSteps(ctx context.Context, component string) ([]constants.FirmwareInstallStep, error) {
if err := c.firmwareInstallSupported(ctx); err != nil {
if err := c.serviceClient.supportsFirmwareInstall(ctx, c.bmc.deviceModel()); err != nil {
return nil, err
}

switch {
case strings.HasPrefix(strings.ToLower(c.model), "x12"):
return c.x12().firmwareInstallSteps(component)
case strings.HasPrefix(strings.ToLower(c.model), "x11"):
return c.x11().firmwareInstallSteps(component)
}

return nil, errors.Wrap(errUnexpectedModel, c.model)
return c.bmc.firmwareInstallSteps(component)
}

func (c *Client) FirmwareUpload(ctx context.Context, component string, file *os.File) (taskID string, err error) {
if err := c.firmwareInstallSupported(ctx); err != nil {
if err := c.serviceClient.supportsFirmwareInstall(ctx, c.bmc.deviceModel()); err != nil {
return "", err
}

Expand All @@ -60,62 +52,28 @@ func (c *Client) FirmwareUpload(ctx context.Context, component string, file *os.
return "", errors.New("remaining context deadline insufficient to perform update: " + time.Until(d).String())
}

switch {
case strings.HasPrefix(strings.ToLower(c.model), "x12"):
return c.x12().firmwareUpload(ctx, component, file)
case strings.HasPrefix(strings.ToLower(c.model), "x11"):
return c.x11().firmwareUpload(ctx, component, file)
}

return "", errors.Wrap(errUnexpectedModel, c.model)
return c.bmc.firmwareUpload(ctx, component, file)
}

func (c *Client) FirmwareInstallUploaded(ctx context.Context, component, uploadTaskID string) (installTaskID string, err error) {
if err := c.firmwareInstallSupported(ctx); err != nil {
if err := c.serviceClient.supportsFirmwareInstall(ctx, c.bmc.deviceModel()); err != nil {
return "", err
}

if uploadTaskID == "" {
// x11's don't return a upload Task ID, since the upload mechanism is not redfish
if !strings.HasPrefix(c.bmc.deviceModel(), "x11") && uploadTaskID == "" {
return "", errUploadTaskIDExpected
}

switch {
case strings.HasPrefix(strings.ToLower(c.model), "x12"):
return c.x12().firmwareInstallUploaded(ctx, component, uploadTaskID)
case strings.HasPrefix(strings.ToLower(c.model), "x11"):
return "", c.x11().firmwareInstallUploaded(ctx, component)
}

return "", errors.Wrap(errUnexpectedModel, c.model)

return c.bmc.firmwareInstallUploaded(ctx, component, uploadTaskID)
}

// FirmwareTaskStatus returns the status of a firmware related task queued on the BMC.
func (c *Client) FirmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string) (state, status string, err error) {
if err := c.firmwareInstallSupported(ctx); err != nil {
if err := c.serviceClient.supportsFirmwareInstall(ctx, c.bmc.deviceModel()); err != nil {
return "", "", errors.Wrap(bmclibErrs.ErrFirmwareInstallStatus, err.Error())
}

component = strings.ToUpper(component)

if strings.HasPrefix(strings.ToLower(c.model), "x12") {
return c.x12().firmwareTaskStatus(ctx, component, taskID)
} else if strings.HasPrefix(strings.ToLower(c.model), "x11") {
return c.x11().firmwareTaskStatus(ctx, component)

}

return "", "", errors.Wrap(errUnexpectedModel, c.model)
}

func (c *Client) firmwareInstallSupported(ctx context.Context) error {
errBoardUnsupported := errors.New("firmware install not supported/implemented for device model")

for _, s := range supportedModels {
if strings.EqualFold(s, c.model) {
return nil
}
}

return errBoardUnsupported
return c.bmc.firmwareTaskStatus(ctx, component, taskID)
}
15 changes: 11 additions & 4 deletions providers/supermicro/firmware_bios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"testing"

"github.com/bmc-toolbox/bmclib/v2/internal/httpclient"
"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -79,8 +80,11 @@ func Test_setComponentUpdateMisc(t *testing.T) {
t.Fatal(err)
}

client := NewClient(parsedURL.Hostname(), "foo", "bar", logr.Discard(), WithPort(parsedURL.Port()))
if err := client.x11().checkComponentUpdateMisc(context.Background(), tc.stage); err != nil {
serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

if err := client.checkComponentUpdateMisc(context.Background(), tc.stage); err != nil {
if tc.errorContains != "" {
assert.ErrorContains(t, err, tc.errorContains)

Expand Down Expand Up @@ -165,8 +169,11 @@ func Test_setBIOSFirmwareInstallMode(t *testing.T) {
t.Fatal(err)
}

client := NewClient(parsedURL.Hostname(), "foo", "bar", logr.Discard(), WithPort(parsedURL.Port()))
if err := client.x11().setBMCFirmwareInstallMode(context.Background()); err != nil {
serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

if err := client.setBMCFirmwareInstallMode(context.Background()); err != nil {
if tc.errorContains != "" {
assert.ErrorContains(t, err, tc.errorContains)

Expand Down
8 changes: 4 additions & 4 deletions providers/supermicro/floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Client) floppyImageMounted(ctx context.Context) (bool, error) {
return false, err
}

inserted, err := c.redfish.InsertedVirtualMedia(ctx)
inserted, err := c.serviceClient.redfish.InsertedVirtualMedia(ctx)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *Client) MountFloppyImage(ctx context.Context, image io.Reader) error {
},
{
name: "csrf-token",
data: bytes.NewBufferString(c.csrfToken),
data: bytes.NewBufferString(c.serviceClient.csrfToken),
},
}

Expand Down Expand Up @@ -103,7 +103,7 @@ func (c *Client) MountFloppyImage(ctx context.Context, image io.Reader) error {
}
payloadWriter.Close()

resp, statusCode, err := c.query(
resp, statusCode, err := c.serviceClient.query(
ctx,
"cgi/uimapin.cgi",
http.MethodPost,
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c *Client) UnmountFloppyImage(ctx context.Context) error {
return nil
}

resp, statusCode, err := c.query(
resp, statusCode, err := c.serviceClient.query(
ctx,
"cgi/uimapout.cgi",
http.MethodPost,
Expand Down
Loading

0 comments on commit 370e066

Please sign in to comment.