Update Robot Framework format - step 3
[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 ${L3VPN_RSP_PATH}               bgp_l3vpn_ipv4_path
52 ${OLD_AS_PATH}                  \n"as-path": {},
53 ${NEW_AS_PATH}                  ${EMPTY}
54 ${PLAY_SCRIPT}                  ${CURDIR}/../../../../tools/fastbgp/play.py
55 ${RIB_INSTANCE}                 example-bgp-rib
56 ${RT_CONSTRAIN_DIR}             ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
57
58
59 *** Test Cases ***
60 Configure_App_Peer
61     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
62     &{mapping}    BuiltIn.Create_Dictionary    BGP_RIB=${RIB_INSTANCE}    IP=${ODL_SYSTEM_IP}
63     TemplatedRequests.Put_As_Xml_Templated
64     ...    ${RT_CONSTRAIN_DIR}/app_peer
65     ...    mapping=${mapping}
66     ...    session=${CONFIG_SESSION}
67
68 Reconfigure_ODL_To_Accept_Connection
69     [Documentation]    Configures BGP peer module with initiate-connection set to false.
70     &{mapping}    BuiltIn.Create_Dictionary
71     ...    IP=${TOOLS_SYSTEM_IP}
72     ...    BGP_RIB=${RIB_INSTANCE}
73     ...    HOLDTIME=${HOLDTIME}
74     ...    PEER_PORT=${BGP_TOOL_PORT}
75     ...    INITIATE=false
76     ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
77     ...    PASSIVE_MODE=true
78     CompareStream.Run_Keyword_If_At_Least_Fluorine
79     ...    TemplatedRequests.Put_As_Xml_Templated
80     ...    ${RT_CONSTRAIN_DIR}/bgp_peer
81     ...    mapping=${mapping}
82     ...    session=${CONFIG_SESSION}
83     CompareStream.Run_Keyword_If_Less_Than_Fluorine
84     ...    TemplatedRequests.Put_As_Xml_Templated
85     ...    ${BGP_VAR_FOLDER}/bgp_peer
86     ...    mapping=${mapping}
87     ...    session=${CONFIG_SESSION}
88
89 L3vpn_Ipv4_To_Odl
90     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
91     [Setup]    Setup_Testcase    ${L3VPN_EXA_CFG}
92     ${L3VPN_RESPONSE}    CompareStream.Set_Variable_If_At_Least_Fluorine    ${L3VPN_RSP_PATH}    ${L3VPN_RSP}
93     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Reported_Data    ${L3VPN_RESPONSE}
94     [Teardown]    Teardown_Simple
95
96 Start_Play
97     [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.
98     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
99     CompareStream.Run_Keyword_If_Less_Than_Fluorine    BuiltIn.Pass_Execution    "Only run on Fluorine and later"
100     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
101     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
102     SSHLibrary.Read
103     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Start_Bgp_Peer
104
105 Play_To_Odl_rt_constrain_type_0
106     [Documentation]    This keyword sends route-target route containg route-target argument so odl
107     ...    can identify this peer as appropriate for advertizement when it recieves such route.
108     CompareStream.Run_Keyword_If_Less_Than_Fluorine    BuiltIn.Pass_Execution    "Only run on Fluorine and later"
109     BgpOperations.Play_To_Odl_Non_Removal_Template    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
110
111 Odl_To_Play_l3vpn
112     [Documentation]    Send l3vpn route to app peer, and than checks that app peer advertizes this route.
113     CompareStream.Run_Keyword_If_At_Least_Fluorine    BuiltIn.Pass_Execution    "Only run on less than Fluorine"
114     Setup_Testcase    ${DEFAULT_EXA_CFG}
115     L3vpn_Ipv4_To_App
116     [Teardown]    CompareStream.Run_Keyword_If_Less_Than_Fluorine    Teardowm_With_Remove_Route
117
118 Odl_To_Play_l3vpn_rt_arg
119     [Documentation]    Same as TC before but fluorine and further this l3vpn route also needs to contain route-target argument.
120     CompareStream.Run_Keyword_If_Less_Than_Fluorine    BuiltIn.Pass_Execution    "Only run on Fluorine and later"
121     BgpOperations.Odl_To_Play_Template    l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}    False
122
123 Kill_Talking_BGP_Speaker
124     [Documentation]    Abort the Python speaker
125     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
126     CompareStream.Run_Keyword_If_Less_Than_Fluorine    BuiltIn.Pass_Execution    "Only run on Fluorine and later"
127     BGPSpeaker.Kill_BGP_Speaker
128     BGPcliKeywords.Store_File_To_Workspace    play.py.out    010_l3vpn_play.log
129
130 Delete_Bgp_Peer_Configuration
131     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
132     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB=${RIB_INSTANCE}
133     TemplatedRequests.Delete_Templated
134     ...    ${RT_CONSTRAIN_DIR}/bgp_peer
135     ...    mapping=${mapping}
136     ...    session=${CONFIG_SESSION}
137
138 Deconfigure_App_Peer
139     [Documentation]    Revert the BGP configuration to the original state: without application peer
140     &{mapping}    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_INSTANCE}
141     TemplatedRequests.Delete_Templated
142     ...    ${RT_CONSTRAIN_DIR}/app_peer
143     ...    mapping=${mapping}
144     ...    session=${CONFIG_SESSION}
145
146
147 *** Keywords ***
148 Start_Suite
149     [Documentation]    Suite setup keyword.
150     SetupUtils.Setup_Utils_For_Setup_And_Teardown
151     ${tools_system_conn_id}    SSHLibrary.Open_Connection
152     ...    ${TOOLS_SYSTEM_IP}
153     ...    prompt=${DEFAULT_LINUX_PROMPT}
154     ...    timeout=6s
155     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
156     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
157     SSHKeywords.Virtual_Env_Create
158     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
159     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
160     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
161     Upload_Config_Files
162     ${AS_PATH}    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
163     BuiltIn.Set_Suite_Variable    ${AS_PATH}
164
165 Stop_Suite
166     [Documentation]    Suite teardown keyword
167     SSHKeywords.Virtual_Env_Delete
168     SSHLibrary.Close_All_Connections
169     RequestsLibrary.Delete_All_Sessions
170
171 Upload_Config_Files
172     [Documentation]    Uploads exabgp config files and needed scripts
173     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAULT_EXA_CFG}    .
174     SSHLibrary.Put_File    ${BGP_L3VPN_DIR}/${L3VPN_EXA_CFG}    .
175     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
176     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
177     FOR    ${cfgfile}    IN    @{cfgfiles}
178         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
179         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
180         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
181         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
182         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
183         Log    ${stdout}
184     END
185
186 Setup_Testcase
187     [Documentation]    Verifies initial test condition and starts the exabgp
188     [Arguments]    ${cfg_file}
189     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
190     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
191     ExaBgpLib.Start_ExaBgp_And_Verify_Connected
192     ...    ${cfg_file}
193     ...    ${CONFIG_SESSION}
194     ...    ${TOOLS_SYSTEM_IP}
195     ...    connection_retries=${3}
196
197 Teardowm_With_Remove_Route
198     [Documentation]    Removes configured route from application peer and stops the exabgp
199     &{mapping}    BuiltIn.Create_Dictionary    APP_PEER_IP=${ODL_SYSTEM_IP}
200     TemplatedRequests.Delete_Templated    ${BGP_L3VPN_DIR}/route    mapping=${mapping}    session=${CONFIG_SESSION}
201     Teardown_Simple
202
203 Teardown_Simple
204     [Documentation]    Testcse teardown with data verification
205     ExaBgpLib.Stop_ExaBgp
206     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
207
208 Verify_ExaBgp_Received_Update
209     [Documentation]    Verification of receiving particular update message
210     [Arguments]    ${exp_update_fn}
211     ${exp_update}    TemplatedRequests.Resolve_Text_From_Template_File
212     ...    ${BGP_L3VPN_DIR}${/}${exp_update_fn}
213     ...    data.json
214     ${rcv_update_dict}    BgpRpcClient.exa_get_update_message    msg_only=${True}
215     ${rcv_update}    BuiltIn.Evaluate    json.dumps(${rcv_update_dict})    modules=json
216     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_update}    ${rcv_update}
217
218 Verify_Empty_Reported_Data
219     [Documentation]    Verfiy empty data response
220     CompareStream.Run_Keyword_If_At_Most_Fluorine
221     ...    TemplatedRequests.Get_As_Json_Templated
222     ...    ${BGP_L3VPN_DIR}${/}${L3VPN_RSPEMPTY}
223     ...    session=${CONFIG_SESSION}
224     ...    verify=True
225     CompareStream.Run_Keyword_If_At_Least_Neon    Verify_Empty_Data_Neon
226
227 Verify_Reported_Data
228     [Documentation]    Verifies expected response
229     [Arguments]    ${exprspdir}
230     &{mapping}    BuiltIn.Create_Dictionary    AS_PATH=${AS_PATH}
231     TemplatedRequests.Get_As_Json_Templated
232     ...    ${BGP_L3VPN_DIR}${/}${exprspdir}
233     ...    mapping=${mapping}
234     ...    session=${CONFIG_SESSION}
235     ...    verify=True
236
237 Start_Bgp_Peer
238     [Documentation]    Starts bgp peer and verifies that the peer runs.
239     BGPSpeaker.Start_BGP_Speaker
240     ...    --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --debug --allf --wfr 1
241     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
242
243 L3vpn_Ipv4_To_App
244     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
245     BgpRpcClient.exa_clean_update_message
246     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}    APP_PEER_IP=${ODL_SYSTEM_IP}
247     TemplatedRequests.Post_As_Xml_Templated
248     ...    ${BGP_L3VPN_DIR}/route
249     ...    mapping=${mapping}
250     ...    session=${CONFIG_SESSION}
251     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Update    ${L3VPN_EXP}
252
253 Verify_Empty_Data_Neon
254     [Documentation]    Verify empty data on neon
255     TemplatedRequests.Get_As_Json_Templated
256     ...    ${BGP_L3VPN_DIR}${/}empty_route
257     ...    session=${CONFIG_SESSION}
258     ...    verify=True