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