updating expected results for boron stream
[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 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 Deconfigure_ODL_To_Accept_Connection
55     [Documentation]    Deconfigure BGP peer.
56     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
57     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}    ${template_as_string}
58
59 *** Keywords ***
60 Start Suite
61     [Documentation]    Suite setup keyword
62     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
63     Builtin.Set Suite Variable    ${mininet_conn_id}
64     Utils.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
65     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    ls    return_stdout=True    return_stderr=True
66     ...    return_rc=True
67     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
68     ...    return_rc=True
69     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo pip install exabgp    return_stdout=True    return_stderr=True
70     ...    return_rc=True
71     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
72     ConfigViaRestconf.Setup_Config_Via_Restconf
73     Upload Config Files    ${CURDIR}/../../../variables/bgpflowspec/
74
75 Stop Suite
76     [Documentation]    Suite teardown keyword
77     ConfigViaRestconf.Teardown_Config_Via_Restconf
78     SSHLibrary.Close All Connections
79     RequestsLibrary.Delete All Sessions
80
81 Upload Config Files
82     [Arguments]    ${dir_name}
83     [Documentation]    Uploads exabgp config files
84     SSHLibrary.Put Directory    ${CURDIR}/../../../variables/bgpflowspec/    .
85     @{cfgfiles}=    SSHLibrary.List Files In Directory    .    *.cfg
86     : FOR    ${cfgfile}    IN    @{cfgfiles}
87     \    SSHLibrary.Execute Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
88     \    SSHLibrary.Execute Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
89     \    ${stdout}=    SSHLibrary.Execute Command    cat ${cfgfile}
90     \    Log    ${stdout}
91
92 Setup Testcase
93     [Arguments]    ${cfg_file}
94     Verify Empty Flowspec Data
95     Start Tool    ${cfg_file}
96
97 Start_Tool
98     [Arguments]    ${cfg_file}
99     [Documentation]    Start the tool ${cmd} ${cfg_file}
100     BuiltIn.Log    ${cmd} ${cfg_file}
101     ${output}=    SSHLibrary.Write    ${cmd} ${cfg_file}
102     BuiltIn.Log    ${output}
103
104 Wait_Until_Tool_Finish
105     [Arguments]    ${timeout}
106     [Documentation]    Wait ${timeout} for the tool exit.
107     BuiltIn.Wait Until Keyword Succeeds    ${timeout}    1s    SSHLibrary.Read Until Prompt
108
109 Stop_Tool
110     [Documentation]    Stop the tool if still running.
111     Utils.Write_Bare_Ctrl_C
112     ${output}=    SSHLibrary.Read    delay=1s
113     BuiltIn.Log    ${output}
114     Verify Empty Flowspec Data
115
116 Verify Empty Flowspec Data
117     [Documentation]    Verify expected response.
118     Verify Flowspec Data    ${EXP0}
119
120 Verify Flowspec Data
121     [Arguments]    ${exprspfile}
122     [Documentation]    Verify expected response
123     ${keys_with_bits}=    BuiltIn.Create_List    op
124     ${expected_rsp}=    Get Expected Response From File    ${exprspfile}
125     ${expected_json}=    norm_json.Normalize Json Text    ${expected_rsp}    keys_with_bits=${keys_with_bits}
126     ${rsp}=    RequestsLibrary.Get Request    session    ${FLOWSPEC_URL}
127     BuiltIn.Log    ${rsp.content}
128     ${received_json}=    norm_json.Normalize Json Text    ${rsp.content}    keys_with_bits=${keys_with_bits}
129     BuiltIn.Log    ${received_json}
130     BuiltIn.Log    ${expected_json}
131     BuiltIn.Should Be Equal    ${received_json}    ${expected_json}
132
133 Get Expected Response From File
134     [Arguments]    ${exprspfile}
135     [Documentation]    Looks for release specific response first, then take default.
136     ${status}    ${expresponse}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}.${ODL_STREAM}
137     Return From Keyword If    '${status}' == 'PASS'    ${expresponse}
138     ${expresponse}=    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}
139     [Return]    ${expresponse}