From 7ebacd2cd7a7704a8d3859816710cfac3e420a41 Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Tue, 11 Jul 2023 12:26:41 +0200 Subject: [PATCH] redfish/FirmwareInstall: check ctx timeout and override before proceeding install --- providers/redfish/firmware.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/providers/redfish/firmware.go b/providers/redfish/firmware.go index b36fd821..3d5f432a 100644 --- a/providers/redfish/firmware.go +++ b/providers/redfish/firmware.go @@ -13,6 +13,7 @@ import ( "path/filepath" "strconv" "strings" + "time" "github.com/pkg/errors" gofishrf "github.com/stmcginnis/gofish/redfish" @@ -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 { @@ -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,