removing validations for netvirt related testing
[integration/test.git] / csit / libraries / KarafKeywords.robot
index 200d2d2b114e17f66f7305c02358582c2ae35dd0..d602683fb4d7874ce4344c3303b7265f8fbd8d05 100644 (file)
@@ -1,4 +1,5 @@
 *** Settings ***
+Documentation     Karaf library. This library is useful to deal with controller Karaf console.
 Library           SSHLibrary
 Library           OperatingSystem
 Variables         ../variables/Variables.py
@@ -9,13 +10,6 @@ ${BUNDLEFOLDER}    distribution-karaf-0.3.0-SNAPSHOT
 ${KarafKeywords__karaf_connection_index}    -1
 
 *** Keywords ***
-Check Karaf Log File Does Not Have Messages
-    [Arguments]    ${ip}    ${message}    ${user}=${CONTROLLER_USER}    ${password}=${CONTROLLER_PASSWORD}    ${prompt}=${DEFAULT_LINUX_PROMPT}    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
-    [Documentation]    Fails if the provided ${message} is found in the karaf.log file. Uses grep to search. The
-    ...    karaf.log file can be overridden with ${log_file} to be any file on the given system @ ${ip}
-    ${output}=    Run Command On Controller    ${ip}    grep ${message} ${log_file}    user=${user}    password=${password}    prompt=${prompt}
-    Should Not Contain    ${output}    ${message}
-
 Verify Feature Is Installed
     [Arguments]    ${feature_name}    ${controller}=${CONTROLLER}    ${karaf_port}=${KARAF_SHELL_PORT}
     [Documentation]    Will Succeed if the given ${feature_name} is found in the output of "feature:list -i"
@@ -64,6 +58,13 @@ Check Karaf Log Has Messages
     \    Should Contain    ${output}    ${message}
     [Return]    ${output}
 
+Check Karaf Log File Does Not Have Messages
+    [Arguments]    ${ip}    ${message}    ${user}=${CONTROLLER_USER}    ${password}=${CONTROLLER_PASSWORD}    ${prompt}=${DEFAULT_LINUX_PROMPT}    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
+    [Documentation]    Fails if the provided ${message} is found in the karaf.log file. Uses grep to search. The
+    ...    karaf.log file can be overridden with ${log_file} to be any file on the given system @ ${ip}
+    ${output}=    Run Command On Controller    ${ip}    grep -c '${message}' ${log_file}    user=${user}    password=${password}    prompt=${prompt}
+    Should Be Equal As Strings    ${output}    0
+
 Install a Feature
     [Arguments]    ${feature_name}    ${controller}=${CONTROLLER}    ${karaf_port}=${KARAF_SHELL_PORT}    ${timeout}=15
     [Documentation]    Will Install the given ${feature_name}
@@ -115,6 +116,14 @@ Open Controller Karaf Console On Background
     BuiltIn.Set Suite Variable    ${KarafKeywords__karaf_connection_index}    ${karaf_connection.index}
     Restore Current SSH Connection From Index    ${current_ssh_connection.index}
 
+Configure Timeout For Karaf Console
+    [Arguments]    ${timeout}
+    [Documentation]    Configure a different timeout for the Karaf console
+    BuiltIn.Run Keyword If    ${KarafKeywords__karaf_connection_index} == -1    Fail    Need to connect to a Karaf Console first
+    ${current_connection_index}=    SSHLibrary.Switch Connection    ${KarafKeywords__karaf_connection_index}
+    SSHLibrary.Set_Client_Configuration    timeout=${timeout}
+    Restore Current SSH Connection From Index    ${current_connection_index}
+
 Execute Controller Karaf Command On Background
     [Arguments]    ${command}
     [Documentation]    Send command to karaf without affecting current SSH connection. Read, log and return response.
@@ -129,10 +138,20 @@ Execute Controller Karaf Command On Background
     BuiltIn.Run Keyword If    '${status_wait}' != 'PASS'    BuiltIn.Fail    Failed to see prompt after sending the command: ${command}
     [Return]    ${message_wait}
 
+Execute Controller Karaf Command With Retry On Background
+    [Arguments]    ${command}
+    [Documentation]    Attemp to send command to karaf, if fail then open connection and try again.
+    ${status}    ${message}=    BuiltIn.Run Keyword And Ignore Error    Execute Controller Karaf Command On Background    ${command}
+    BuiltIn.Return_From_Keyword_If    '${status}' == 'PASS'    ${message}
+    # TODO: Verify this does not leak connections indices.
+    Open Controller Karaf Console On Background
+    ${message}=    Execute Controller Karaf Command On Background    ${command}
+    [Return]    ${message}
+
 Log Message To Controller Karaf
     [Arguments]    ${message}
     [Documentation]    Send a message into the controller's karaf log file. Do not change current SSH connection.
-    ${reply}=    Execute Controller Karaf Command On Background    log:log "ROBOT MESSAGE: ${message}"
+    ${reply}=    Execute Controller Karaf Command With Retry On Background    log:log "ROBOT MESSAGE: ${message}"
     [Return]    ${reply}
 
 Log Test Suite Start To Controller Karaf
@@ -149,3 +168,13 @@ Set Bgpcep Log Levels
     # FIXME: Move to appropriate Resource
     Execute Controller Karaf Command On Background    log:set ${bgpcep_level} org.opendaylight.bgpcep
     Execute Controller Karaf Command On Background    log:set ${protocol_level} org.opendaylight.protocol
+
+Wait For Karaf Log
+    [Arguments]    ${message}    ${timeout}=60
+    [Documentation]    Read karaf logs until message appear
+    Log    Waiting for '${message}' in karaf log
+    Open Connection    ${CONTROLLER}    port=${KARAF_SHELL_PORT}    prompt=${KARAF_PROMPT}    timeout=${timeout}
+    Flexible SSH Login    ${KARAF_USER}    ${KARAF_PASSWORD}
+    Write    log:tail
+    Read Until    ${message}
+    Close Connection