Added BGP_PORT and BGP_TOOL_PORT
[integration/test.git] / csit / suites / bgpcep / bgpuser / cases.robot
index 4cc685016883ab8fe439e3e1e018a2be126d12c3..eba29808ecda370c578a915fc3d77f1820289ece 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
@@ -41,16 +42,13 @@ Check_For_Empty_Topology_Before_Talking
 
 Reconfigure_ODL_To_Accept_Connection
     [Documentation]    Configure BGP peer module with initiate-connection set to false.
-    ${template_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'HOLDTIME': '${HOLDTIME}', 'INITIATE': 'false'}
+    ${template_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}bgp_peer    ${template_as_string}
 
 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=${BGP_TOOL_PORT} --peerip=${CONTROLLER} --peerport=${ODL_BGP_PORT}
     Read_And_Fail_If_Prompt_Is_Seen
 
 Check_Talking_Connection_Is_Established
@@ -66,7 +64,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 +76,7 @@ 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=${BGP_TOOL_PORT} --peerip=${CONTROLLER}
     Read_And_Fail_If_Prompt_Is_Seen
 
 Check_Listening_Connection_Is_Not_Established_Yet
@@ -95,7 +90,7 @@ Check_For_Empty_Topology_Before_Listening
 
 Reconfigure_ODL_To_Initiate_Connection
     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
-    ${template_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'HOLDTIME': '${HOLDTIME}', 'INITIATE': 'true'}
+    ${template_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}bgp_peer    ${template_as_string}
 
 Check_Listening_Connection_Is_Established
@@ -110,7 +105,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 +187,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 +203,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}