Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / libraries / Utils.robot
index 914fc47ef79144b543ef803dc7fed891e5b417ce..17077d466caa6c10a471b7f0a5d0a631a42732d5 100644 (file)
@@ -96,7 +96,8 @@ Check Nodes Stats
     [Arguments]    ${node}    ${session}=session
     ${resp}=    RequestsLibrary.Get On Session
     ...    ${session}
-    ...    ${RFC8040_NODES_API}/node=${node}?${RFC8040_OPERATIONAL_CONTENT}
+    ...    url=${RFC8040_NODES_API}/node=${node}
+    ...    params=${RFC8040_OPERATIONAL_CONTENT}
     Should Be Equal As Strings    ${resp.status_code}    200
     Should Contain    ${resp.text}    flow-capable-node-connector-statistics
     Should Contain    ${resp.text}    flow-table-statistics
@@ -105,7 +106,7 @@ Check For Specific Number Of Elements At URI
     [Documentation]    A GET is made to the specified ${URI} and the specific count of a
     ...    given element is done (as supplied by ${element} and ${expected_count})
     [Arguments]    ${uri}    ${element}    ${expected_count}    ${session}=session
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}
     Log    ${resp.text}
     Should Be Equal As Strings    ${resp.status_code}    200
     Should Contain X Times    ${resp.text}    ${element}    ${expected_count}
@@ -113,7 +114,9 @@ Check For Specific Number Of Elements At URI
 Log Content
     [Arguments]    ${resp_content}
     IF    '''${resp_content}''' != '${EMPTY}'
-        ${resp_json}=    RequestsLibrary.To Json    ${resp_content}    pretty_print=True
+        ${resp_json}=    BuiltIn.Evaluate
+        ...    json.dumps(json.loads('''${resp_content}'''), sort_keys=True, indent=4, separators=(',', ': '))
+        ...    modules=json
     ELSE
         ${resp_json}=    BuiltIn.Set Variable    ${EMPTY}
     END
@@ -124,7 +127,7 @@ Check For Elements At URI
     [Documentation]    A GET is made at the supplied ${URI} and every item in the list of
     ...    ${elements} is verified to exist in the response
     [Arguments]    ${uri}    ${elements}    ${session}=session    ${pretty_print_json}=False
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}
     IF    "${pretty_print_json}" == "True"
         Log Content    ${resp.text}
     ELSE
@@ -141,7 +144,7 @@ Check For Elements Not At URI
     ...    return of 404 is treated as empty list. From Neon onwards, an empty list is always
     ...    returned as null, giving 404 on rest call.
     [Arguments]    ${uri}    ${elements}    ${session}=session    ${pretty_print_json}=False    ${check_for_null}=False
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}
     IF    "${pretty_print_json}" == "True"
         Log Content    ${resp.text}
     ELSE
@@ -175,7 +178,7 @@ Clean Up Ovs
 Extract Value From Content
     [Documentation]    Will take the given response content and return the value at the given index as a string
     [Arguments]    ${content}    ${index}
-    ${JSON}=    Evaluate    json.loads('''${content}''')    json
+    ${JSON}=    BuiltIn.Evaluate    json.loads('''${content}''')    modules=json
     ${value}=    Set Variable    ${JSON${index}}
     RETURN    ${value}
 
@@ -364,26 +367,26 @@ Concatenate the String
 Post Elements To URI
     [Documentation]    Perform a POST rest operation, using the URL and data provided
     [Arguments]    ${rest_uri}    ${data}    ${headers}=${headers}    ${session}=session
-    ${resp}=    RequestsLibrary.Post On Session    ${session}    ${rest_uri}    data=${data}    headers=${headers}
+    ${resp}=    RequestsLibrary.Post On Session    ${session}    url=${rest_uri}    data=${data}    headers=${headers}
     Log    ${resp.text}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
 
 Remove All Elements At URI
     [Arguments]    ${uri}    ${session}=session
-    ${resp}=    RequestsLibrary.Delete On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Delete On Session    ${session}    url=${uri}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
 
 Remove All Elements At URI And Verify
     [Arguments]    ${uri}    ${session}=session
-    ${resp}=    RequestsLibrary.Delete On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Delete On Session    ${session}    url=${uri}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}
     Should Contain    ${DELETED_STATUS_CODES}    ${resp.status_code}
 
 Remove All Elements If Exist
     [Documentation]    Delete all elements from an URI if the configuration was not empty
     [Arguments]    ${uri}    ${session}=session
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}
     IF    '${resp.status_code}'!='404' and '${resp.status_code}'!='409'
         Remove All Elements At URI    ${uri}    ${session}
     END
@@ -392,7 +395,7 @@ Add Elements To URI From File
     [Documentation]    Put data from a file to a URI
     [Arguments]    ${dest_uri}    ${data_file}    ${headers}=${headers}    ${session}=session
     ${body}=    OperatingSystem.Get File    ${data_file}
-    ${resp}=    RequestsLibrary.Put On Session    ${session}    ${dest_uri}    data=${body}    headers=${headers}
+    ${resp}=    RequestsLibrary.Put On Session    ${session}    url=${dest_uri}    data=${body}    headers=${headers}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
 
 Add Elements To URI From File And Verify
@@ -404,9 +407,9 @@ Add Elements To URI From File And Verify
 Add Elements To URI And Verify
     [Documentation]    Put data to a URI and verify the HTTP response
     [Arguments]    ${dest_uri}    ${data}    ${headers}=${headers}    ${session}=session
-    ${resp}=    RequestsLibrary.Put On Session    ${session}    ${dest_uri}    ${data}    headers=${headers}
+    ${resp}=    RequestsLibrary.Put On Session    ${session}    url=${dest_uri}    ${data}    headers=${headers}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${dest_uri}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${dest_uri}
     Should Not Contain    ${DELETED_STATUS_CODES}    ${resp.status_code}
 
 Add Elements To URI From File And Check Validation Error
@@ -414,7 +417,7 @@ Add Elements To URI From File And Check Validation Error
     [Arguments]    ${dest_uri}    ${data_file}    ${headers}=${headers}    ${session}=session
     BuiltIn.Comment    TODO: Does this have any benefits, considering TemplatedRequests can also do this in one line?
     ${body}=    OperatingSystem.Get File    ${data_file}
-    ${resp}=    RequestsLibrary.Put On Session    ${session}    ${dest_uri}    data=${body}    headers=${headers}
+    ${resp}=    RequestsLibrary.Put On Session    ${session}    url=${dest_uri}    data=${body}    headers=${headers}
     Should Contain    ${DATA_VALIDATION_ERROR}    ${resp.status_code}
 
 Add Elements To URI From File And Check Server Error
@@ -423,13 +426,13 @@ Add Elements To URI From File And Check Server Error
     [Arguments]    ${dest_uri}    ${data_file}    ${headers}=${headers}    ${session}=session
     BuiltIn.Comment    TODO: Does this have any benefits, considering TemplatedRequests can also do this in one line?
     ${body}=    OperatingSystem.Get File    ${data_file}
-    ${resp}=    RequestsLibrary.Put On Session    ${session}    ${dest_uri}    data=${body}    headers=${headers}
+    ${resp}=    RequestsLibrary.Put On Session    ${session}    url=${dest_uri}    data=${body}    headers=${headers}
     Should Contain    ${INTERNAL_SERVER_ERROR}    ${resp.status_code}
 
 Post Elements To URI From File
     [Arguments]    ${dest_uri}    ${data_file}    ${headers}=${headers}    ${session}=session
     ${body}=    OperatingSystem.Get File    ${data_file}
-    ${resp}=    RequestsLibrary.Post On Session    ${session}    ${dest_uri}    data=${body}    headers=${headers}
+    ${resp}=    RequestsLibrary.Post On Session    ${session}    url=${dest_uri}    data=${body}    headers=${headers}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
 
 Run Process With Logging And Status Check
@@ -447,7 +450,7 @@ Get Data From URI
     ...    ${headers}. If the request returns a HTTP error, fails. Otherwise
     ...    returns the data obtained by the request.
     [Arguments]    ${session}    ${uri}    ${headers}=${NONE}
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}    ${headers}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}    headers=${headers}
     IF    ${resp.status_code} == 200    RETURN    ${resp.text}
     Builtin.Log    ${resp.text}
     Builtin.Fail    The request failed with code ${resp.status_code}
@@ -456,7 +459,7 @@ Get URI And Verify
     [Documentation]    Issue a Get On Session and verify a successfull HTTP return.
     ...    Issues a Get On Session for ${uri} in ${session} using headers from ${headers}.
     [Arguments]    ${uri}    ${session}=session    ${headers}=${NONE}
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}    ${headers}
+    ${resp}=    RequestsLibrary.Get On Session    ${session}    url=${uri}    headers=${headers}
     Builtin.Log    ${resp.status_code}
     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
 
@@ -466,7 +469,11 @@ No Content From URI
     ...    ${headers}. If the request returns a HTTP error, fails. Otherwise
     ...    returns the data obtained by the request.
     [Arguments]    ${session}    ${uri}    ${headers}=${NONE}
-    ${resp}=    RequestsLibrary.Get On Session    ${session}    ${uri}    ${headers}     expected_status=409
+    ${resp}=    RequestsLibrary.Get On Session
+    ...    ${session}
+    ...    url=${uri}
+    ...    headers=${headers}
+    ...    expected_status=anything
     IF    ${resp.status_code} == 404 or ${resp.status_code} == 409    RETURN
     Builtin.Log    ${resp.text}
     Builtin.Fail    The request failed with code ${resp.status_code}
@@ -494,7 +501,7 @@ Check Item Occurrence
 Post Log Check
     [Documentation]    Post body to ${uri}, log response content, and check status
     [Arguments]    ${uri}    ${body}    ${session}=session    ${status_codes}=200
-    ${resp}=    RequestsLibrary.Post On Session    ${session}    ${uri}    ${body}
+    ${resp}=    RequestsLibrary.Post On Session    ${session}    url=${uri}    data=${body}
     Log    ${resp.text}
     TemplatedRequests.Check Status Code    ${resp}    ${status_codes}
     RETURN    ${resp}
@@ -658,16 +665,8 @@ Check Diagstatus
     ...    By default, this keyword will pass if the status code returned is 200, and fail otherwise.
     [Arguments]    ${ip_address}=${ODL_SYSTEM_IP}    ${check_status}=True    ${expected_status}=${200}
     RequestsLibrary.Create Session    diagstatus_session    http://${ip_address}:${RESTCONFPORT}
-    ${resp}=    RequestsLibrary.Get On Session    diagstatus_session    /diagstatus
+    ${resp}=    RequestsLibrary.Get On Session    diagstatus_session    url=/diagstatus
     IF    "${check_status}" == "True"
         BuiltIn.Should Be Equal As Strings    ${resp.status_code}    ${expected_status}
     END
     RETURN    ${resp}
-
-Download File On Openstack Node
-    [Documentation]    Download a file from web to the node. the input will be a session ID with established SSH connection.
-    [Arguments]    ${conn_id}    ${save_file_name}    ${url}
-    SSHLibrary.Switch Connection    ${conn_id}
-    Utils.Write Commands Until Expected Prompt
-    ...    wget -O /tmp/${save_file_name} ${url}
-    ...    ${DEFAULT_LINUX_PROMPT_STRICT}