Keyword to log messages to controller's karaf log
authorJozef Behran <jbehran@cisco.com>
Wed, 26 Aug 2015 11:45:27 +0000 (13:45 +0200)
committerJozef Behran <jbehran@cisco.com>
Thu, 27 Aug 2015 11:55:54 +0000 (13:55 +0200)
The keyword "Log Message To Controller Karaf" sends the
specified text to the Karaf log. It makes initialization
on its first call so no special initialization is necessary
and it does not drain any resources from suites that don't
use it. This keyword is not "cluster friendly" as it always
sends the message to the controller which is specified using
the "CONTROLLER" Robot variable.

Change-Id: I07417c242b5ad0e8fea2ee9910d2b44764a02ade
Signed-off-by: Jozef Behran <jbehran@cisco.com>
test/csit/libraries/Utils.robot

index 2b83078f14b55052ab53da9a9b81aa76249f38ff..f330170f2ffefbeeac76b062550066af054d39ae 100644 (file)
@@ -9,6 +9,7 @@ Variables           ../variables/Variables.py
 *** Variables ***
 # TODO: Introduce ${tree_size} and use instead of 1 in the next line.
 ${start}          sudo mn --controller=remote,ip=${CONTROLLER} --topo tree,1 --switch ovsk,protocols=OpenFlow13
+${controller_index}    -1
 
 *** Keywords ***
 Start Suite
@@ -37,6 +38,27 @@ Start Mininet
     Read Until    mininet>
     [Return]    ${mininet_conn_id}
 
+Connect To Controller Karaf
+    [Documentation]    Connect to the controller's karaf console.
+    ${connection}=    SSHLibrary.Open_Connection    ${CONTROLLER}    port=${KARAF_SHELL_PORT}    prompt=>
+    Set Suite Variable    ${controller_index}    ${connection}
+    SSHLibrary.Login    ${KARAF_USER}    ${KARAF_PASSWORD}
+
+Log Message To Controller Karaf
+    [Arguments]    ${message}
+    [Documentation]    Send a message into the controller's karaf log file.
+    # Background info: If there was no previous SSH connection, the "Get
+    # Connection" returns an information structure whose "index" field
+    # resolves to "None", and the "Switch Connection" below does not
+    # complain.
+    ${current}=    Get_Connection
+    ${connection}=    Set Variable    ${current.index}
+    BuiltIn.Run Keyword If    ${controller_index} <> -1    Switch Connection    ${controller_index}
+    BuiltIn.Run Keyword If    ${controller_index} == -1    Connect to Controller Karaf
+    SSHLibrary.Write    log:log "ROBOT MESSAGE: ${message}"
+    SSHLibrary.Read_Until_Prompt
+    Switch Connection    ${connection}
+
 Stop Mininet
     [Arguments]    ${mininet_conn_id}    ${prompt}=${DEFAULT_LINUX_PROMPT}
     [Documentation]    Basic setup to stop/clean mininet