[RIC-395] - E2M new REST API - E2M Set Parameters - Automation + Decoder 63/4163/2
authorIrina <ib565x@intl.att.com>
Wed, 17 Jun 2020 12:01:21 +0000 (15:01 +0300)
committerShuky Har-Noy <shuky.har-noy@intl.att.com>
Wed, 17 Jun 2020 12:15:48 +0000 (12:15 +0000)
Change-Id: I4cefd6da49c6e67103ad07d2612b41aa6f955fbf
Signed-off-by: Irina <ib565x@intl.att.com>
Automation/Tests/SetGeneralConfiguration/set_general_configuration.robot
E2Manager/container-tag.yaml
E2Manager/controllers/nodeb_controller.go
E2Manager/controllers/nodeb_controller_test.go

index da7356b..c6f74c1 100644 (file)
 
 *** Settings ***
 Suite Setup   Prepare Enviorment
+Resource   ../Resource/scripts_variables.robot
 Resource   ../Resource/resource.robot
 Resource   ../Resource/Keywords.robot
+Library    ../Scripts/find_error_script.py
 Library     OperatingSystem
 Library     REST        ${url}
 
@@ -33,16 +35,16 @@ Library     REST        ${url}
 
 *** Test Cases ***
 
-prepare logs for tests
-    Remove log files
-    Save logs
-
 Set General Configuration
     Sleep  2s
     Set General Configuration request
     Integer  response status  200
-    String   response body enableRic    false
+    Boolean  response body enableRic    false
+
+prepare logs for tests
+    Remove log files
+    Save logs
 
-Verify e2mgr logs - Third retry to retrieve from db
-   ${result}    find_error_script.find_error     ${EXECDIR}  ${e2mgr_log_filename}   ${save_general_configuration}
+Verify e2mgr logs - Save General Configuration
+  ${result}    find_error_script.find_error     ${EXECDIR}  ${e2mgr_log_filename}    ${save_general_configuration}
    Should Be Equal As Strings    ${result}      True
\ No newline at end of file
index 273b7ac..3e5978b 100644 (file)
@@ -1,4 +1,4 @@
 # The Jenkins job requires a tag to build the Docker image.
 # Global-JJB script assumes this file is in the repo root.
 ---
-tag: 5.2.0
+tag: 5.2.1
index 49e821d..cef57f9 100644 (file)
@@ -103,7 +103,7 @@ func (c *NodebController) SetGeneralConfiguration(writer http.ResponseWriter, r
 
        request := models.GeneralConfigurationRequest{}
 
-       if !c.extractJsonBody(r, &request, writer){
+       if !c.extractJsonBodyDisallowUnknownFields(r, &request, writer){
                return
        }
        c.handleRequest(writer, &r.Header, httpmsghandlerprovider.SetGeneralConfigurationRequest, request, false)
@@ -165,6 +165,21 @@ func (c *NodebController) extractRequestBodyToProto(r *http.Request, pb proto.Me
        return true
 }
 
+func (c *NodebController) extractJsonBodyDisallowUnknownFields(r *http.Request, request models.Request, writer http.ResponseWriter) bool {
+       defer r.Body.Close()
+
+       decoder := json.NewDecoder(r.Body)
+       decoder.DisallowUnknownFields()
+
+       if err := decoder.Decode(&request); err != nil {
+               c.logger.Errorf("[Client -> E2 Manager] #NodebController.extractJsonBody - unable to extract json body - error: %s", err)
+               c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer)
+               return false
+       }
+
+       return true
+}
+
 func (c *NodebController) extractJsonBody(r *http.Request, request models.Request, writer http.ResponseWriter) bool {
        defer r.Body.Close()
        body, err := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest))
index 1543674..8209228 100644 (file)
@@ -300,7 +300,7 @@ func TestSetGeneralConfigurationInvalidJson(t *testing.T) {
 
        writer := httptest.NewRecorder()
 
-       httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{}{}"))
+       httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false, \"someValue\":false}"))
 
        controller.SetGeneralConfiguration(writer, httpRequest)