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

expand response payload processing #399

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion 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 All @@ -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 (
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
Loading