Skip to content

Commit

Permalink
Use openbmcGetStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
ofaurax committed Aug 10, 2023
1 parent 82e20fa commit 9021066
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
36 changes: 6 additions & 30 deletions providers/redfish/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,45 +163,21 @@ func (c *Conn) FirmwareInstallStatus(ctx context.Context, installVersion, compon
task, err = c.dellJobAsRedfishTask(taskID)
case strings.Contains(vendor, constants.Packet):
resp, _ := c.redfishwrapper.Get("/redfish/v1/TaskService/Tasks/" + taskID)

type TaskMsg struct {
Message string
}

type TaskStatus struct {
TaskState string
TaskStatus string
Messages []TaskMsg
}

var status TaskStatus

if resp.StatusCode != 200 {
err = errors.Wrap(
bmclibErrs.ErrFirmwareInstall,
"HTTP Error: "+fmt.Sprint(resp.StatusCode),
)

Check warning on line 170 in providers/redfish/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/firmware.go#L164-L170

Added lines #L164 - L170 were not covered by tests

state = "failed"
break

Check warning on line 173 in providers/redfish/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/firmware.go#L172-L173

Added lines #L172 - L173 were not covered by tests
}

} else {
data, _ := io.ReadAll(resp.Body)
resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
resp.Body.Close()

Check warning on line 177 in providers/redfish/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/firmware.go#L176-L177

Added lines #L176 - L177 were not covered by tests

state, err = c.openbmcGetStatus(data)

Check warning on line 179 in providers/redfish/firmware.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/firmware.go#L179

Added line #L179 was not covered by tests

err = json.Unmarshal(data, &status)
if err != nil {
fmt.Println(err)
} else {
state = strings.ToLower(status.TaskState)
if state != "running" {
// Display all messages when not running (failed or completed)
fmt.Println(status.TaskState, status.TaskStatus)
for _, m := range status.Messages {
fmt.Println(m.Message)
}
}
}
}
default:
err = errors.Wrap(
bmclibErrs.ErrNotImplemented,
Expand Down
2 changes: 1 addition & 1 deletion providers/redfish/firmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/bmc-toolbox/common"
)

// handler registered in mock_test.go
// handler registered in main_test.go
func multipartUpload(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusNotFound)
Expand Down

0 comments on commit 9021066

Please sign in to comment.