diff --git a/internal/redfishwrapper/firmware.go b/internal/redfishwrapper/firmware.go index 81c3f1a5..aed6e3fe 100644 --- a/internal/redfishwrapper/firmware.go +++ b/internal/redfishwrapper/firmware.go @@ -16,6 +16,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/stmcginnis/gofish/redfish" "github.com/bmc-toolbox/bmclib/v2/constants" bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors" @@ -31,7 +32,7 @@ const ( var ( // the URI for starting a firmware update via StartUpdate is defined in the Redfish Resource and // Schema Guide (2024.1) - startUpdateURI = "redfish/v1/UpdateService/Actions/UpdateService.StartUpdate" + startUpdateURI = "/redfish/v1/UpdateService/Actions/UpdateService.StartUpdate" ) var ( @@ -112,6 +113,16 @@ func (c *Client) FirmwareUpload(ctx context.Context, updateFile *os.File, params return taskIDFromLocationHeader(location) } + rfTask := &redfish.Task{} + if err := rfTask.UnmarshalJSON(response); err != nil { + // we got invalid JSON + return "", fmt.Errorf("unmarshaling redfish response: %w", err) + } + // it's possible to get well-formed JSON that isn't a Task (thanks SMC). Test that we have something sensible. + if strings.Contains(rfTask.ODataType, "Task") { + return rfTask.ID, nil + } + return taskIDFromResponseBody(response) } @@ -146,6 +157,15 @@ func (c *Client) StartUpdateForUploadedFirmware(ctx context.Context) (taskID str return taskIDFromLocationHeader(location) } + rfTask := &redfish.Task{} + if err := rfTask.UnmarshalJSON(response); err != nil { + // we got invalid JSON + return "", fmt.Errorf("unmarshaling redfish response: %w", err) + } + if strings.Contains(rfTask.ODataType, "Task") { + return rfTask.ID, nil + } + return taskIDFromResponseBody(response) }