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