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

Fixed invalid status code for error responses from plugins #1243

Merged
merged 7 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions svc-systems/scommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ func ContactPlugin(ctx context.Context, req PluginContactRequest, errorMessage s
resp.StatusCode = int32(response.StatusCode)
if response.StatusCode != http.StatusCreated && response.StatusCode != http.StatusOK && response.StatusCode != http.StatusAccepted {
resp.StatusCode = int32(response.StatusCode)
l.LogWithFields(ctx).Println(errorMessage)
return body, "", "", resp, fmt.Errorf(errorMessage)
msg := errorMessage + "got the response :" + string(body)
return body, "", "", resp, fmt.Errorf(msg)
}

data := string(body)
Expand Down
7 changes: 6 additions & 1 deletion svc-systems/systems/bootorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ func (p *PluginContact) ChangeBiosSettings(ctx context.Context, req *systemsprot
if err != nil {
resp.StatusCode = getResponse.StatusCode
json.Unmarshal(body, &resp.Body)
common.GeneralError(http.StatusInternalServerError, response.InternalError, err.Error(), nil, taskInfo)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.OK, 100, http.MethodPatch)
p.UpdateTask(ctx, task)
return
}
if getResponse.StatusCode == http.StatusAccepted {
Expand Down Expand Up @@ -360,6 +362,9 @@ func (p *PluginContact) ChangeBootOrderSettings(ctx context.Context, req *system
if err != nil {
resp.StatusCode = getResponse.StatusCode
json.Unmarshal(body, &resp.Body)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.OK, 100, http.MethodPatch)
p.UpdateTask(ctx, task)
return
}

Expand Down
20 changes: 11 additions & 9 deletions svc-systems/systems/secureBoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (e *ExternalInterface) UpdateSecureBoot(ctx context.Context, req *systemspr
// unmarshalling the volume
err := json.Unmarshal(req.RequestBody, &secureBoot)
if err != nil {
errorMessage := "Error while unmarshaling the create volume request: " + err.Error()
errorMessage := "Error while unmarshaling the update secure boot request: " + err.Error()
if StringContain(err.Error(), "smodel.OdataIDLink") {
errorMessage = "Error processing create volume request: @odata.id key(s) is missing in Drives list"
errorMessage = "Error processing update secure boot request: @odata.id key(s) is missing in Drives list"
}
l.LogWithFields(ctx).Error(errorMessage)
common.GeneralError(http.StatusBadRequest, response.MalformedJSON, errorMessage, []interface{}{}, taskInfo)
Expand All @@ -76,7 +76,7 @@ func (e *ExternalInterface) UpdateSecureBoot(ctx context.Context, req *systemspr
common.GeneralError(http.StatusInternalServerError, response.InternalError, errMsg, nil, taskInfo)
return
} else if invalidProperties != "" {
errorMessage := "error: one or more properties given in the request body are not valid, ensure properties are listed in uppercamelcase "
errorMessage := "error: one or more properties given in the request body are not valid, ensure properties are listed in upper camel case "
l.LogWithFields(ctx).Error(errorMessage)
common.GeneralError(http.StatusBadRequest, response.PropertyUnknown, errorMessage, []interface{}{invalidProperties}, taskInfo)
return
Expand Down Expand Up @@ -130,14 +130,15 @@ func (e *ExternalInterface) UpdateSecureBoot(ctx context.Context, req *systemspr
contactRequest.DeviceInfo = target
contactRequest.OID = fmt.Sprintf("/ODIM/v1/Systems/%s/SecureBoot", requestData[1])

body, location, pluginIP, getResponse, err := ContactPluginFunc(ctx, contactRequest, "error while creating a volume: ")
body, location, pluginIP, getResponse, err := ContactPluginFunc(ctx, contactRequest, "error while updating secure boot: ")
if err != nil {
resp.StatusCode = getResponse.StatusCode
json.Unmarshal(body, &resp.Body)
errMsg := "error while creating volume: " + err.Error()
errMsg := "error while updating secure boot: " + err.Error()
l.LogWithFields(ctx).Error(errMsg)
common.GeneralError(http.StatusInternalServerError, response.InternalError,
errMsg, nil, taskInfo)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.Warning, 100, http.MethodPatch)
pc.UpdateTask(ctx, task)
return
}
if getResponse.StatusCode == http.StatusAccepted {
Expand Down Expand Up @@ -267,8 +268,9 @@ func (e *ExternalInterface) ResetSecureBoot(ctx context.Context, req *systemspro
json.Unmarshal(body, &resp.Body)
errMsg := "error while resetting secure boot: " + err.Error()
l.LogWithFields(ctx).Error(errMsg)
common.GeneralError(http.StatusInternalServerError, response.InternalError,
errMsg, nil, taskInfo)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.Warning, 100, http.MethodPost)
pc.UpdateTask(ctx, task)
return
}
if getResponse.StatusCode == http.StatusAccepted {
Expand Down
25 changes: 18 additions & 7 deletions svc-systems/systems/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ func (e *ExternalInterface) CreateVolume(ctx context.Context, req *systemsproto.
if err != nil {
resp.StatusCode = getResponse.StatusCode
json.Unmarshal(body, &resp.Body)
errMsg := "error while creating volume: " + err.Error()
l.LogWithFields(ctx).Error(errMsg)
common.GeneralError(http.StatusInternalServerError, response.InternalError,
errMsg, nil, taskInfo)
l.LogWithFields(ctx).Error(err)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.Warning, 100, http.MethodPost)
pc.UpdateTask(ctx, task)
return
}
if getResponse.StatusCode == http.StatusAccepted {
Expand Down Expand Up @@ -511,8 +511,9 @@ func (e *ExternalInterface) DeleteVolume(ctx context.Context, req *systemsproto.
json.Unmarshal(body, &resp.Body)
errMsg := "error while deleting volume: " + err.Error()
l.LogWithFields(ctx).Error(errMsg)
common.GeneralError(http.StatusInternalServerError, response.InternalError,
errMsg, nil, taskInfo)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.Warning, 100, http.MethodPost)
pc.UpdateTask(ctx, task)
return
}
if getResponse.StatusCode == http.StatusAccepted {
Expand All @@ -523,6 +524,16 @@ func (e *ExternalInterface) DeleteVolume(ctx context.Context, req *systemsproto.
return
}

// handling the status ok response from plugin
if getResponse.StatusCode == http.StatusOK && body != nil {
resp.StatusCode = getResponse.StatusCode
json.Unmarshal(body, &resp.Body)
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.OK, 100, http.MethodDelete)
pc.UpdateTask(ctx, task)
return
}

// delete a volume in db
if derr := e.DB.DeleteVolume(ctx, key); derr != nil {
errMsg := "error while trying to delete volume: " + derr.Error()
Expand All @@ -544,6 +555,6 @@ func (e *ExternalInterface) DeleteVolume(ctx context.Context, req *systemsproto.
resp.StatusCode = http.StatusNoContent
resp.StatusMessage = response.Success
task := fillTaskData(taskID, targetURI, string(req.RequestBody), resp,
common.Completed, common.OK, 100, http.MethodPost)
common.Completed, common.OK, 100, http.MethodDelete)
pc.UpdateTask(ctx, task)
}