Skip to content

Commit

Permalink
redfish/FirmwareInstall: check ctx timeout and override before procee…
Browse files Browse the repository at this point in the history
…ding install
  • Loading branch information
joelrebel committed Jul 14, 2023
1 parent 7eddbde commit 7ebacd2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions providers/redfish/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
gofishrf "github.com/stmcginnis/gofish/redfish"
Expand Down Expand Up @@ -43,6 +44,12 @@ func (c *Conn) FirmwareInstall(ctx context.Context, component, applyAt string, f
return "", errors.Wrap(bmclibErrs.ErrFirmwareInstall, "invalid applyAt parameter: "+applyAt)
}

// expect atleast 30 minutes left in the deadline to proceed with the update
ctxDeadline, _ := ctx.Deadline()
if time.Until(ctxDeadline) < 30*time.Minute {
return "", errors.New("remaining context deadline insufficient to perform update: " + time.Until(ctxDeadline).String())
}

// list redfish firmware install task if theres one present
task, err := c.GetFirmwareInstallTaskQueued(ctx, component)
if err != nil {
Expand Down Expand Up @@ -77,6 +84,17 @@ func (c *Conn) FirmwareInstall(ctx context.Context, component, applyAt string, f
return "", errors.Wrap(bmclibErrs.ErrFirmwareInstall, err.Error())
}

// override the gofish HTTP client timeout, since that is generally set to a much lower value,
// and we cannot pass a context deadline for the multipart upload.
//
// record the http client time to be restored
httpClientTimeout := c.redfishwrapper.HttpClientTimeout()
defer func() {
c.redfishwrapper.SetHttpClientTimeout(httpClientTimeout)
}()

c.redfishwrapper.SetHttpClientTimeout(time.Until(ctxDeadline))

payload := map[string]io.Reader{
"UpdateParameters": bytes.NewReader(updateParameters),
"UpdateFile": reader,
Expand Down

0 comments on commit 7ebacd2

Please sign in to comment.