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

Smc checks #387

Merged
merged 10 commits into from
Apr 18, 2024
1 change: 1 addition & 0 deletions providers/supermicro/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
"X11DPT-B",
"X11SSE-F",
"X12STH-SYS",
"X12SPO-NTF",
}

errUploadTaskIDExpected = errors.New("expected an firmware upload taskID")
Expand Down
18 changes: 12 additions & 6 deletions providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,24 @@ func (c *Client) Open(ctx context.Context) (err error) {
return errors.Wrap(bmclibErrs.ErrLoginFailed, strconv.Itoa(status))
}

// called after a session was opened but further login dependencies failed
closeWithError := func(ctx context.Context, err error) error {
_ = c.Close(ctx)
return err
}

if !bytes.Contains(body, []byte(`url_redirect.cgi?url_name=mainmenu`)) &&
!bytes.Contains(body, []byte(`url_redirect.cgi?url_name=topmenu`)) {
return errors.Wrap(bmclibErrs.ErrLoginFailed, "unexpected response contents")
return closeWithError(ctx, errors.Wrap(bmclibErrs.ErrLoginFailed, "unexpected response contents"))
}

contentsTopMenu, status, err := c.serviceClient.query(ctx, "cgi/url_redirect.cgi?url_name=topmenu", http.MethodGet, nil, nil, 0)
if err != nil {
return errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error())
return closeWithError(ctx, errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error()))
}

if status != 200 {
return errors.Wrap(bmclibErrs.ErrLoginFailed, strconv.Itoa(status))
return closeWithError(ctx, errors.Wrap(bmclibErrs.ErrLoginFailed, strconv.Itoa(status)))
}

// Note: older firmware version on the X11s don't use a CSRF token
Expand All @@ -183,11 +189,11 @@ func (c *Client) Open(ctx context.Context) (err error) {

c.bmc, err = c.bmcQueryor(ctx)
if err != nil {
return errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error())
return closeWithError(ctx, errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error()))
}

if err := c.serviceClient.redfishSession(ctx); err != nil {
return errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error())
return closeWithError(ctx, errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error()))
}

return nil
Expand Down Expand Up @@ -257,7 +263,7 @@ func (c *Client) bmcQueryor(ctx context.Context) (bmcQueryor, error) {

model := strings.ToLower(queryor.deviceModel())
if !strings.HasPrefix(model, "x12") && !strings.HasPrefix(model, "x11") {
return nil, errors.Wrap(ErrModelUnsupported, model)
return nil, errors.Wrap(ErrModelUnsupported, "expected one of X11* or X12*, got:"+model)
}

return queryor, nil
Expand Down
Loading