Add optional parameter in Openstack lib.
[integration/test.git] / csit / libraries / BGPSpeaker.robot
index edb812ef1e044f9ea7f795aefd51e81e687fcd57..de5f2a8cd29263059848c7b4b2c0358c8d650b11 100644 (file)
@@ -24,10 +24,13 @@ Documentation     Robot keyword library (Resource) for handling the BGP speaker
 ...               want to make the assumption that an SSH connection was already open.
 ...               alternative TODO: Explain that it is not worth to perform separate SSH logins.
 Library           SSHLibrary
-Resource          ${CURDIR}/Utils.robot
+Library           RequestsLibrary
+Resource          RemoteBash.robot
+Resource          ../variables/Variables.robot
 
 *** Variables ***
 ${BGPSpeaker__OUTPUT_LOG}    play.py.out
+${PEER_URL}       restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/peer/bgp:%2F%2F
 
 *** Keywords ***
 Start_BGP_Speaker
@@ -40,6 +43,24 @@ Start_BGP_Speaker
     BuiltIn.Log    ${command}
     ${output} =    SSHLibrary.Write    ${command}
 
+Start_BGP_Speaker_And_Verify_Connected
+    [Arguments]    ${arguments}    ${session}    ${speaker_ip}=${TOOLS_SYSTEM_IP}    ${connected}=${True}
+    [Documentation]    Start the BGP speaker python utility, and verifies it's connection.
+    ...    We can change connected variable to false to verify Speaker did not connect.
+    Start_BGP_Speaker    ${arguments}
+    ${message}    BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_BGP_Speaker_Connection    ${session}    ${speaker_ip}
+    ...    ${connected}
+    [Return]    ${message}
+
+Verify_BGP_Speaker_Connection
+    [Arguments]    ${session}    ${ip}    ${connected}=${True}
+    [Documentation]    Verifies peer's presence in bgp rib.
+    ${exp_status_code}    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
+    ${url}    BuiltIn.Set_Variable    ${PEER_URL}${ip}
+    ${response}    RequestsLibrary.Get_Request    ${session}    ${url}
+    BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${response.status_code}
+    [Return]    ${response.content}
+
 Start_BGP_Manager
     [Arguments]    ${arguments}
     [Documentation]    Start the BGP manager python utility. Redirect its error output to a log file.
@@ -59,7 +80,7 @@ Kill_BGP_Speaker
     [Documentation]    Interrupt play.py, fail if no prompt is seen within SSHLibrary timeout.
     ...    Also dump the logs with the output the program produced.
     ...    This keyword is also suitable for stopping BGP manager.
-    Utils.Write_Bare_Ctrl_C
+    RemoteBash.Write_Bare_Ctrl_C
     ${status}    ${message} =    BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Read_Until_Prompt
     Dump_BGP_Speaker_Logs
     # TODO: When Propagate_Failure is moved to better Resource, use it instead of the following.