Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 030_bgp_functional_evpn.robot
1 *** Settings ***
2 Documentation       Functional test for bgp - evpn
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 evpn content.
11 ...                 It uses play.py and odl as bgp peers. Routes advertized from odl
12 ...                 are configured via application peer. Routes advertised from play.py are
13 ...                 stored in *.hex files. These files are used also as expected data which
14 ...                 is recevied from odl.
15
16 Library             RequestsLibrary
17 Library             SSHLibrary
18 Library             String
19 Library             ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
20 Resource            ../../../libraries/BGPcliKeywords.robot
21 Resource            ../../../libraries/BgpOperations.robot
22 Resource            ../../../libraries/BGPSpeaker.robot
23 Resource            ../../../libraries/CompareStream.robot
24 Resource            ../../../libraries/SetupUtils.robot
25 Resource            ../../../libraries/SSHKeywords.robot
26 Resource            ../../../libraries/TemplatedRequests.robot
27 Resource            ../../../variables/Variables.robot
28
29 Suite Setup         Start_Suite
30 Suite Teardown      Stop_Suite
31 Test Setup          Run Keywords    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
32 ...                     AND    Verify_Test_Preconditions
33 Test Template       Odl_To_Play_Template
34
35
36 *** Variables ***
37 ${HOLDTIME}                 180
38 ${RIB_NAME}                 example-bgp-rib
39 ${BGP_DIR}                  ${CURDIR}/../../../variables/bgpfunctional
40 ${DEFAUTL_RPC_CFG}          exa.cfg
41 ${CONFIG_SESSION}           config-session
42 ${EVPN_DIR}                 ${CURDIR}/../../../variables/bgpfunctional/l2vpn_evpn
43 ${BGP_TOOL_LOG_LEVEL}       debug
44 ${PLAY_SCRIPT}              ${CURDIR}/../../../../tools/fastbgp/play.py
45
46
47 *** Test Cases ***
48 Configure_App_Peer
49     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
50     [Template]    NONE
51     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
52     &{mapping} =    BuiltIn.Create_Dictionary    BGP_RIB_OPENCONFIG=${RIB_NAME}    IP=${ODL_SYSTEM_IP}
53     TemplatedRequests.Put_As_Xml_Templated    ${BGP_DIR}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
54 Reconfigure_ODL_To_Accept_Connection
55     [Documentation]    Configures BGP peer module with initiate-connection set to false.
56     [Template]    NONE
57     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
58     &{mapping} =    BuiltIn.Create_Dictionary
59     ...    IP=${TOOLS_SYSTEM_IP}
60     ...    HOLDTIME=${HOLDTIME}
61     ...    PEER_PORT=${BGP_TOOL_PORT}
62     ...    INITIATE=false
63     ...    BGP_RIB_OPENCONFIG=${RIB_NAME}
64     ...    PASSIVE_MODE=true
65     TemplatedRequests.Put_As_Xml_Templated    ${BGP_DIR}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
66 Start_Bgp_Peer
67     [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.
68     [Template]    NONE
69     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
70     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Start Bgp Peer
71 Odl_To_Play_route_es_arb
72     route_es_arb
73 Play_To_Odl_route_es_arb
74     [Template]    Play_To_Odl_Template
75     route_es_arb
76 Odl_To_Play_route_es_as
77     route_es_as
78 Play_To_Odl_route_es_as
79     [Template]    Play_To_Odl_Template
80     route_es_as
81 Odl_To_Play_route_es_lacp
82     route_es_lacp
83 Play_To_Odl_route_es_lacp
84     [Template]    Play_To_Odl_Template
85     route_es_lacp
86 Odl_To_Play_route_es_lan
87     route_es_lan
88 Play_To_Odl_route_es_lan
89     [Template]    Play_To_Odl_Template
90     route_es_lan
91 Odl_To_Play_route_es_mac
92     route_es_mac
93 Play_To_Odl_route_es_mac
94     [Template]    Play_To_Odl_Template
95     route_es_mac
96 Odl_To_Play_route_es_rou
97     route_es_rou
98 Play_To_Odl_route_es_rou
99     [Template]    Play_To_Odl_Template
100     route_es_rou
101 Odl_To_Play_route_eth_arb
102     route_eth_arb
103 Play_To_Odl_route_eth_arb
104     [Template]    Play_To_Odl_Template
105     route_eth_arb
106 Odl_To_Play_route_eth_as
107     route_eth_as
108 Play_To_Odl_route_eth_as
109     [Template]    Play_To_Odl_Template
110     route_eth_as
111 Odl_To_Play_route_eth_lacp
112     route_eth_lacp
113 Play_To_Odl_route_eth_lacp
114     [Template]    Play_To_Odl_Template
115     route_eth_lacp
116 Odl_To_Play_route_eth_lacp_extdef
117     route_eth_lacp_extdef
118 Play_To_Odl_route_eth_lacp_extdef
119     [Template]    Play_To_Odl_Template
120     route_eth_lacp_extdef
121 Odl_To_Play_route_eth_lacp_extesilab
122     route_eth_lacp_extesilab
123 Play_To_Odl_route_eth_lacp_extesilab
124     [Template]    Play_To_Odl_Template
125     route_eth_lacp_extesilab
126 Odl_To_Play_route_eth_lacp_extesr
127     route_eth_lacp_extesr
128 Play_To_Odl_route_eth_lacp_extesr
129     [Template]    Play_To_Odl_Template
130     route_eth_lacp_extesr
131 Odl_To_Play_route_eth_lacp_extl2
132     route_eth_lacp_extl2
133 Play_To_Odl_route_eth_lacp_extl2
134     [Template]    Play_To_Odl_Template
135     route_eth_lacp_extl2
136 Odl_To_Play_route_eth_lacp_extmac
137     route_eth_lacp_extmac
138 Play_To_Odl_route_eth_lacp_extmac
139     [Template]    Play_To_Odl_Template
140     route_eth_lacp_extmac
141 Odl_To_Play_route_eth_lan
142     route_eth_lan
143 Play_To_Odl_route_eth_lan
144     [Template]    Play_To_Odl_Template
145     route_eth_lan
146 Odl_To_Play_route_eth_mac
147     route_eth_mac
148 Play_To_Odl_route_eth_mac
149     [Template]    Play_To_Odl_Template
150     route_eth_mac
151 Odl_To_Play_route_eth_rou
152     route_eth_rou
153 Play_To_Odl_route_eth_rou
154     [Template]    Play_To_Odl_Template
155     route_eth_rou
156 Odl_To_Play_route_inc_arb
157     route_inc_arb
158 Play_To_Odl_route_inc_arb
159     [Template]    Play_To_Odl_Template
160     route_inc_arb
161 Odl_To_Play_route_inc_as
162     route_inc_as
163 Play_To_Odl_route_inc_as
164     [Template]    Play_To_Odl_Template
165     route_inc_as
166 Odl_To_Play_route_inc_lacp
167     route_inc_lacp
168 Play_To_Odl_route_inc_lacp
169     [Template]    Play_To_Odl_Template
170     route_inc_lacp
171 Odl_To_Play_route_inc_lan
172     route_inc_lan
173 Play_To_Odl_route_inc_lan
174     [Template]    Play_To_Odl_Template
175     route_inc_lan
176 Odl_To_Play_route_inc_mac
177     route_inc_mac
178 Play_To_Odl_route_inc_mac
179     [Template]    Play_To_Odl_Template
180     route_inc_mac
181 Odl_To_Play_route_inc_rou
182     route_inc_rou
183 Play_To_Odl_route_inc_rou
184     [Template]    Play_To_Odl_Template
185     route_inc_rou
186 Odl_To_Play_route_mac_arb
187     route_mac_arb
188 Play_To_Odl_route_mac_arb
189     [Template]    Play_To_Odl_Template
190     route_mac_arb
191 Odl_To_Play_route_mac_as
192     route_mac_as
193 Play_To_Odl_route_mac_as
194     [Template]    Play_To_Odl_Template
195     route_mac_as
196 Odl_To_Play_route_mac_lacp
197     route_mac_lacp
198 Play_To_Odl_route_mac_lacp
199     [Template]    Play_To_Odl_Template
200     route_mac_lacp
201 Odl_To_Play_route_mac_lan
202     route_mac_lan
203 Play_To_Odl_route_mac_lan
204     [Template]    Play_To_Odl_Template
205     route_mac_lan
206 Odl_To_Play_route_mac_mac
207     route_mac_mac
208 Play_To_Odl_route_mac_mac
209     [Template]    Play_To_Odl_Template
210     route_mac_mac
211 Odl_To_Play_route_mac_rou
212     route_mac_rou
213 Play_To_Odl_route_mac_rou
214     [Template]    Play_To_Odl_Template
215     route_mac_rou
216 Odl_To_Play_pmsi_rsvp_te_p2mp_lsp
217     [Template]    None
218     Odl_To_Play_Template    pmsi_rsvp_te_p2mp_lsp
219 Play_To_Odl_pmsi_rsvp_te_p2mp_lsp
220     [Template]    None
221     Play_To_Odl_Template    pmsi_rsvp_te_p2mp_lsp
222 Odl_To_Play_pmsi_mldp_p2mp_lsp
223     pmsi_mldp_p2mp_lsp
224 Play_To_Odl_pmsi_mldp_p2mp_lsp
225     [Template]    Play_To_Odl_Template
226     pmsi_mldp_p2mp_lsp
227 Odl_To_Play_pmsi_pim_ssm_tree
228     pmsi_pim_ssm_tree
229 Play_To_Odl_pmsi_pim_ssm_tree
230     [Template]    Play_To_Odl_Template
231     pmsi_pim_ssm_tree
232 Odl_To_Play_pmsi_pim_sm_tree
233     pmsi_pim_sm_tree
234 Play_To_Odl_pmsi_pim_sm_tree
235     [Template]    Play_To_Odl_Template
236     pmsi_pim_sm_tree
237 Odl_To_Play_pmsi_bidir_pim_tree
238     pmsi_bidir_pim_tree
239 Play_To_Odl_pmsi_bidir_pim_tree
240     [Template]    Play_To_Odl_Template
241     pmsi_bidir_pim_tree
242 Odl_To_Play_pmsi_ingress_replication
243     pmsi_ingress_replication
244 Play_To_Odl_pmsi_ingress_replication
245     [Template]    Play_To_Odl_Template
246     pmsi_ingress_replication
247 Odl_To_Play_pmsi_mldp_mp2mp_lsp
248     pmsi_mldp_mp2mp_lsp
249 Play_To_Odl_pmsi_mldp_mp2mp_lsp
250     [Template]    Play_To_Odl_Template
251     pmsi_mldp_mp2mp_lsp
252 Kill_Talking_BGP_Speaker
253     [Documentation]    Abort the Python speaker
254     [Template]    NONE
255     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
256     BGPSpeaker.Kill_BGP_Speaker
257     BGPcliKeywords.Store_File_To_Workspace    play.py.out    evpn_play.log
258 Delete_Bgp_Peer_Configuration
259     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
260     [Template]    NONE
261     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
262     &{mapping} =    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${RIB_NAME}
263     TemplatedRequests.Delete_Templated    ${BGP_DIR}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
264 Deconfigure_App_Peer
265     [Documentation]    Revert the BGP configuration to the original state: without application peer
266     [Template]    NONE
267     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
268     &{mapping} =    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${RIB_NAME}
269     TemplatedRequests.Delete_Templated    ${BGP_DIR}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
270
271
272 *** Keywords ***
273 Start_Suite
274     [Documentation]    Initialize SetupUtils. Suite setup keyword.
275     SetupUtils.Setup_Utils_For_Setup_And_Teardown
276     ${mininet_conn_id} =    SSHLibrary.Open Connection
277     ...    ${TOOLS_SYSTEM_IP}
278     ...    prompt=${DEFAULT_LINUX_PROMPT}
279     ...    timeout=6s
280     Builtin.Set Suite Variable    ${mininet_conn_id}
281     SSHKeywords.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
282     RequestsLibrary.Create Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
283     SSHLibrary.Put File    ${PLAY_SCRIPT}    .
284     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
285     BuiltIn.Set_Suite_Variable
286     ...    ${EVPN_CONF_URL}
287     ...    /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
288     BuiltIn.Set_Suite_Variable
289     ...    ${EVPN_LOC_RIB}
290     ...    /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
291     BuiltIn.Set_Suite_Variable
292     ...    ${EVPN_FAMILY_LOC_RIB}
293     ...    /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
294     ${EMPTY_ROUTES} =    TemplatedRequests.Resolve_Text_From_Template_File
295     ...    ${EVPN_DIR}/empty_routes
296     ...    empty_routes.json
297     BuiltIn.Set_Suite_Variable    ${EMPTY_ROUTES}
298
299 Stop_Suite
300     [Documentation]    Suite teardown keyword
301     SSHLibrary.Close_All_Connections
302     RequestsLibrary.Delete_All_Sessions
303
304 Start_Bgp_Peer
305     [Documentation]    Starts bgp peer and verifies that the peer runs.
306     BGPSpeaker.Start_BGP_Speaker
307     ...    --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_TOOL_LOG_LEVEL} --evpn --wfr 1
308     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
309
310 Odl_To_Play_Template
311     [Arguments]    ${totest}
312     ${data_xml} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/${totest}.xml
313     ${data_json} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/${totest}.json
314     ${announce_hex} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/announce_${totest}.hex
315     ${announce_hex} =    String.Remove_String    ${announce_hex}    \n
316     ${withdraw_hex} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/withdraw_${totest}.hex
317     ${withdraw_hex} =    String.Remove_String    ${withdraw_hex}    \n
318     BuiltIn.Log    ${data_xml}
319     BuiltIn.Log    ${data_json}
320     BuiltIn.Log    ${announce_hex}
321     BuiltIn.Log    ${withdraw_hex}
322     BgpRpcClient.play_clean
323     ${resp} =    RequestsLibrary.POST On Session
324     ...    ${CONFIG_SESSION}
325     ...    url=${EVPN_CONF_URL}
326     ...    data=${data_xml}
327     ...    headers=${HEADERS_XML}
328     ...    expected_status=201
329     BuiltIn.Log    ${resp.content}
330     ${resp} =    RequestsLibrary.GET On Session
331     ...    ${CONFIG_SESSION}
332     ...    url=${EVPN_CONF_URL}?content=config
333     ...    headers=${HEADERS_XML}
334     BuiltIn.Log    ${resp.content}
335     ${aupdate} =    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Get_Update_Content    ${ALLOWED_STATUS_CODES}
336     BuiltIn.Log    ${aupdate}
337     BgpOperations.Verify_Two_Hex_Messages_Are_Equal    ${aupdate}    ${announce_hex}
338     BgpRpcClient.play_clean
339     Remove_Configured_Routes
340     ${wupdate} =    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Get_Update_Content    ${DELETED_STATUS_CODES}
341     BuiltIn.Log    ${wupdate}
342     BgpOperations.Verify_Two_Hex_Messages_Are_Equal    ${wupdate}    ${withdraw_hex}
343     [Teardown]    Remove_Configured_Routes
344
345 Play_To_Odl_Template
346     [Arguments]    ${totest}
347     ${data_xml} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/${totest}.xml
348     ${data_json} =    TemplatedRequests.Resolve_Text_From_Template_File
349     ...    ${EVPN_DIR}/${totest}
350     ...    ${totest}.json
351     ${announce_hex} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/announce_${totest}.hex
352     ${withdraw_hex} =    OperatingSystem.Get_File    ${EVPN_DIR}/${totest}/withdraw_${totest}.hex
353     BuiltIn.Log    ${data_xml}
354     BuiltIn.Log    ${data_json}
355     BuiltIn.Log    ${announce_hex}
356     BuiltIn.Log    ${withdraw_hex}
357     BgpRpcClient.play_clean
358     BgpRpcClient.play_send    ${announce_hex}
359     BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Loc_Rib_Presence    ${data_json}
360     BgpRpcClient.play_send    ${withdraw_hex}
361     BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Verify_Test_Preconditions
362     [Teardown]    Withdraw_Route_And_Verify    ${withdraw_hex}
363
364 Verify_Test_Preconditions
365     ${resp} =    RequestsLibrary.GET On Session
366     ...    ${CONFIG_SESSION}
367     ...    url=${EVPN_CONF_URL}?content=config
368     ...    expected_status=anything
369     BuiltIn.Should_Contain    ${DELETED_STATUS_CODES}    ${resp.status_code}
370     ${resp} =    RequestsLibrary.GET On Session
371     ...    ${CONFIG_SESSION}
372     ...    url=${EVPN_FAMILY_LOC_RIB}
373     ...    headers=${HEADERS}
374     TemplatedRequests.Normalize_Jsons_And_Compare    ${EMPTY_ROUTES}    ${resp.content}
375
376 Remove_Configured_Routes
377     [Documentation]    Removes the route if present. First GET is for debug purposes.
378     ${resp} =    RequestsLibrary.GET On Session
379     ...    ${CONFIG_SESSION}
380     ...    url=${EVPN_LOC_RIB}
381     ...    headers=${HEADERS}
382     ...    expected_status=anything
383     BuiltIn.Log    ${resp.content}
384     BuiltIn.Should_Contain    ${ALLOWED_DELETE_STATUS_CODES}    ${resp.status_code}
385     ${resp} =    RequestsLibrary.GET On Session
386     ...    ${CONFIG_SESSION}
387     ...    url=${EVPN_CONF_URL}?content=config
388     ...    headers=${HEADERS}
389     ...    expected_status=anything
390     BuiltIn.Log    ${resp.content}
391     BuiltIn.Should_Contain    ${ALLOWED_DELETE_STATUS_CODES}    ${resp.status_code}
392     IF    ${resp.status_code} in ${DELETED_STATUS_CODES}    RETURN
393     ${resp} =    RequestsLibrary.DELETE On Session
394     ...    ${CONFIG_SESSION}
395     ...    url=${EVPN_CONF_URL}
396     ...    expected_status=204
397
398 Withdraw_Route_And_Verify
399     [Documentation]    Sends withdraw update message from exabgp and verifies route removal from odl's rib
400     [Arguments]    ${withdraw_hex}
401     BgpRpcClient.play_send    ${withdraw_hex}
402     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Test_Preconditions
403
404 Get_Update_Content
405     [Documentation]    Gets received data from odl's peer
406     [Arguments]    ${expected_status_codes}
407     ${resp} =    RequestsLibrary.GET On Session
408     ...    ${CONFIG_SESSION}
409     ...    url=${EVPN_LOC_RIB}
410     ...    headers=${HEADERS_XML}
411     ...    expected_status=anything
412     BuiltIn.Log    ${resp.content}
413     BuiltIn.Should_Contain    ${expected_status_codes}    ${resp.status_code}
414     ${update} =    BgpRpcClient.play_get
415     BuiltIn.Should_Not_Be_Equal    ${update}    ${Empty}
416     RETURN    ${update}
417
418 Loc_Rib_Presence
419     [Documentation]    Verifies if loc-rib contains expected data
420     [Arguments]    ${exp_content}
421     ${resp} =    RequestsLibrary.GET On Session    ${CONFIG_SESSION}    url=${EVPN_LOC_RIB}    headers=${HEADERS}
422     BuiltIn.Log_Many    ${exp_content}    ${resp.content}
423     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_content}    ${resp.content}