Skip to content

Commit

Permalink
expand response payload processing
Browse files Browse the repository at this point in the history
In contrast to other server-vendors, SMC does not return the task id in
the Location header of the response to a firmware upload. In BMC version
1.05.03 (Redfish version 1.14.0) the payload format changes from a
TaskAccepted message to a Redfish task, which breaks task id detection.
This change adds an attempt to deserialize the task structure before
falling back to the earlier TaskAccepted message type.
  • Loading branch information
DoctorVin committed Oct 14, 2024
1 parent eba5356 commit 57cf52e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/redfishwrapper/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 57cf52e

Please sign in to comment.