Minimize connection time in new BGP cluster suites
[integration/test.git] / csit / suites / bgpcep / bgpflowspec / 010_bgp_flowspec.robot
index 36c3c910b519d3aee8480d5436dee205d5cbf4ef..dfe9251d78d1528b6ba73160440d95c1fa0f4da7 100644 (file)
@@ -11,11 +11,12 @@ Suite Teardown    Stop Suite
 Library           RequestsLibrary
 Library           SSHLibrary
 Variables         ${CURDIR}/../../../variables/Variables.py
-Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}
+Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}    ${ODL_STREAM}
+Resource          ${CURDIR}/../../../libraries/ExaBgpLib.robot
 Resource          ${CURDIR}/../../../libraries/Utils.robot
 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
-Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
-Library           ${CURDIR}/../../../libraries/norm_json.py
+Resource          ${CURDIR}/../../../libraries/CompareStream.robot
+Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
 
 *** Variables ***
 ${HOLDTIME}       180
@@ -27,6 +28,11 @@ ${EXP1}           bgp-flowspec.json
 ${CFG2}           bgp-flowspec-redirect.cfg
 ${EXP2}           bgp-flowspec-redirect.json
 ${FLOWSPEC_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/tables/bgp-types:ipv4-address-family/bgp-flowspec:flowspec-subsequent-address-family/bgp-flowspec:flowspec-routes
+${CONFIG_SESSION}    session
+${DEVICE_NAME}    controller-config
+${BGP_PEER_NAME}    example-bgp-peer
+${RIB_INSTANCE}    example-bgp-rib
+${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
 
 *** Test Cases ***
 Check_For_Empty_Topology_Before_Talking
@@ -36,20 +42,26 @@ 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    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
-    ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}    ${template_as_string}
+    &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
+    ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
+    TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
 
 FlowSpec Test 1
     [Documentation]    Testing flowspec values for ${CFG1}
     [Setup]    Setup Testcase    ${CFG1}
     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP1}
-    [Teardown]    Stop_Tool
+    [Teardown]    ExaBgpLib.Stop_ExaBgp
 
 FlowSpec Test 2
     [Documentation]    Testing flowspec values for ${CFG2}
     [Setup]    Setup Testcase    ${CFG2}
     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP2}
-    [Teardown]    Stop_Tool
+    [Teardown]    ExaBgpLib.Stop_ExaBgp
+
+Deconfigure_ODL_To_Accept_Connection
+    [Documentation]    Deconfigure BGP peer.
+    &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
+    TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
 
 *** Keywords ***
 Start Suite
@@ -63,13 +75,11 @@ Start Suite
     ...    return_rc=True
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo pip install exabgp    return_stdout=True    return_stderr=True
     ...    return_rc=True
-    RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
-    ConfigViaRestconf.Setup_Config_Via_Restconf
+    RequestsLibrary.Create Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
     Upload Config Files    ${CURDIR}/../../../variables/bgpflowspec/
 
 Stop Suite
     [Documentation]    Suite teardown keyword
-    ConfigViaRestconf.Teardown_Config_Via_Restconf
     SSHLibrary.Close All Connections
     RequestsLibrary.Delete All Sessions
 
@@ -87,26 +97,7 @@ Upload Config Files
 Setup Testcase
     [Arguments]    ${cfg_file}
     Verify Empty Flowspec Data
-    Start Tool    ${cfg_file}
-
-Start_Tool
-    [Arguments]    ${cfg_file}
-    [Documentation]    Start the tool ${cmd} ${cfg_file}
-    BuiltIn.Log    ${cmd} ${cfg_file}
-    ${output}=    SSHLibrary.Write    ${cmd} ${cfg_file}
-    BuiltIn.Log    ${output}
-
-Wait_Until_Tool_Finish
-    [Arguments]    ${timeout}
-    [Documentation]    Wait ${timeout} for the tool exit.
-    BuiltIn.Wait Until Keyword Succeeds    ${timeout}    1s    SSHLibrary.Read Until Prompt
-
-Stop_Tool
-    [Documentation]    Stop the tool if still running.
-    Utils.Write_Bare_Ctrl_C
-    ${output}=    SSHLibrary.Read    delay=1s
-    BuiltIn.Log    ${output}
-    Verify Empty Flowspec Data
+    ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
 
 Verify Empty Flowspec Data
     [Documentation]    Verify expected response.
@@ -115,12 +106,16 @@ Verify Empty Flowspec Data
 Verify Flowspec Data
     [Arguments]    ${exprspfile}
     [Documentation]    Verify expected response
-    ${keys_with_bits}=    BuiltIn.Create_List    op
-    ${expected_rsp}=    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}
-    ${expected_json}=    norm_json.Normalize Json Text    ${expected_rsp}    keys_with_bits=${keys_with_bits}
-    ${rsp}=    RequestsLibrary.Get Request    session    ${FLOWSPEC_URL}
-    BuiltIn.Log    ${rsp.content}
-    ${received_json}=    norm_json.Normalize Json Text    ${rsp.content}    keys_with_bits=${keys_with_bits}
-    BuiltIn.Log    ${received_json}
-    BuiltIn.Log    ${expected_json}
-    BuiltIn.Should Be Equal    ${received_json}    ${expected_json}
+    ${keys_with_bits}=    BuiltIn.Create_List
+    CompareStream.Run_Keyword_If_At_Most    boron    Collections.Append_To_List    ${keys_with_bits}    op
+    ${expected_rsp}=    Get Expected Response From File    ${exprspfile}
+    ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
+    TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare    ${expected_rsp}    ${rsp.content}    keys_with_bits=${keys_with_bits}
+
+Get Expected Response From File
+    [Arguments]    ${exprspfile}
+    [Documentation]    Looks for release specific response first, then take default.
+    ${status}    ${expresponse}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}.${ODL_STREAM}
+    Return From Keyword If    '${status}' == 'PASS'    ${expresponse}
+    ${expresponse}=    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}
+    [Return]    ${expresponse}