Skip to content

Commit

Permalink
providers/redfish/firmware: Add TaskIDFromLocationURI and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ofaurax committed Sep 13, 2023
1 parent 2e973ca commit 9c3621b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
20 changes: 15 additions & 5 deletions providers/redfish/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,24 @@ func (c *Conn) FirmwareInstall(ctx context.Context, component, applyAt string, f
// The response contains a location header pointing to the task URI
// Location: /redfish/v1/TaskService/Tasks/JID_467696020275
var location = resp.Header.Get("Location")
if strings.Contains(location, "JID_") {
taskID = strings.Split(resp.Header.Get("Location"), "JID_")[1]
} else if strings.Contains(location, "/Monitor") {

taskID, err = TaskIDFromLocationURI(location)

return taskID, err
}

func TaskIDFromLocationURI(uri string) (taskID string, err error) {

if strings.Contains(uri, "JID_") {
taskID = strings.Split(uri, "JID_")[1]
} else if strings.Contains(uri, "/Monitor") {
// OpenBMC returns a monitor URL in Location
// Location: /redfish/v1/TaskService/Tasks/12/Monitor
splits := strings.Split(location, "/")
splits := strings.Split(uri, "/")
taskID = splits[5]
} else {
}

if taskID == "" {
return "", bmclibErrs.ErrTaskNotFound
}

Expand Down
20 changes: 20 additions & 0 deletions providers/redfish/firmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,23 @@ func Test_FirmwareInstall2(t *testing.T) {
t.Fatal("Wrong test state:", state)
}
}

func Test_TaskIDFromLocationURI(t *testing.T) {
var task string
var err error

task, err = TaskIDFromLocationURI("/redfish/v1/TaskService/Tasks/JID_467696020275")
if err != nil && task != "467696020275" {
t.Fatal("Wrong task ID 467696020275. task,err=", task, err)
}

task, err = TaskIDFromLocationURI("/redfish/v1/TaskService/Tasks/12/Monitor")
if err != nil && task != "12" {
t.Fatal("Wrong task ID 12. task,err=", task, err)
}

task, err = TaskIDFromLocationURI("/redfish/v1/TaskService/Tasks/NO-TASK-ID")
if err == nil {
t.Fatal("Should return an error. task,err=", task, err)
}
}

0 comments on commit 9c3621b

Please sign in to comment.