Update Robot Framework format - step 3
[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 ${OLD_AS_PATH}              \n"as-path": {},
27 ${NEW_AS_PATH}              ${EMPTY}
28 ${EXP0}                     {"bgp-flowspec:flowspec-routes": {}}
29 ${CFG1}                     bgp-flowspec.cfg
30 ${EXP1}                     bgp_flowspec
31 ${CFG2}                     bgp-flowspec-redirect.cfg
32 ${EXP2}                     bgp_flowspec_redirect
33 ${FLOWSPEC_URL}
34 ...                         /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
35 ${CONFIG_SESSION}           session
36 ${DEVICE_NAME}              controller-config
37 ${RIB_INSTANCE}             example-bgp-rib
38 ${PROTOCOL_OPENCONFIG}      ${RIB_INSTANCE}
39 @{EMPTY_LIST}
40
41
42 *** Test Cases ***
43 Check_For_Empty_Topology_Before_Talking
44     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
45     [Tags]    critical
46     BuiltIn.Wait_Until_Keyword_Succeeds    60s    3s    Verify_Empty_Flowspec_Data
47
48 Reconfigure_ODL_To_Accept_Connection
49     [Documentation]    Configure BGP peer module with initiate-connection set to false.
50     &{mapping}    BuiltIn.Create_Dictionary
51     ...    IP=${TOOLS_SYSTEM_IP}
52     ...    HOLDTIME=${HOLDTIME}
53     ...    PEER_PORT=${BGP_TOOL_PORT}
54     ...    INITIATE=false
55     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
56     ...    PASSIVE_MODE=true
57     TemplatedRequests.Put_As_Xml_Templated
58     ...    ${BGP_VARIABLES_FOLDER}/bgp_peer
59     ...    mapping=${mapping}
60     ...    session=${CONFIG_SESSION}
61
62 FlowSpec_Test_1
63     [Documentation]    Testing flowspec values for ${CFG1}
64     [Setup]    Setup_Testcase    ${CFG1}
65     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP1}
66     [Teardown]    ExaBgpLib.Stop_ExaBgp
67
68 FlowSpec_Test_2
69     [Documentation]    Testing flowspec values for ${CFG2}
70     [Setup]    Setup_Testcase    ${CFG2}
71     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP2}
72     [Teardown]    ExaBgpLib.Stop_ExaBgp
73
74 Deconfigure_ODL_To_Accept_Connection
75     [Documentation]    Deconfigure BGP peer.
76     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
77     TemplatedRequests.Delete_Templated
78     ...    ${BGP_VARIABLES_FOLDER}/bgp_peer
79     ...    mapping=${mapping}
80     ...    session=${CONFIG_SESSION}
81
82
83 *** Keywords ***
84 Start_Suite
85     [Documentation]    Suite setup keyword
86     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
87     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
88     SSHKeywords.Virtual_Env_Create
89     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
90     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
91     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
92     Upload_Config_Files    ${BGP_VARIABLES_FOLDER}
93     ${AS_PATH}    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
94     BuiltIn.Set_Suite_Variable    ${AS_PATH}
95
96 Stop_Suite
97     [Documentation]    Suite teardown keyword
98     SSHLibrary.Close_All_Connections
99     RequestsLibrary.Delete_All_Sessions
100
101 Upload_Config_Files
102     [Documentation]    Uploads exabgp config files
103     [Arguments]    ${dir_name}
104     SSHLibrary.Put_Directory    ${BGP_VARIABLES_FOLDER}    .
105     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
106     FOR    ${cfgfile}    IN    @{cfgfiles}
107         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
108         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
109         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
110         Log    ${stdout}
111     END
112
113 Setup_Testcase
114     [Arguments]    ${cfg_file}
115     Verify_Empty_Flowspec_Data
116     ExaBgpLib.Start_ExaBgp_And_Verify_Connected
117     ...    ${cfg_file}
118     ...    ${CONFIG_SESSION}
119     ...    ${TOOLS_SYSTEM_IP}
120     ...    connection_retries=${3}
121
122 Verify_Empty_Flowspec_Data
123     [Documentation]    Verify expected response.
124     CompareStream.Run_Keyword_If_At_Most_Fluorine    Normalize_And_Compare
125     CompareStream.Run_Keyword_If_At_Least_Neon    Verify_Empty_Flowspec_Data_Neon
126
127 Verify_Flowspec_Data
128     [Documentation]    Verify expected response
129     [Arguments]    ${exprspdir}
130     &{mapping}    BuiltIn.Create_Dictionary    AS_PATH=${AS_PATH}
131     TemplatedRequests.Get_As_Json_Templated
132     ...    ${BGP_VARIABLES_FOLDER}${/}${exprspdir}
133     ...    session=${CONFIG_SESSION}
134     ...    mapping=${mapping}
135     ...    verify=True
136
137 Normalize_And_Compare
138     [Documentation]    Verify empty flowspec data
139     ${rsp}    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
140     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare
141     ...    ${EXP0}
142     ...    ${rsp.content}
143     ...    keys_with_bits=${EMPTY_LIST}
144
145 Verify_Empty_Flowspec_Data_Neon
146     [Documentation]    Verify empty flowspec data on neon
147     TemplatedRequests.Get_As_Json_Templated
148     ...    ${BGP_VARIABLES_FOLDER}${/}empty_route
149     ...    session=${CONFIG_SESSION}
150     ...    verify=True