36c3c910b519d3aee8480d5436dee205d5cbf4ef
[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 Variables         ${CURDIR}/../../../variables/Variables.py
14 Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}
15 Resource          ${CURDIR}/../../../libraries/Utils.robot
16 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
17 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
18 Library           ${CURDIR}/../../../libraries/norm_json.py
19
20 *** Variables ***
21 ${HOLDTIME}       180
22 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpflowspec
23 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
24 ${EXP0}           empty-flowspec.json
25 ${CFG1}           bgp-flowspec.cfg
26 ${EXP1}           bgp-flowspec.json
27 ${CFG2}           bgp-flowspec-redirect.cfg
28 ${EXP2}           bgp-flowspec-redirect.json
29 ${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
30
31 *** Test Cases ***
32 Check_For_Empty_Topology_Before_Talking
33     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
34     [Tags]    critical
35     BuiltIn.Wait Until Keyword Succeeds    60s    3s    Verify Empty Flowspec Data
36
37 Reconfigure_ODL_To_Accept_Connection
38     [Documentation]    Configure BGP peer module with initiate-connection set to false.
39     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
40     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}    ${template_as_string}
41
42 FlowSpec Test 1
43     [Documentation]    Testing flowspec values for ${CFG1}
44     [Setup]    Setup Testcase    ${CFG1}
45     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP1}
46     [Teardown]    Stop_Tool
47
48 FlowSpec Test 2
49     [Documentation]    Testing flowspec values for ${CFG2}
50     [Setup]    Setup Testcase    ${CFG2}
51     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP2}
52     [Teardown]    Stop_Tool
53
54 *** Keywords ***
55 Start Suite
56     [Documentation]    Suite setup keyword
57     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
58     Builtin.Set Suite Variable    ${mininet_conn_id}
59     Utils.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
60     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    ls    return_stdout=True    return_stderr=True
61     ...    return_rc=True
62     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
63     ...    return_rc=True
64     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo pip install exabgp    return_stdout=True    return_stderr=True
65     ...    return_rc=True
66     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
67     ConfigViaRestconf.Setup_Config_Via_Restconf
68     Upload Config Files    ${CURDIR}/../../../variables/bgpflowspec/
69
70 Stop Suite
71     [Documentation]    Suite teardown keyword
72     ConfigViaRestconf.Teardown_Config_Via_Restconf
73     SSHLibrary.Close All Connections
74     RequestsLibrary.Delete All Sessions
75
76 Upload Config Files
77     [Arguments]    ${dir_name}
78     [Documentation]    Uploads exabgp config files
79     SSHLibrary.Put Directory    ${CURDIR}/../../../variables/bgpflowspec/    .
80     @{cfgfiles}=    SSHLibrary.List Files In Directory    .    *.cfg
81     : FOR    ${cfgfile}    IN    @{cfgfiles}
82     \    SSHLibrary.Execute Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
83     \    SSHLibrary.Execute Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
84     \    ${stdout}=    SSHLibrary.Execute Command    cat ${cfgfile}
85     \    Log    ${stdout}
86
87 Setup Testcase
88     [Arguments]    ${cfg_file}
89     Verify Empty Flowspec Data
90     Start Tool    ${cfg_file}
91
92 Start_Tool
93     [Arguments]    ${cfg_file}
94     [Documentation]    Start the tool ${cmd} ${cfg_file}
95     BuiltIn.Log    ${cmd} ${cfg_file}
96     ${output}=    SSHLibrary.Write    ${cmd} ${cfg_file}
97     BuiltIn.Log    ${output}
98
99 Wait_Until_Tool_Finish
100     [Arguments]    ${timeout}
101     [Documentation]    Wait ${timeout} for the tool exit.
102     BuiltIn.Wait Until Keyword Succeeds    ${timeout}    1s    SSHLibrary.Read Until Prompt
103
104 Stop_Tool
105     [Documentation]    Stop the tool if still running.
106     Utils.Write_Bare_Ctrl_C
107     ${output}=    SSHLibrary.Read    delay=1s
108     BuiltIn.Log    ${output}
109     Verify Empty Flowspec Data
110
111 Verify Empty Flowspec Data
112     [Documentation]    Verify expected response.
113     Verify Flowspec Data    ${EXP0}
114
115 Verify Flowspec Data
116     [Arguments]    ${exprspfile}
117     [Documentation]    Verify expected response
118     ${keys_with_bits}=    BuiltIn.Create_List    op
119     ${expected_rsp}=    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}
120     ${expected_json}=    norm_json.Normalize Json Text    ${expected_rsp}    keys_with_bits=${keys_with_bits}
121     ${rsp}=    RequestsLibrary.Get Request    session    ${FLOWSPEC_URL}
122     BuiltIn.Log    ${rsp.content}
123     ${received_json}=    norm_json.Normalize Json Text    ${rsp.content}    keys_with_bits=${keys_with_bits}
124     BuiltIn.Log    ${received_json}
125     BuiltIn.Log    ${expected_json}
126     BuiltIn.Should Be Equal    ${received_json}    ${expected_json}