From 7fc8d64fc6aaeeb7c1cc37034d456860658f17b1 Mon Sep 17 00:00:00 2001 From: Angith Date: Tue, 6 Jun 2023 23:07:20 +0530 Subject: [PATCH 1/2] fixed status code for error responses from plugin added support for xr11 dell server --- svc-systems/scommon/common.go | 4 ++-- svc-systems/systems/bootorder.go | 7 ++++++- svc-systems/systems/secureBoot.go | 20 +++++++++++--------- svc-systems/systems/storage.go | 25 ++++++++++++++++++------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/svc-systems/scommon/common.go b/svc-systems/scommon/common.go index 4739bcc0e..691bacc3e 100644 --- a/svc-systems/scommon/common.go +++ b/svc-systems/scommon/common.go @@ -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) diff --git a/svc-systems/systems/bootorder.go b/svc-systems/systems/bootorder.go index b557b659b..7e1d9cb07 100644 --- a/svc-systems/systems/bootorder.go +++ b/svc-systems/systems/bootorder.go @@ -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 { @@ -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 } diff --git a/svc-systems/systems/secureBoot.go b/svc-systems/systems/secureBoot.go index d18806c3b..b105f8e55 100644 --- a/svc-systems/systems/secureBoot.go +++ b/svc-systems/systems/secureBoot.go @@ -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) @@ -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 @@ -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 { @@ -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 { diff --git a/svc-systems/systems/storage.go b/svc-systems/systems/storage.go index efa50734b..0443d8743 100644 --- a/svc-systems/systems/storage.go +++ b/svc-systems/systems/storage.go @@ -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 { @@ -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 { @@ -523,6 +524,16 @@ func (e *ExternalInterface) DeleteVolume(ctx context.Context, req *systemsproto. return } + // updating response of DELL XR11 response + 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() @@ -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) } From 294dacec88e1af138504634e35af085e187fa6cb Mon Sep 17 00:00:00 2001 From: Angith Date: Mon, 12 Jun 2023 12:12:39 +0530 Subject: [PATCH 2/2] code review changes --- svc-systems/systems/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svc-systems/systems/storage.go b/svc-systems/systems/storage.go index 0443d8743..12c01d663 100644 --- a/svc-systems/systems/storage.go +++ b/svc-systems/systems/storage.go @@ -524,7 +524,7 @@ func (e *ExternalInterface) DeleteVolume(ctx context.Context, req *systemsproto. return } - // updating response of DELL XR11 response + // handling the status ok response from plugin if getResponse.StatusCode == http.StatusOK && body != nil { resp.StatusCode = getResponse.StatusCode json.Unmarshal(body, &resp.Body)