Add flag to log, or not, in Get_From_URI kw 46/88446/6
authorJamo Luhrsen <jluhrsen@gmail.com>
Mon, 16 Mar 2020 21:53:35 +0000 (14:53 -0700)
committerJamo Luhrsen <jluhrsen@gmail.com>
Tue, 17 Mar 2020 23:25:34 +0000 (16:25 -0700)
the problem fixed here was noticed in the netconf max
device scale job. The GET was retrieving a semi-large
output each time it was checking and looping until
success (which could be minutes) and over hundreds of
devices was causing the logs to grow so large that
robot itself would crash (assuming kernel killed OOM)

Note: some keywords were given an additional argument
${log_response}=True even though the body of the keyword
does not use it. This is because there is a wrapper
keyword that calls other keywords. That wrapper
(Perform_Operation_On_Each_Device) is now passing
this log_response flag every time, even for keywords
that don't need it (e.g., Configure_Device).

Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
Change-Id: Ia9828be85e1fc2a7e4392f58c421f49f507d611b
Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
csit/libraries/NetconfKeywords.robot
csit/libraries/TemplatedRequests.robot
csit/suites/netconf/scale/max_devices.robot

index e2c292c7aba619c277b3fd8250ee9aee2ee7311c..bc692a32869930cfb5fac074d2f689815c6d6061 100644 (file)
@@ -77,26 +77,26 @@ Check_Device_Has_No_Netconf_Connector
     Builtin.Should_Be_Equal_As_Strings    ${count}    0
 
 Check_Device_Completely_Gone
-    [Arguments]    ${device_name}    ${session}=default
+    [Arguments]    ${device_name}    ${session}=default    ${log_response}=True
     [Documentation]    Check that the specified device has no Netconf connectors nor associated data.
     Check_Device_Has_No_Netconf_Connector    ${device_name}    session=${session}
     ${uri} =    Restconf.Generate URI    network-topology:network-topology    config    topology=topology-netconf    node=${device_name}
-    ${status}    ${response}=    BuiltIn.Run_Keyword_And_Ignore_Error    TemplatedRequests.Get_As_Xml_From_Uri    ${uri}    session=${session}
+    ${status}    ${response}=    BuiltIn.Run_Keyword_And_Ignore_Error    TemplatedRequests.Get_As_Xml_From_Uri    ${uri}    session=${session}    log_response=${log_response}
     BuiltIn.Should_Be_Equal_As_Strings    ${status}    FAIL
     BuiltIn.Should_Contain    ${response}    404
 
 Check_Device_Connected
-    [Arguments]    ${device_name}    ${session}=default
+    [Arguments]    ${device_name}    ${session}=default    ${log_response}=True
     [Documentation]    Check that the specified device is accessible from Netconf.
     ${uri} =    Restconf.Generate URI    network-topology:network-topology    operational    topology=topology-netconf    node=${device_name}
-    ${device_status}=    TemplatedRequests.Get_As_Json_From_Uri    ${uri}    session=${session}
+    ${device_status}=    TemplatedRequests.Get_As_Json_From_Uri    ${uri}    session=${session}    log_response=${log_response}
     Builtin.Should_Contain    ${device_status}    "netconf-node-topology:connection-status": "connected"
 
 Wait_Device_Connected
-    [Arguments]    ${device_name}    ${timeout}=20s    ${period}=1s    ${session}=default
+    [Arguments]    ${device_name}    ${timeout}=20s    ${period}=1s    ${session}=default    ${log_response}=True
     [Documentation]    Wait for the device to become connected.
     ...    It is more readable to use this keyword in a test case than to put the whole WUKS below into it.
-    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${period}    Check_Device_Connected    ${device_name}    session=${session}
+    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${period}    Check_Device_Connected    ${device_name}    session=${session}    log_response=${log_response}
 
 Remove_Device_From_Netconf
     [Arguments]    ${device_name}    ${session}=default    ${location}=location
@@ -106,7 +106,7 @@ Remove_Device_From_Netconf
     TemplatedRequests.Delete_Templated    ${DIRECTORY_WITH_DEVICE_TEMPLATES}${/}${device_type}    ${template_as_string}    session=${session}    location=${location}
 
 Wait_Device_Fully_Removed
-    [Arguments]    ${device_name}    ${timeout}=10s    ${period}=1s    ${session}=default
+    [Arguments]    ${device_name}    ${timeout}=10s    ${period}=1s    ${session}=default    ${log_response}=True
     [Documentation]    Wait until all netconf connectors for the device with the given name disappear.
     ...    Call of Remove_Device_From_Netconf returns before netconf gets
     ...    around deleting the device's connector. To ensure the device is
@@ -115,7 +115,7 @@ Wait_Device_Fully_Removed
     ...    is not made before using this keyword, the wait will fail.
     ...    Using this keyword is more readable than putting the WUKS below
     ...    into a test case.
-    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${period}    Check_Device_Completely_Gone    ${device_name}    session=${session}
+    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${period}    Check_Device_Completely_Gone    ${device_name}    session=${session}    log_response=${log_response}
 
 NetconfKeywords__Deploy_Additional_Schemas
     [Arguments]    ${schemas}
@@ -162,7 +162,7 @@ NetconfKeywords__Check_Device_Is_Up
     BuiltIn.Should_Be_Equal_As_Integers    ${count}    1
 
 NetconfKeywords__Wait_Device_Is_Up_And_Running
-    [Arguments]    ${device_name}
+    [Arguments]    ${device_name}    ${log_response}=True
     ${number}=    BuiltIn.Evaluate    '${device_name}'.split('-').pop()
     BuiltIn.Wait_Until_Keyword_Succeeds    ${TESTTOOL_BOOT_TIMEOUT}    1s    Check_Device_Up_And_Running    ${number}
 
@@ -218,16 +218,16 @@ NetconfKeywords__Check_Netconf_Test_Timeout_Not_Expired
     BuiltIn.Run_Keyword_If    ${ellapsed_seconds}<0    Fail    The global time out period expired
 
 NetconfKeywords__Perform_Operation_With_Checking_On_Next_Device
-    [Arguments]    ${operation}    ${deadline_Date}
+    [Arguments]    ${operation}    ${deadline_Date}    ${log_response}=True
     NetconfKeywords__Check_Netconf_Test_Timeout_Not_Expired    ${deadline_Date}
     ${number}=    BuiltIn.Evaluate    ${current_port}-${BASE_NETCONF_DEVICE_PORT}+1
-    BuiltIn.Run_Keyword    ${operation}    ${DEVICE_NAME_BASE}-${number}
+    BuiltIn.Run_Keyword    ${operation}    ${DEVICE_NAME_BASE}-${number}    log_response=${log_response}
     ${next}=    BuiltIn.Evaluate    ${current_port}+1
     BuiltIn.Set_Suite_Variable    ${current_port}    ${next}
 
 Perform_Operation_On_Each_Device
-    [Arguments]    ${operation}    ${count}=${NetconfKeywords__testtool_device_count}    ${timeout}=30m
+    [Arguments]    ${operation}    ${count}=${NetconfKeywords__testtool_device_count}    ${timeout}=30m    ${log_response}=True
     ${current_Date}=    DateTime.Get_Current_Date
     ${deadline_Date}=    DateTime.Add_Time_To_Date    ${current_Date}    ${timeout}
     BuiltIn.Set_Suite_Variable    ${current_port}    ${BASE_NETCONF_DEVICE_PORT}
-    BuiltIn.Repeat_Keyword    ${count} times    NetconfKeywords__Perform_Operation_With_Checking_On_Next_Device    ${operation}    ${deadline_Date}
+    BuiltIn.Repeat_Keyword    ${count} times    NetconfKeywords__Perform_Operation_With_Checking_On_Next_Device    ${operation}    ${deadline_Date}    log_response=${log_response}
index a484e26ae76877576872818f51e7ffa27bd35ed2..052080703a9f0e3fce314dac8be706ef6fa5b6d8 100644 (file)
@@ -136,13 +136,13 @@ Create_Default_Session
 
 Get_As_Json_Templated
     [Arguments]    ${folder}    ${mapping}={}    ${session}=default    ${verify}=False    ${iterations}=${EMPTY}    ${iter_start}=1
-    ...    ${http_timeout}=${EMPTY}
+    ...    ${http_timeout}=${EMPTY}    ${log_response}=True
     [Documentation]    Add arguments sensible for JSON data, return Get_Templated response text.
     ...    Optionally, verification against JSON data (may be iterated) is called.
     ...    Only subset of JSON data is verified and returned if JMES path is specified in
     ...    file ${folder}${/}jmespath.expr.
     ${response_text} =    Get_Templated    folder=${folder}    mapping=${mapping}    accept=${ACCEPT_EMPTY}    session=${session}    normalize_json=True
-    ...    http_timeout=${http_timeout}
+    ...    http_timeout=${http_timeout}    log_response=${log_response}
     BuiltIn.Run_Keyword_If    ${verify}    Verify_Response_As_Json_Templated    response=${response_text}    folder=${folder}    base_name=data    mapping=${mapping}
     ...    iterations=${iterations}    iter_start=${iter_start}
     [Return]    ${response_text}
@@ -249,15 +249,15 @@ Verify_Response_As_Xml_Templated
     ...    endline=${EMPTY}    iterations=${iterations}    iter_start=${iter_start}
 
 Get_As_Json_From_Uri
-    [Arguments]    ${uri}    ${session}=default    ${http_timeout}=${EMPTY}
+    [Arguments]    ${uri}    ${session}=default    ${http_timeout}=${EMPTY}    ${log_response}=True
     [Documentation]    Specify JSON headers and return Get_From_Uri normalized response text.
-    ${response_text} =    Get_From_Uri    uri=${uri}    accept=${ACCEPT_EMPTY}    session=${session}    normalize_json=True    http_timeout=${http_timeout}
+    ${response_text} =    Get_From_Uri    uri=${uri}    accept=${ACCEPT_EMPTY}    session=${session}    normalize_json=True    http_timeout=${http_timeout}    log_response=${log_response}
     [Return]    ${response_text}
 
 Get_As_Xml_From_Uri
-    [Arguments]    ${uri}    ${session}=default    ${http_timeout}=${EMPTY}
+    [Arguments]    ${uri}    ${session}=default    ${http_timeout}=${EMPTY}    ${log_response}=True
     [Documentation]    Specify XML headers and return Get_From_Uri response text.
-    ${response_text} =    Get_From_Uri    uri=${uri}    accept=${ACCEPT_XML}    session=${session}    normalize_json=False    http_timeout=${http_timeout}
+    ${response_text} =    Get_From_Uri    uri=${uri}    accept=${ACCEPT_XML}    session=${session}    normalize_json=False    http_timeout=${http_timeout}    log_response=${log_response}
     [Return]    ${response_text}
 
 Put_As_Json_To_Uri
@@ -321,13 +321,13 @@ Resolve_Volatiles_Path
     [Return]    ${volatiles_list}
 
 Get_Templated
-    [Arguments]    ${folder}    ${accept}    ${mapping}={}    ${session}=default    ${normalize_json}=False    ${http_timeout}=${EMPTY}
+    [Arguments]    ${folder}    ${accept}    ${mapping}={}    ${session}=default    ${normalize_json}=False    ${http_timeout}=${EMPTY}    ${log_response}=True
     [Documentation]    Resolve URI from folder, call Get_From_Uri, return response text.
     ${uri} =    Resolve_Text_From_Template_Folder    folder=${folder}    base_name=location    extension=uri    mapping=${mapping}
     ${jmes_expression} =    Resolve_Jmes_Path    ${folder}
     ${volatiles_list}=    Resolve_Volatiles_Path    ${folder}
     ${response_text} =    Get_From_Uri    uri=${uri}    accept=${accept}    session=${session}    normalize_json=${normalize_json}    jmes_path=${jmes_expression}
-    ...    http_timeout=${http_timeout}    keys_with_volatiles=${volatiles_list}
+    ...    http_timeout=${http_timeout}    keys_with_volatiles=${volatiles_list}    log_response=${log_response}
     [Return]    ${response_text}
 
 Put_Templated
@@ -369,7 +369,7 @@ Verify_Response_Templated
 
 Get_From_Uri
     [Arguments]    ${uri}    ${accept}=${ACCEPT_EMPTY}    ${session}=default    ${normalize_json}=False    ${jmes_path}=${EMPTY}    ${http_timeout}=${EMPTY}
-    ...    ${keys_with_volatiles}=${EMPTY}
+    ...    ${keys_with_volatiles}=${EMPTY}    ${log_response}=True
     [Documentation]    GET data from given URI, check status code and return response text.
     ...    \${accept} is a Python object with headers to use.
     ...    If \${normalize_json}, normalize as JSON text before returning.
@@ -377,7 +377,7 @@ Get_From_Uri
     BuiltIn.Log    ${accept}
     ${response} =    BuiltIn.Run_Keyword_If    """${http_timeout}""" == """${EMPTY}"""    RequestsLibrary.Get_Request    alias=${session}    uri=${uri}    headers=${accept}
     ...    ELSE    RequestsLibrary.Get_Request    alias=${session}    uri=${uri}    headers=${accept}    timeout=${http_timeout}
-    Check_Status_Code    ${response}
+    Check_Status_Code    ${response}    log_response=${log_response}
     BuiltIn.Run_Keyword_Unless    ${normalize_json}    BuiltIn.Return_From_Keyword    ${response.text}
     ${text_normalized} =    norm_json.normalize_json_text    ${response.text}    jmes_path=${jmes_path}    keys_with_volatiles=${keys_with_volatiles}
     [Return]    ${text_normalized}
@@ -423,11 +423,13 @@ Post_To_Uri
     [Return]    ${text_normalized}
 
 Check_Status_Code
-    [Arguments]    ${response}    ${additional_allowed_status_codes}=${NO_STATUS_CODES}    ${explicit_status_codes}=${NO_STATUS_CODES}
-    [Documentation]    Log response text, check status_code is one of allowed ones.
+    [Arguments]    ${response}    ${additional_allowed_status_codes}=${NO_STATUS_CODES}    ${explicit_status_codes}=${NO_STATUS_CODES}    ${log_response}=True
+    [Documentation]    Log response text, check status_code is one of allowed ones. In cases where this keyword is
+    ...    called in a WUKS it could end up logging tons of data and it may be desired to skip the logging by passing
+    ...    log_response=False, but by default it remains True.
     # TODO: Remove overlap with keywords from Utils.robot
-    BuiltIn.Log    ${response.text}
-    BuiltIn.Log    ${response.status_code}
+    Run Keyword If    "${log_response}" == "True"    BuiltIn.Log    ${response.text}
+    Run Keyword If    "${log_response}" == "True"    BuiltIn.Log    ${response.status_code}
     # In order to allow other existing keywords to consume this keyword by passing a single non-list status code, we need to
     # check the type of the argument passed and convert those single non-list codes in to a one item list
     ${status_codes_type} =    Evaluate    type($additional_allowed_status_codes).__name__
index 07d066dfb43d9e49b40332ee7857cb48258d5c65..e9cdca111d08949b8521faee01d5e7f1b4e7f374 100644 (file)
@@ -55,16 +55,16 @@ Find Max Netconf Devices
         ...    ELSE    NetconfKeywords.Start_Testtool    ${TESTTOOL_EXECUTABLE}    debug=false    schemas=${schema_dir}    device-count=${devices}
         ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Configure_Device    timeout=${timeout}
         Exit For Loop If    '${status}' == 'FAIL'
-        ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Wait_Connected    timeout=${timeout}
+        ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Wait_Connected    timeout=${timeout}    log_response=False
         Exit For Loop If    '${status}' == 'FAIL'
         ${status}    ${result} =    Run Keyword And Ignore Error    Issue_Requests_On_Devices    ${TOOLS_SYSTEM_IP}    ${devices}
         ...    ${NUM_WORKERS}
         Exit For Loop If    '${status}' == 'FAIL'
-        ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Wait_Connected    timeout=${timeout}
+        ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Wait_Connected    timeout=${timeout}    log_response=False
         Exit For Loop If    '${status}' == 'FAIL'
         ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Deconfigure_Device    timeout=${timeout}
         Exit For Loop If    '${status}' == 'FAIL'
-        ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Check_Device_Deconfigured    timeout=${timeout}
+        ${status}    ${result} =    Run Keyword And Ignore Error    NetconfKeywords.Perform_Operation_On_Each_Device    Check_Device_Deconfigured    timeout=${timeout}    log_response=False
         Exit For Loop If    '${status}' == 'FAIL'
         ${maximum_devices} =    Set Variable    ${devices}
         Run Keyword And Ignore Error    CheckJVMResource.Get JVM Memory
@@ -114,17 +114,17 @@ Teardown_Everything
     NetconfKeywords.Stop_Testtool
 
 Configure_Device
-    [Arguments]    ${current_name}
+    [Arguments]    ${current_name}    ${log_response}=True
     [Documentation]    Operation for configuring the device.
     KarafKeywords.Log_Message_To_Controller_Karaf    Configuring device ${current_name} to Netconf
     NetconfKeywords.Configure_Device_In_Netconf    ${current_name}    device_type=${device_type}    device_port=${current_port}
     KarafKeywords.Log_Message_To_Controller_Karaf    Device ${current_name} configured
 
 Wait_Connected
-    [Arguments]    ${current_name}
+    [Arguments]    ${current_name}    ${log_response}=True
     [Documentation]    Operation for waiting until the device is connected.
     KarafKeywords.Log_Message_To_Controller_Karaf    Waiting for device ${current_name} to connect
-    NetconfKeywords.Wait_Device_Connected    ${current_name}    period=0.5s    timeout=120s
+    NetconfKeywords.Wait_Device_Connected    ${current_name}    period=0.5s    timeout=120s    log_response=${log_response}
     KarafKeywords.Log_Message_To_Controller_Karaf    Device ${current_name} connected
 
 Read_Python_Tool_Operation_Result
@@ -144,17 +144,17 @@ Read_Python_Tool_Operation_Result
     BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
 
 Deconfigure_Device
-    [Arguments]    ${current_name}
+    [Arguments]    ${current_name}    ${log_response}=True
     [Documentation]    Operation for deconfiguring the device.
     KarafKeywords.Log_Message_To_Controller_Karaf    Deconfiguring device ${current_name}
     NetconfKeywords.Remove_Device_From_Netconf    ${current_name}
     KarafKeywords.Log_Message_To_Controller_Karaf    Device ${current_name} deconfigured
 
 Check_Device_Deconfigured
-    [Arguments]    ${current_name}
+    [Arguments]    ${current_name}    ${log_response}=True
     [Documentation]    Operation for making sure the device is really deconfigured.
     KarafKeywords.Log_Message_To_Controller_Karaf    Waiting for device ${current_name} to disappear
-    NetconfKeywords.Wait_Device_Fully_Removed    ${current_name}    period=0.5s    timeout=120s
+    NetconfKeywords.Wait_Device_Fully_Removed    ${current_name}    period=0.5s    timeout=120s    log_response=${log_response}
     KarafKeywords.Log_Message_To_Controller_Karaf    Device ${current_name} removed
 
 Get Juniper Device Schemas