Library for handling BGP speaker tool
[integration/test.git] / csit / suites / bgpcep / bgpuser / cases.robot
index 4cc685016883ab8fe439e3e1e018a2be126d12c3..4cd26d8a9e10d49442dda58af5760d781fff1ee1 100644 (file)
@@ -22,6 +22,7 @@ Variables         ${CURDIR}/../../../variables/Variables.py
 Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${MININET}
 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
 Resource          ${CURDIR}/../../../libraries/FailFast.robot
+Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
 Resource          ${CURDIR}/../../../libraries/Utils.robot
@@ -46,11 +47,9 @@ Reconfigure_ODL_To_Accept_Connection
 
 Start_Talking_BGP_speaker
     [Documentation]    Start Python speaker to connect to ODL, verify that the tool does not promptly exit.
-    ${command}=    BuiltIn.Set_Variable    python play.py --amount 2 --myip=${MININET} --myport=17900 --peerip=${CONTROLLER} --peerport=1790
     # Myport value is needed for checking whether connection at precise port was established.
     # TODO: Do we want to define ${BGP_PORT} in Variables.py?
-    BuiltIn.Log    ${command}
-    ${output}=    SSHLibrary.Write    ${command}
+    BGPSpeaker.Start_BGP_Speaker    --amount 2 --myip=${MININET} --myport=17900 --peerip=${CONTROLLER} --peerport=1790
     Read_And_Fail_If_Prompt_Is_Seen
 
 Check_Talking_Connection_Is_Established
@@ -66,7 +65,7 @@ Check_Talking_Topology_Is_Filled
 Kill_Talking_BGP_Speaker
     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
     [Setup]    FailFast.Run_Even_When_Failing_Fast
-    Kill_BGP_Speaker
+    BGPSpeaker.Kill_BGP_Speaker
     FailFast.Do_Not_Fail_Fast_From_Now_On
     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
@@ -78,10 +77,8 @@ Check_For_Empty_Topology_After_Talking
 
 Start_Listening_BGP_Speaker
     [Documentation]    Start Python speaker in listening mode, verify that the tool does not exit quickly.
-    ${command}=    BuiltIn.Set_Variable    python play.py --amount 2 --listen --myip=${MININET} --myport=17900 --peerip=${CONTROLLER}
     # TODO: ${BGP_TOOL_PORT} is probably not worth the trouble.
-    Builtin.Log    ${command}
-    ${output}=    SSHLibrary.Write    ${command}
+    BGPSpeaker.Start_BGP_Speaker    --amount 2 --listen --myip=${MININET} --myport=17900 --peerip=${CONTROLLER}
     Read_And_Fail_If_Prompt_Is_Seen
 
 Check_Listening_Connection_Is_Not_Established_Yet
@@ -110,7 +107,7 @@ Check_Listening_Topology_Is_Filled
 Kill_Listening_BGP_Speaker
     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
     [Setup]    FailFast.Run_Even_When_Failing_Fast
-    Kill_BGP_Speaker
+    BGPSpeaker.Kill_BGP_Speaker
     FailFast.Do_Not_Fail_Fast_From_Now_On
     # NOTE: It is still possible to remain failing, if both previous and this test failed.
     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
@@ -192,13 +189,6 @@ Normalize_And_Save_Expected_Json
     # TODO: Should we prepend .json to the filename? When we detect it is not already prepended?
     [Return]    ${json_normalized}
 
-Kill_BGP_Speaker
-    [Documentation]    Interrupt play.py, fail if no prompt is seen within SSHLibrary timeout.
-    ...    Also, check that TCP connection is no longer established.
-    Write_Bare_Ctrl_C
-    SSHLibrary.Read_Until_Prompt
-    Check_Speaker_Is_Not_Connected
-
 Check_Speaker_Is_Not_Connected
     [Documentation]    Give it a few tries to see zero established connections.
     BuiltIn.Wait_Until_Keyword_Succeeds    3s    1s    Check_Number_Of_Speaker_Connections    0
@@ -215,16 +205,13 @@ Check_Number_Of_Speaker_Connections
 
 Read_And_Fail_If_Prompt_Is_Seen
     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
-    BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
+    ${passed}=    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
+    BuiltIn.Return_From_Keyword_If    ${passed}
+    BGPSpeaker.Dump_BGP_Speaker_Logs
+    Builtin.Fail    The prompt was seen but it was not expected yet
 
 Read_Text_Before_Prompt
     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
     ${text}=    SSHLibrary.Read_Until_Prompt
     BuiltIn.Log    ${text}
-
-Write_Bare_Ctrl_C
-    [Documentation]    Construct ctrl+c character and SSH-write it (without endline). Do not read anything yet.
-    # TODO: Place this keyword to some Resource so that it can be re-used in other suites.
-    ${command}=    BuiltIn.Evaluate    chr(int(3))
-    SSHLibrary.Write_Bare    ${command}