Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / bgpflowspec / 010_bgp_flowspec.robot
1 *** Settings ***
2 Documentation       Functional test for bgp flowspec.
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 Library             RequestsLibrary
11 Library             SSHLibrary
12 Resource            ../../../libraries/CompareStream.robot
13 Resource            ../../../libraries/ExaBgpLib.robot
14 Resource            ../../../libraries/SSHKeywords.robot
15 Resource            ../../../libraries/TemplatedRequests.robot
16 Resource            ../../../variables/Variables.robot
17
18 Suite Setup         Start_Suite
19 Suite Teardown      Stop_Suite
20
21
22 *** Variables ***
23 ${BGP_VARIABLES_FOLDER}     ${CURDIR}/../../../variables/bgpflowspec/
24 ${CMD}                      env exabgp.tcp.port=1790 exabgp --debug
25 ${HOLDTIME}                 180
26 ${EXP0}                     {"bgp-flowspec:flowspec-routes": {}}
27 ${CFG1}                     bgp-flowspec.cfg
28 ${EXP1}                     bgp_flowspec
29 ${CFG2}                     bgp-flowspec-redirect.cfg
30 ${EXP2}                     bgp_flowspec_redirect
31 ${FLOWSPEC_URL}
32 ...                         /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/tables/bgp-types:ipv4-address-family/bgp-flowspec:flowspec-subsequent-address-family/bgp-flowspec:flowspec-routes
33 ${CONFIG_SESSION}           session
34 ${DEVICE_NAME}              controller-config
35 ${RIB_INSTANCE}             example-bgp-rib
36 ${PROTOCOL_OPENCONFIG}      ${RIB_INSTANCE}
37 @{EMPTY_LIST}
38
39
40 *** Test Cases ***
41 Check_For_Empty_Topology_Before_Talking
42     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
43     [Tags]    critical
44     BuiltIn.Wait_Until_Keyword_Succeeds    60s    3s    Verify_Empty_Flowspec_Data
45
46 Reconfigure_ODL_To_Accept_Connection
47     [Documentation]    Configure BGP peer module with initiate-connection set to false.
48     &{mapping}    BuiltIn.Create_Dictionary
49     ...    IP=${TOOLS_SYSTEM_IP}
50     ...    HOLDTIME=${HOLDTIME}
51     ...    PEER_PORT=${BGP_TOOL_PORT}
52     ...    INITIATE=false
53     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
54     ...    PASSIVE_MODE=true
55     TemplatedRequests.Put_As_Xml_Templated
56     ...    ${BGP_VARIABLES_FOLDER}/bgp_peer
57     ...    mapping=${mapping}
58     ...    session=${CONFIG_SESSION}
59
60 FlowSpec_Test_1
61     [Documentation]    Testing flowspec values for ${CFG1}
62     [Setup]    Setup_Testcase    ${CFG1}
63     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP1}
64     [Teardown]    ExaBgpLib.Stop_ExaBgp
65
66 FlowSpec_Test_2
67     [Documentation]    Testing flowspec values for ${CFG2}
68     [Setup]    Setup_Testcase    ${CFG2}
69     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP2}
70     [Teardown]    ExaBgpLib.Stop_ExaBgp
71
72 Deconfigure_ODL_To_Accept_Connection
73     [Documentation]    Deconfigure BGP peer.
74     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
75     TemplatedRequests.Delete_Templated
76     ...    ${BGP_VARIABLES_FOLDER}/bgp_peer
77     ...    mapping=${mapping}
78     ...    session=${CONFIG_SESSION}
79
80
81 *** Keywords ***
82 Start_Suite
83     [Documentation]    Suite setup keyword
84     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
85     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
86     SSHKeywords.Virtual_Env_Create
87     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
88     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
89     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
90     Upload_Config_Files    ${BGP_VARIABLES_FOLDER}
91
92 Stop_Suite
93     [Documentation]    Suite teardown keyword
94     SSHLibrary.Close_All_Connections
95     RequestsLibrary.Delete_All_Sessions
96
97 Upload_Config_Files
98     [Documentation]    Uploads exabgp config files
99     [Arguments]    ${dir_name}
100     SSHLibrary.Put_Directory    ${BGP_VARIABLES_FOLDER}    .
101     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
102     FOR    ${cfgfile}    IN    @{cfgfiles}
103         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
104         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
105         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
106         Log    ${stdout}
107     END
108
109 Setup_Testcase
110     [Arguments]    ${cfg_file}
111     Verify_Empty_Flowspec_Data
112     ExaBgpLib.Start_ExaBgp_And_Verify_Connected
113     ...    ${cfg_file}
114     ...    ${CONFIG_SESSION}
115     ...    ${TOOLS_SYSTEM_IP}
116     ...    connection_retries=${3}
117
118 Verify_Empty_Flowspec_Data
119     [Documentation]    Verify expected response.
120     Verify_Empty_Flowspec_Data_Neon
121
122 Verify_Flowspec_Data
123     [Documentation]    Verify expected response
124     [Arguments]    ${exprspdir}
125     TemplatedRequests.Get_As_Json_Templated
126     ...    ${BGP_VARIABLES_FOLDER}${/}${exprspdir}
127     ...    session=${CONFIG_SESSION}
128     ...    verify=True
129
130 Normalize_And_Compare
131     [Documentation]    Verify empty flowspec data
132     ${rsp}    RequestsLibrary.GET On Session    ${CONFIG_SESSION}    url=${FLOWSPEC_URL}
133     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare
134     ...    ${EXP0}
135     ...    ${rsp.content}
136     ...    keys_with_bits=${EMPTY_LIST}
137
138 Verify_Empty_Flowspec_Data_Neon
139     [Documentation]    Verify empty flowspec data on neon
140     TemplatedRequests.Get_As_Json_Templated
141     ...    ${BGP_VARIABLES_FOLDER}${/}empty_route
142     ...    session=${CONFIG_SESSION}
143     ...    verify=True