Fix bgpcep-1node-userfeatures tests
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 030_bgp_functional_evpn.robot
index a6cdefc20742d6f4baab305413cd44575fd5bb5c..58d316ecbb80281f69d3f3393ac1eb3f3f49870c 100644 (file)
@@ -15,13 +15,14 @@ Documentation     Functional test for bgp - evpn
 Suite Setup       Start_Suite
 Suite Teardown    Stop_Suite
 Test Setup        Run Keywords    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
-...               AND    Verify Test Preconditions
+...               AND    Verify_Test_Preconditions
 Test Template     Odl_To_Play_Template
 Library           RequestsLibrary
 Library           SSHLibrary
 Library           String
 Library           ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
 Resource          ../../../libraries/BGPcliKeywords.robot
+Resource          ../../../libraries/BgpOperations.robot
 Resource          ../../../libraries/BGPSpeaker.robot
 Resource          ../../../libraries/CompareStream.robot
 Resource          ../../../libraries/SetupUtils.robot
@@ -41,6 +42,10 @@ ${PLAY_SCRIPT}    ${CURDIR}/../../../../tools/fastbgp/play.py
 ${SS}             ${SPACE}${SPACE}${SPACE}${SPACE}
 ${PATH_ID_JSON}    ${SS}${SS}"path-id": 0,${\n}
 ${PATH_ID_XML}    ${SS}<path-id>0</path-id>${\n}
+${OLD_EVPN_ROUTES_LINE}    \n"odl-bgp-evpn:evpn-routes": {},
+${NEW_EVPN_ROUTES_LINE}    ${EMPTY}
+${OLD_AS_PATH}    ,\n"as-path": {}
+${NEW_AS_PATH}    ${EMPTY}
 
 *** Test Cases ***
 Configure_App_Peer
@@ -348,9 +353,12 @@ Start_Suite
     RequestsLibrary.Create Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
     SSHLibrary.Put File    ${PLAY_SCRIPT}    .
     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
-    BuiltIn.Set_Suite_Variable    ${EVPN_CONF_URL}    /restconf/config/bgp-rib:application-rib/${ODL_SYSTEM_IP}/tables/odl-bgp-evpn:l2vpn-address-family/odl-bgp-evpn:evpn-subsequent-address-family/odl-bgp-evpn:evpn-routes/
-    BuiltIn.Set_Suite_Variable    ${EVPN_LOC_RIB}    /restconf/operational/bgp-rib:bgp-rib/rib/${RIB_NAME}/loc-rib/tables/odl-bgp-evpn:l2vpn-address-family/odl-bgp-evpn:evpn-subsequent-address-family/odl-bgp-evpn:evpn-routes
-    ${EMPTY_ROUTES} =    OperatingSystem.Get_File    ${EVPN_DIR}/empty_routes/empty_routes.json
+    BuiltIn.Set_Suite_Variable    ${EVPN_CONF_URL}    /rests/data/bgp-rib:application-rib=${ODL_SYSTEM_IP}/tables=odl-bgp-evpn%3Al2vpn-address-family,odl-bgp-evpn%3Aevpn-subsequent-address-family/odl-bgp-evpn:evpn-routes
+    BuiltIn.Set_Suite_Variable    ${EVPN_LOC_RIB}    /rests/data/bgp-rib:bgp-rib/rib=${RIB_NAME}/loc-rib/tables=odl-bgp-evpn%3Al2vpn-address-family,odl-bgp-evpn%3Aevpn-subsequent-address-family/odl-bgp-evpn:evpn-routes?content=nonconfig
+    BuiltIn.Set_Suite_Variable    ${EVPN_FAMILY_LOC_RIB}    /rests/data/bgp-rib:bgp-rib/rib=${RIB_NAME}/loc-rib/tables=odl-bgp-evpn%3Al2vpn-address-family,odl-bgp-evpn%3Aevpn-subsequent-address-family?content=nonconfig
+    ${evpn_routes_line} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_EVPN_ROUTES_LINE}    ${OLD_EVPN_ROUTES_LINE}
+    &{mapping}    BuiltIn.Create_Dictionary    EVPN_ROUTES=${evpn_routes_line}
+    ${EMPTY_ROUTES} =    TemplatedRequests.Resolve_Text_From_Template_File    ${EVPN_DIR}/empty_routes    empty_routes.json    ${mapping}
     BuiltIn.Set_Suite_Variable    ${EMPTY_ROUTES}
 
 Stop_Suite
@@ -380,23 +388,25 @@ Odl_To_Play_Template
     BgpRpcClient.play_clean
     ${resp} =    RequestsLibrary.Post_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}    data=${post_data_xml}    headers=${HEADERS_XML}
     BuiltIn.Log    ${resp.content}
-    BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    204
-    ${resp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}    headers=${HEADERS_XML}
+    BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    201
+    ${resp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}?content=config    headers=${HEADERS_XML}
     BuiltIn.Log    ${resp.content}
     ${aupdate} =    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Get_Update_Content
     BuiltIn.Log    ${aupdate}
-    BuiltIn.Should_Be_Equal_As_Strings    ${aupdate}    ${announce_hex}
+    BgpOperations.Verify_Two_Hex_Messages_Are_Equal    ${aupdate}    ${announce_hex}
     BgpRpcClient.play_clean
     Remove_Configured_Routes
     ${wupdate} =    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Get_Update_Content
     BuiltIn.Log    ${wupdate}
-    BuiltIn.Should Be Equal As Strings    ${wupdate}    ${withdraw_hex}
+    BgpOperations.Verify_Two_Hex_Messages_Are_Equal    ${wupdate}    ${withdraw_hex}
     [Teardown]    Remove_Configured_Routes
 
 Play_To_Odl_Template
     [Arguments]    ${totest}
     ${data_xml} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/${totest}.xml
-    ${data_json} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/${totest}.json
+    ${AS_PATH} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
+    &{mapping}    BuiltIn.Create_Dictionary    AS_PATH=${AS_PATH}
+    ${data_json} =    TemplatedRequests.Resolve_Text_From_Template_File    ${EVPN_DIR}/${totest}    ${totest}.json    ${mapping}
     ${announce_hex} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/announce_${totest}.hex
     ${withdraw_hex} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/withdraw_${totest}.hex
     ${data_path_json}    CompareStream.Run_Keyword_If_Less_Than_Fluorine    String.Replace_String    ${data_json}    ${PATH_ID_JSON}    ${EMPTY}
@@ -409,29 +419,30 @@ Play_To_Odl_Template
     BgpRpcClient.play_send    ${announce_hex}
     BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Loc_Rib_Presence    ${data_json_exp}
     BgpRpcClient.play_send    ${withdraw_hex}
-    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Loc_Rib_Presence    ${EMPTY_ROUTES}
+    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Verify_Test_Preconditions
     [Teardown]    Withdraw_Route_And_Verify    ${withdraw_hex}
 
 Verify_Test_Preconditions
-    ${resp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}
-    BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    404
-    Loc_Rib_Presence    ${EMPTY_ROUTES}
+    ${resp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}?content=config
+    BuiltIn.Should_Contain    ${DELETED_STATUS_CODES}    ${resp.status_code}
+    ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_FAMILY_LOC_RIB}    headers=${HEADERS}
+    TemplatedRequests.Normalize_Jsons_And_Compare    ${EMPTY_ROUTES}    ${rsp.content}
 
 Remove_Configured_Routes
     [Documentation]    Removes the route if present. First GET is for debug purposes.
     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_LOC_RIB}    headers=${HEADERS}
     Log    ${rsp.content}
-    ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}    headers=${HEADERS}
+    ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}?content=config    headers=${HEADERS}
     Log    ${rsp.content}
-    BuiltIn.Return_From_Keyword_If    "${rsp.status_code}" == "404"
+    BuiltIn.Return_From_Keyword_If    ${rsp.status_code} in ${DELETED_STATUS_CODES}
     ${resp} =    RequestsLibrary.Delete_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}
-    BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    200
+    BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    204
 
 Withdraw_Route_And_Verify
     [Arguments]    ${withdraw_hex}
     [Documentation]    Sends withdraw update message from exabgp and verifies route removal from odl's rib
     BgpRpcClient.play_send    ${withdraw_hex}
-    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Loc_Rib_Presence    ${EMPTY_ROUTES}
+    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Test_Preconditions
 
 Get_Update_Content
     [Documentation]    Gets received data from odl's peer
@@ -445,4 +456,5 @@ Loc_Rib_Presence
     [Arguments]    ${exp_content}
     [Documentation]    Verifies if loc-rib contains expected data
     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_LOC_RIB}    headers=${HEADERS}
+    BuiltIn.Log_Many    ${exp_content}    ${rsp.content}
     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_content}    ${rsp.content}