creating Normalize_Jsons_With_Bits_And_Compare to TemplatedRequests
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 010_bgp_functional_l3vpn.robot
1 *** Settings ***
2 Documentation     Functional test suite for bgp - l3vpn-ipv4
3 ...
4 ...               Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...               This suite tests advertising and receiveing routes with l3vpn content.
11 ...               It uses odl and exabgp as bgp peers. Routes advertized from odl
12 ...               are configured via application peer. Routes advertised from exabgp is
13 ...               statically configured in exabgp config file.
14 Suite Setup       Start_Suite
15 Suite Teardown    Stop_Suite
16 Library           RequestsLibrary
17 Library           SSHLibrary
18 Variables         ${CURDIR}/../../../variables/Variables.py
19 Resource          ${CURDIR}/../../../libraries/Utils.robot
20 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
21 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
22 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
23 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
24 Library           ${CURDIR}/../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
25
26 *** Variables ***
27 ${HOLDTIME}       180
28 ${DEVICE_NAME}    controller-config
29 ${BGP_PEER_NAME}    example-bgp-peer
30 ${RIB_INSTANCE}    example-bgp-rib
31 ${APP_PEER_NAME}    example-bgp-peer-app
32 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
33 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpfunctional
34 ${BGP_L3VPN_DIR}    ${BGP_VAR_FOLDER}/l3vpn_ipv4
35 ${DEFAUTL_EXA_CFG}    exa.cfg
36 ${L3VPN_EXA_CFG}    bgp-l3vpn-ipv4.cfg
37 ${L3VPN_RSPEMPTY}    ${BGP_L3VPN_DIR}/bgp-l3vpn-ipv4-empty.json
38 ${L3VPN_RSP}      ${BGP_L3VPN_DIR}/bgp-l3vpn-ipv4.json
39 ${L3VPN_URL}      /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/tables/bgp-types:ipv4-address-family/bgp-types:mpls-labeled-vpn-subsequent-address-family/bgp-vpn-ipv4:vpn-ipv4-routes
40 ${CONFIG_SESSION}    config-session
41 ${EXARPCSCRIPT}    ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
42 ${PEER_CHECK_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/peer/bgp:%2F%2F
43 ${DEFAULT_BGPCEP_LOG_LEVEL}    INFO
44
45 *** Test Cases ***
46 Configure_App_Peer
47     [Documentation]    Configures bgp application peer
48     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
49     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}    RIB_INSTANCE_NAME=${RIB_INSTANCE}    APP_PEER_ID=${ODL_SYSTEM_IP}
50     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
51
52 Reconfigure_ODL_To_Accept_Connection
53     [Documentation]    Configures BGP peer module with initiate-connection set to false.
54     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
55     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
56     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}
57     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
58
59 L3vpn_Ipv4_To_Odl
60     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
61     [Setup]    Setup_Testcase    ${L3VPN_EXA_CFG}    ${L3VPN_URL}    ${L3VPN_RSPEMPTY}
62     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify Reported Data    ${L3VPN_URL}    ${L3VPN_RSP}
63     [Teardown]    Teardown_Testcase    ${L3VPN_URL}    ${L3VPN_RSPEMPTY}
64
65 L3vpn_Ipv4_From_Odl
66     [Documentation]    Testing mpls vpn ipv4 routes reported from odl to exabgp
67     [Setup]    Start_Tool_And_Verify_Connected    ${DEFAUTL_EXA_CFG}
68     BgpRpcClient.exa_clean_update_message
69     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}
70     TemplatedRequests.Post_As_Xml_Templated    ${BGP_L3VPN_DIR}/route    mapping=${mapping}    session=${CONFIG_SESSION}
71     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_Tool_Received_Update    ${BGP_L3VPN_DIR}/route/exa-expected.json
72     [Teardown]    Remove_Route_And_Stop_Tool
73
74 Delete_Bgp_Peer_Configuration
75     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
76     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
77     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}
78     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
79
80 Deconfigure_App_Peer
81     [Documentation]    Revert the BGP configuration to the original state: without application peer
82     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
83     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}
84     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
85
86 *** Keywords ***
87 Start_Suite
88     [Documentation]    Suite setup keyword
89     SetupUtils.Setup_Utils_For_Setup_And_Teardown
90     ${tools_system_conn_id}=    SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
91     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
92     Utils.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
93     SSHKeywords.Virtual_Env_Create
94     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
95     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
96     Upload_Config_Files
97     KarafKeywords.Set_Bgpcep_Log_Levels    # ${DEFAULT_BGPCEP_LOG_LEVEL} is applied by default
98
99 Stop_Suite
100     [Documentation]    Suite teardown keyword
101     SSHKeywords.Virtual_Env_Delete
102     SSHLibrary.Close_All_Connections
103     RequestsLibrary.Delete_All_Sessions
104
105 Upload_Config_Files
106     [Documentation]    Uploads exabgp config files and needed scripts
107     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAUTL_EXA_CFG}    .
108     SSHLibrary.Put_File    ${BGP_L3VPN_DIR}/${L3VPN_EXA_CFG}    .
109     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
110     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
111     : FOR    ${cfgfile}    IN    @{cfgfiles}
112     \    SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
113     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
114     \    SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
115     \    SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
116     \    ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
117     \    Log    ${stdout}
118
119 Setup_Testcase
120     [Arguments]    ${cfg_file}    ${url}    ${empty_response}
121     [Documentation]    Verifies initial test condition and starts the tool
122     Verify_Reported_Data    ${url}    ${empty_response}
123     Start_Tool_And_Verify_Connected    ${cfg_file}
124
125 Start_Tool
126     [Arguments]    ${cfg_file}    ${mapping}={}
127     [Documentation]    Start the tool ${cmd} ${cfg_file}
128     ${start_cmd}    BuiltIn.Set_Variable    ${cmd} ${cfg_file}
129     BuiltIn.Log    ${start_cmd}
130     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
131     ${output}=    SSHLibrary.Write    ${start_cmd}
132     BuiltIn.Log    ${output}
133
134 Verify_Tools_Connection
135     [Arguments]    ${connected}=${True}
136     [Documentation]    Checks peer presence in operational datastore
137     ${exp_status_code}=    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
138     ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    ${PEER_CHECK_URL}${TOOLS_SYSTEM_IP}
139     BuiltIn.Log    ${rsp.content}
140     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}
141
142 Start_Tool_And_Verify_Connected
143     [Arguments]    ${cfg_file}
144     [Documentation]    Start the tool and verify its connection
145     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
146     Start_Tool    ${cfg_file}
147     BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s    Verify_Tools_Connection    connected=${True}
148
149 Stop_Tool
150     [Documentation]    Stop the tool by sending ctrl+c
151     ${output}=    SSHLibrary.Read
152     BuiltIn.Log    ${output}
153     Utils.Write_Bare_Ctrl_C
154     ${output}=    SSHLibrary.Read_Until_Prompt
155     BuiltIn.Log    ${output}
156     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
157
158 Remove_Route_And_Stop_Tool
159     [Documentation]    Removes configured route from application peer and stops the tool
160     &{mapping}    BuiltIn.Create_Dictionary
161     TemplatedRequests.Delete_Templated    ${BGP_L3VPN_DIR}/route    mapping=${mapping}    session=${CONFIG_SESSION}
162     Stop_Tool
163
164 Teardown_Testcase
165     [Arguments]    ${url}    ${empty_response}
166     [Documentation]    Testcse teardown with data verification
167     Stop_Tool
168     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Verify_Reported_Data    ${url}    ${empty_response}
169
170 Verify_Tool_Received_Update
171     [Arguments]    ${exp_update_fn}
172     [Documentation]    Verification of receiving particular update message
173     ${exp_update}=    Get_Expected_Response_From_File    ${exp_update_fn}
174     ${rcv_update_dict}=    BgpRpcClient.exa_get_update_message    msg_only=${True}
175     ${rcv_update}=    BuiltIn.Evaluate    json.dumps(${rcv_update_dict})    modules=json
176     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_update}    ${rcv_update}
177
178 Verify_Reported_Data
179     [Arguments]    ${url}    ${exprspfile}
180     [Documentation]    Verifies expected response
181     ${expected_rsp}=    Get_Expected_Response_From_File    ${exprspfile}
182     ${rsp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${url}
183     TemplatedRequests.Normalize_Jsons_And_Compare    ${expected_rsp}    ${rsp.content}
184
185 Get_Expected_Response_From_File
186     [Arguments]    ${exprspfile}
187     [Documentation]    Looks for release specific response first, then take default.
188     ${status}    ${expresponse}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get File    ${exprspfile}.${ODL_STREAM}
189     Return From Keyword If    '${status}' == 'PASS'    ${expresponse}
190     ${expresponse}=    OperatingSystem.Get File    ${exprspfile}
191     [Return]    ${expresponse}