Remove variables.py
[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/ExaBgpLib.robot
14 Resource          ../../../libraries/SetupUtils.robot
15 Resource          ../../../libraries/SSHKeywords.robot
16 Resource          ../../../libraries/TemplatedRequests.robot
17 Resource          ../../../variables/Variables.robot
18
19 *** Variables ***
20 ${HOLDTIME}       180
21 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpflowspec
22 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
23 ${EXP0}           empty-flowspec.json
24 ${CFG1}           bgp-flowspec.cfg
25 ${EXP1}           bgp-flowspec.json
26 ${CFG2}           bgp-flowspec-redirect.cfg
27 ${EXP2}           bgp-flowspec-redirect.json
28 ${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
29 ${CONFIG_SESSION}    session
30 ${DEVICE_NAME}    controller-config
31 ${BGP_PEER_NAME}    example-bgp-peer
32 ${RIB_INSTANCE}    example-bgp-rib
33 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
34
35 *** Test Cases ***
36 Check_For_Empty_Topology_Before_Talking
37     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
38     [Tags]    critical
39     BuiltIn.Wait Until Keyword Succeeds    60s    3s    Verify Empty Flowspec Data
40
41 Reconfigure_ODL_To_Accept_Connection
42     [Documentation]    Configure BGP peer module with initiate-connection set to false.
43     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
44     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
45     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
46
47 FlowSpec Test 1
48     [Documentation]    Testing flowspec values for ${CFG1}
49     [Setup]    Setup Testcase    ${CFG1}
50     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP1}
51     [Teardown]    ExaBgpLib.Stop_ExaBgp
52
53 FlowSpec Test 2
54     [Documentation]    Testing flowspec values for ${CFG2}
55     [Setup]    Setup Testcase    ${CFG2}
56     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP2}
57     [Teardown]    ExaBgpLib.Stop_ExaBgp
58
59 Deconfigure_ODL_To_Accept_Connection
60     [Documentation]    Deconfigure BGP peer.
61     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
62     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
63
64 *** Keywords ***
65 Start Suite
66     [Documentation]    Suite setup keyword
67     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
68     Builtin.Set Suite Variable    ${mininet_conn_id}
69     SSHKeywords.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
70     SSHKeywords.Virtual_Env_Create
71     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
72     RequestsLibrary.Create Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
73     Upload Config Files    ${CURDIR}/../../../variables/bgpflowspec/
74
75 Stop Suite
76     [Documentation]    Suite teardown keyword
77     SSHLibrary.Close All Connections
78     RequestsLibrary.Delete All Sessions
79
80 Upload Config Files
81     [Arguments]    ${dir_name}
82     [Documentation]    Uploads exabgp config files
83     SSHLibrary.Put Directory    ${CURDIR}/../../../variables/bgpflowspec/    .
84     @{cfgfiles}=    SSHLibrary.List Files In Directory    .    *.cfg
85     : FOR    ${cfgfile}    IN    @{cfgfiles}
86     \    SSHLibrary.Execute Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
87     \    SSHLibrary.Execute Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
88     \    ${stdout}=    SSHLibrary.Execute Command    cat ${cfgfile}
89     \    Log    ${stdout}
90
91 Setup Testcase
92     [Arguments]    ${cfg_file}
93     Verify Empty Flowspec Data
94     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}    connection_retries=${3}
95
96 Verify Empty Flowspec Data
97     [Documentation]    Verify expected response.
98     Verify Flowspec Data    ${EXP0}
99
100 Verify Flowspec Data
101     [Arguments]    ${exprspfile}
102     [Documentation]    Verify expected response
103     ${keys_with_bits}=    BuiltIn.Create_List
104     ${expected_rsp}=    Get Expected Response From File    ${exprspfile}
105     ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
106     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare    ${expected_rsp}    ${rsp.content}    keys_with_bits=${keys_with_bits}
107
108 Get Expected Response From File
109     [Arguments]    ${exprspfile}
110     [Documentation]    Looks for release specific response first, then take default.
111     ${status}    ${expresponse}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}.${ODL_STREAM}
112     Return From Keyword If    '${status}' == 'PASS'    ${expresponse}
113     ${expresponse}=    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}
114     [Return]    ${expresponse}