Migrate Get Requests invocations(libraries)
[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 ...
15 ...                 For fluorine and further, instead of exabgp, play.py is used. When sending
16 ...                 routes from odl to peer, first route containg route-target argument have to
17 ...                 be send from peer to odl, so odl can identify this peer. Than it sends l3vpn
18 ...                 route containg this argument to odl app peer, and we check that app peer
19 ...                 advertizes this route back to the peer.
20
21 Library             RequestsLibrary
22 Library             SSHLibrary
23 Library             ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
24 Resource            ../../../libraries/BGPcliKeywords.robot
25 Resource            ../../../libraries/BgpOperations.robot
26 Resource            ../../../libraries/BGPSpeaker.robot
27 Resource            ../../../libraries/CompareStream.robot
28 Resource            ../../../libraries/ExaBgpLib.robot
29 Resource            ../../../libraries/SetupUtils.robot
30 Resource            ../../../libraries/SSHKeywords.robot
31 Resource            ../../../libraries/TemplatedRequests.robot
32 Resource            ../../../variables/Variables.robot
33
34 Suite Setup         Start_Suite
35 Suite Teardown      Stop_Suite
36 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
37
38
39 *** Variables ***
40 ${BGP_L3VPN_DIR}                ${BGP_VAR_FOLDER}/l3vpn_ipv4
41 ${BGP_VAR_FOLDER}               ${CURDIR}/../../../variables/bgpfunctional
42 ${CONFIG_SESSION}               config-session
43 ${DEFAULT_BGPCEP_LOG_LEVEL}     INFO
44 ${DEFAULT_EXA_CFG}              exa.cfg
45 ${EXARPCSCRIPT}                 ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
46 ${HOLDTIME}                     180
47 ${L3VPN_EXA_CFG}                bgp-l3vpn-ipv4.cfg
48 ${L3VPN_EXP}                    exa_expected
49 ${L3VPN_RSP}                    bgp_l3vpn_ipv4
50 ${L3VPN_RSPEMPTY}               bgp_l3vpn_ipv4_empty
51 ${PLAY_SCRIPT}                  ${CURDIR}/../../../../tools/fastbgp/play.py
52 ${RIB_INSTANCE}                 example-bgp-rib
53 ${RT_CONSTRAIN_DIR}             ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
54
55
56 *** Test Cases ***
57 Configure_App_Peer
58     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
59     &{mapping}    BuiltIn.Create_Dictionary    BGP_RIB=${RIB_INSTANCE}    IP=${ODL_SYSTEM_IP}
60     TemplatedRequests.Put_As_Xml_Templated
61     ...    ${RT_CONSTRAIN_DIR}/app_peer
62     ...    mapping=${mapping}
63     ...    session=${CONFIG_SESSION}
64
65 Reconfigure_ODL_To_Accept_Connection
66     [Documentation]    Configures BGP peer module with initiate-connection set to false.
67     &{mapping}    BuiltIn.Create_Dictionary
68     ...    IP=${TOOLS_SYSTEM_IP}
69     ...    BGP_RIB=${RIB_INSTANCE}
70     ...    HOLDTIME=${HOLDTIME}
71     ...    PEER_PORT=${BGP_TOOL_PORT}
72     ...    INITIATE=false
73     ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
74     ...    PASSIVE_MODE=true
75     TemplatedRequests.Put_As_Xml_Templated
76     ...    ${RT_CONSTRAIN_DIR}/bgp_peer
77     ...    mapping=${mapping}
78     ...    session=${CONFIG_SESSION}
79
80 L3vpn_Ipv4_To_Odl
81     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
82     [Setup]    Setup_Testcase    ${L3VPN_EXA_CFG}
83     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Reported_Data    ${L3VPN_RSP}
84     [Teardown]    Teardown_Simple
85
86 Start_Play
87     [Documentation]    Start Python speaker to connect to ODL. We need to do WUKS until odl really starts to accept incomming bgp connection. The failure happens if the incomming connection comes too quickly after configuring the peer in the previous test case.
88     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
89     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
90     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
91     SSHLibrary.Read
92     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Start_Bgp_Peer
93
94 Play_To_Odl_rt_constrain_type_0
95     [Documentation]    This keyword sends route-target route containg route-target argument so odl
96     ...    can identify this peer as appropriate for advertizement when it recieves such route.
97     BgpOperations.Play_To_Odl_Non_Removal_Template    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
98
99 Odl_To_Play_l3vpn_rt_arg
100     [Documentation]    Same as TC before but fluorine and further this l3vpn route also needs to contain route-target argument.
101     BgpOperations.Odl_To_Play_Template    l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}    False
102
103 Kill_Talking_BGP_Speaker
104     [Documentation]    Abort the Python speaker
105     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
106     BGPSpeaker.Kill_BGP_Speaker
107     BGPcliKeywords.Store_File_To_Workspace    play.py.out    010_l3vpn_play.log
108
109 Delete_Bgp_Peer_Configuration
110     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
111     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB=${RIB_INSTANCE}
112     TemplatedRequests.Delete_Templated
113     ...    ${RT_CONSTRAIN_DIR}/bgp_peer
114     ...    mapping=${mapping}
115     ...    session=${CONFIG_SESSION}
116
117 Deconfigure_App_Peer
118     [Documentation]    Revert the BGP configuration to the original state: without application peer
119     &{mapping}    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_INSTANCE}
120     TemplatedRequests.Delete_Templated
121     ...    ${RT_CONSTRAIN_DIR}/app_peer
122     ...    mapping=${mapping}
123     ...    session=${CONFIG_SESSION}
124
125
126 *** Keywords ***
127 Start_Suite
128     [Documentation]    Suite setup keyword.
129     SetupUtils.Setup_Utils_For_Setup_And_Teardown
130     ${tools_system_conn_id}    SSHLibrary.Open_Connection
131     ...    ${TOOLS_SYSTEM_IP}
132     ...    prompt=${DEFAULT_LINUX_PROMPT}
133     ...    timeout=6s
134     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
135     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
136     SSHKeywords.Virtual_Env_Create
137     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
138     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
139     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
140     Upload_Config_Files
141
142 Stop_Suite
143     [Documentation]    Suite teardown keyword
144     SSHKeywords.Virtual_Env_Delete
145     SSHLibrary.Close_All_Connections
146     RequestsLibrary.Delete_All_Sessions
147
148 Upload_Config_Files
149     [Documentation]    Uploads exabgp config files and needed scripts
150     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAULT_EXA_CFG}    .
151     SSHLibrary.Put_File    ${BGP_L3VPN_DIR}/${L3VPN_EXA_CFG}    .
152     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
153     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
154     FOR    ${cfgfile}    IN    @{cfgfiles}
155         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
156         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
157         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
158         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
159         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
160         Log    ${stdout}
161     END
162
163 Setup_Testcase
164     [Documentation]    Verifies initial test condition and starts the exabgp
165     [Arguments]    ${cfg_file}
166     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
167     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
168     ExaBgpLib.Start_ExaBgp_And_Verify_Connected
169     ...    ${cfg_file}
170     ...    ${CONFIG_SESSION}
171     ...    ${TOOLS_SYSTEM_IP}
172     ...    connection_retries=${3}
173
174 Teardown_Simple
175     [Documentation]    Testcse teardown with data verification
176     ExaBgpLib.Stop_ExaBgp
177     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
178
179 Verify_ExaBgp_Received_Update
180     [Documentation]    Verification of receiving particular update message
181     [Arguments]    ${exp_update_fn}
182     ${exp_update}    TemplatedRequests.Resolve_Text_From_Template_File
183     ...    ${BGP_L3VPN_DIR}${/}${exp_update_fn}
184     ...    data.json
185     ${rcv_update_dict}    BgpRpcClient.exa_get_update_message    msg_only=${True}
186     ${rcv_update}    BuiltIn.Evaluate    json.dumps(${rcv_update_dict})    modules=json
187     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_update}    ${rcv_update}
188
189 Verify_Empty_Reported_Data
190     [Documentation]    Verfiy empty data response
191     Verify_Empty_Data_Neon
192
193 Verify_Reported_Data
194     [Documentation]    Verifies expected response
195     [Arguments]    ${exprspdir}
196     TemplatedRequests.Get_As_Json_Templated
197     ...    ${BGP_L3VPN_DIR}${/}${exprspdir}
198     ...    session=${CONFIG_SESSION}
199     ...    verify=True
200
201 Start_Bgp_Peer
202     [Documentation]    Starts bgp peer and verifies that the peer runs.
203     BGPSpeaker.Start_BGP_Speaker
204     ...    --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --debug --allf --wfr 1
205     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
206
207 L3vpn_Ipv4_To_App
208     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
209     BgpRpcClient.exa_clean_update_message
210     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}    APP_PEER_IP=${ODL_SYSTEM_IP}
211     TemplatedRequests.Post_As_Xml_Templated
212     ...    ${BGP_L3VPN_DIR}/route
213     ...    mapping=${mapping}
214     ...    session=${CONFIG_SESSION}
215     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Update    ${L3VPN_EXP}
216
217 Verify_Empty_Data_Neon
218     [Documentation]    Verify empty data on neon
219     TemplatedRequests.Get_As_Json_Templated
220     ...    ${BGP_L3VPN_DIR}${/}empty_route
221     ...    session=${CONFIG_SESSION}
222     ...    verify=True