Skip to content

Commit

Permalink
updateservice/StartUpdate: adds the StartUpdate target (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel authored Oct 12, 2023
1 parent 6be0f7b commit 47a56e1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions redfish/updateservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type UpdateService struct {
TransferProtocol []string
// UpdateServiceTarget indicates where theupdate image is to be applied.
UpdateServiceTarget string
// StartUpdateTarget is the endpoint which starts updating images that have been previously
// invoked using an OperationApplyTime value of OnStartUpdateRequest.
StartUpdateTarget string
// OemActions contains all the vendor specific actions. It is vendor responsibility to parse this field accordingly
OemActions json.RawMessage
// Oem shall contain the OEM extensions. All values for properties that
Expand All @@ -55,6 +58,12 @@ func (updateService *UpdateService) UnmarshalJSON(b []byte) error {
Target string
} `json:"#UpdateService.SimpleUpdate"`

// This action starts updating all images that have been previously
// invoked using an OperationApplyTime value of OnStartUpdateRequest.
StartUpdate struct {
Target string
} `json:"#UpdateService.StartUpdate"`

Oem json.RawMessage // OEM actions will be stored here
}
var t struct {
Expand All @@ -75,6 +84,7 @@ func (updateService *UpdateService) UnmarshalJSON(b []byte) error {
updateService.SoftwareInventory = t.SoftwareInventory.String()
updateService.TransferProtocol = t.Actions.SimpleUpdate.AllowableValues
updateService.UpdateServiceTarget = t.Actions.SimpleUpdate.Target
updateService.StartUpdateTarget = t.Actions.StartUpdate.Target
updateService.OemActions = t.Actions.Oem
updateService.rawData = b

Expand Down
51 changes: 51 additions & 0 deletions redfish/updateservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,54 @@ func TestUpdateService(t *testing.T) {
assertMessage(t, result.UpdateServiceTarget, "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate")
})
}

var startUpdateBody = `{
"@odata.type": "#UpdateService.v1_8_0.UpdateService",
"@odata.id": "/redfish/v1/UpdateService",
"Id": "UpdateService",
"Name": "Update Service",
"Description": "Service for updating firmware and includes inventory of firmware",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"ServiceEnabled": true,
"MultipartHttpPushUri": "/redfish/v1/UpdateService/upload",
"FirmwareInventory": {
"@odata.id": "/redfish/v1/UpdateService/FirmwareInventory"
},
"Actions": {
"Oem": {},
"#UpdateService.SimpleUpdate": {
"target": "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate",
"@Redfish.ActionInfo": "/redfish/v1/UpdateService/SimpleUpdateActionInfo"
},
"#UpdateService.StartUpdate": {
"target": "/redfish/v1/UpdateService/Actions/UpdateService.StartUpdate"
}
},
"Oem": {}
}
}`

func TestUpdateServiceStartUpdate(t *testing.T) {
var result UpdateService
assertMessage := func(t testing.TB, got string, want string) {
t.Helper()
if got != want {
t.Errorf("got %s, want %s", got, want)
}
}

t.Run("Check UpdateService.StartUpdate field", func(t *testing.T) {
c := &common.TestClient{}
result.SetClient(c)

err := json.NewDecoder(strings.NewReader(startUpdateBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertMessage(t, result.StartUpdateTarget, "/redfish/v1/UpdateService/Actions/UpdateService.StartUpdate")
})
}

0 comments on commit 47a56e1

Please sign in to comment.