Include needed Assure_* keywords in BGP tests
[integration/test.git] / csit / suites / bgpcep / bgpuser / cases.robot
1 *** Settings ***
2 Documentation     Basic tests for odl-bgpcep-bgp-all feature.
3 ...
4 ...               Copyright (c) 2015 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 ...
10 ...               TODO: Rename this file after Beryllium is out, for example to basic.robot
11 ...
12 ...               Test suite performs basic BGP functional test cases:
13 ...               BGP peer initiated coonection
14 ...               - introduce and check 3 prefixes in one update message
15 ...               ODL controller initiated coonection:
16 ...               - introduce and check 3 prefixes in one update message
17 ...               - introduce 2 prefixes in first update message and then additional 2 prefixes
18 ...               in another update while the very first prefix is withdrawn
19 ...               - introduce 3 prefixes and try to withdraw the first one
20 ...               (to be ignored by controller) in a single update message
21 ...
22 ...               Brief description how to perform BGP functional test:
23 ...               https://wiki.opendaylight.org/view/BGP_LS_PCEP:Lithium_Feature_Tests#How_to_test_2
24 ...
25 ...               Reported bugs:
26 ...               https://bugs.opendaylight.org/show_bug.cgi?id=4409
27 ...               https://bugs.opendaylight.org/show_bug.cgi?id=4634
28 Suite Setup       Setup_Everything
29 Suite Teardown    Teardown_Everything
30 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
31 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
32 Library           OperatingSystem
33 Library           SSHLibrary    timeout=10s
34 Library           RequestsLibrary
35 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
36 Variables         ${CURDIR}/../../../variables/Variables.py
37 Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}
38 Resource          ${CURDIR}/../../../libraries/BGPcliKeywords.robot
39 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
40 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
41 Resource          ${CURDIR}/../../../libraries/FailFast.robot
42 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
43 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
44 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
45 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
46 Resource          ${CURDIR}/../../../libraries/Utils.robot
47 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
48
49 *** Variables ***
50 ${ACTUAL_RESPONSES_FOLDER}    ${TEMPDIR}/actual
51 ${EXPECTED_RESPONSES_FOLDER}    ${TEMPDIR}/expected
52 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
53 ${TOOLS_SYSTEM_PROMPT}    ${DEFAULT_LINUX_PROMPT}
54 ${HOLDTIME}       180
55 ${BGP_TOOL_LOG_LEVEL}    info
56 ${CONTROLLER_LOG_LEVEL}    INFO
57 ${CONTROLLER_BGP_LOG_LEVEL}    DEFAULT
58
59 *** Test Cases ***
60 Check_For_Empty_Topology_Before_Talking
61     [Documentation]    Sanity check example-ipv4-topology is up but empty.
62     [Tags]    critical
63     Wait_For_Topology_To_Change_To    ${empty_json}    010_Empty.json    timeout=120s
64     # TODO: Verify that 120 seconds is not too short if this suite is run immediatelly after ODL is started.
65
66 Reconfigure_ODL_To_Accept_Connection
67     [Documentation]    Configure BGP peer module with initiate-connection set to false.
68     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
69     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
70
71 Start_Talking_BGP_speaker
72     [Documentation]    Start Python speaker to connect to ODL, verify that the tool does not promptly exit.
73     # Myport value is needed for checking whether connection at precise port was established.
74     BGPSpeaker.Start_BGP_Speaker    --amount 3 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_TOOL_LOG_LEVEL}
75     Read_And_Fail_If_Prompt_Is_Seen
76
77 Check_Talking_Connection_Is_Established
78     [Documentation]    See TCP (BGP) connection in established state.
79     # This case is separate from the previous one, to resemble structure of the second half of this suite more closely.
80     Check_Speaker_Is_Connected
81     [Teardown]    Utils.Report_Failure_Due_To_Bug    5171
82
83 Check_Talking_Topology_Is_Filled
84     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
85     [Tags]    critical
86     Wait_For_Topology_To_Change_To    ${filled_json}    020_Filled.json
87
88 Kill_Talking_BGP_Speaker
89     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
90     [Tags]    critical
91     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
92     BGPSpeaker.Kill_BGP_Speaker
93     FailFast.Do_Not_Fail_Fast_From_Now_On
94     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
95     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
96
97 Check_For_Empty_Topology_After_Talking
98     [Documentation]    See example-ipv4-topology empty again.
99     [Tags]    critical
100     Wait_For_Topology_To_Change_To    ${empty_json}    030_Empty.json
101
102 Start_Listening_BGP_Speaker
103     [Documentation]    Start Python speaker in listening mode, verify that the tool does not exit quickly.
104     BGPSpeaker.Start_BGP_Speaker    --amount 3 --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --${BGP_TOOL_LOG_LEVEL}
105     Read_And_Fail_If_Prompt_Is_Seen
106
107 Check_Listening_Connection_Is_Not_Established_Yet
108     [Documentation]    See no TCP connection, as both ODL and tool are in listening mode.
109     Check_Speaker_Is_Not_Connected
110
111 Check_For_Empty_Topology_Before_Listening
112     [Documentation]    Sanity check example-ipv4-topology is still empty.
113     [Tags]    critical
114     Verify_That_Topology_Does_Not_Change_From    ${empty_json}    040_Empty.json
115
116 Reconfigure_ODL_To_Initiate_Connection
117     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
118     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
119     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
120
121 Check_Listening_Connection_Is_Established
122     [Documentation]    See TCP (BGP) connection in established state.
123     Check_Speaker_Is_Connected
124
125 Check_Listening_Topology_Is_Filled
126     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
127     [Tags]    critical
128     Wait_For_Topology_To_Change_To    ${filled_json}    050_Filled.json
129
130 Kill_Listening_BGP_Speaker
131     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
132     [Tags]    critical
133     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
134     BGPSpeaker.Kill_BGP_Speaker
135     FailFast.Do_Not_Fail_Fast_From_Now_On
136     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
137     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
138
139 Check_For_Empty_Topology_After_Listening
140     [Documentation]    Post-condition: Check example-ipv4-topology is empty again.
141     [Tags]    critical
142     Wait_For_Topology_To_Change_To    ${empty_json}    060_Empty.json
143
144 Start_Listening_BGP_Speaker_Case_2
145     [Documentation]    BGP Speaker introduces 2 prefixes in the first update & another 2 prefixes while the very first is withdrawn in 2nd update
146     BGPSpeaker.Start_BGP_Speaker    --amount 3 --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --prefill=2 --insert=2 --withdraw=1 --updates=single --firstprefix=8.0.0.240 --${BGP_TOOL_LOG_LEVEL}
147     Read_And_Fail_If_Prompt_Is_Seen
148
149 Check_Listening_Connection_Is_Established_Case_2
150     [Documentation]    See TCP (BGP) connection in established state.
151     Check_Speaker_Is_Connected
152
153 Check_Listening_Topology_Is_Filled_Case_2
154     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
155     [Tags]    critical
156     Wait_For_Topology_To_Change_To    ${filled_json}    050_Filled.json
157     [Teardown]    Report_Failure_Due_To_Bug    4409
158
159 Kill_Listening_BGP_Speaker_Case_2
160     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
161     [Tags]    critical
162     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
163     BGPSpeaker.Kill_BGP_Speaker
164     FailFast.Do_Not_Fail_Fast_From_Now_On
165     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
166     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
167
168 Check_For_Empty_Topology_After_Listening_Case_2
169     [Documentation]    Post-condition: Check example-ipv4-topology is empty again.
170     [Tags]    critical
171     Wait_For_Topology_To_Change_To    ${empty_json}    060_Empty.json
172
173 Start_Listening_BGP_Speaker_Case_3
174     [Documentation]    BGP Speaker introduces 3 prefixes while the first one occures again in the withdrawn list (to be ignored bu controller)
175     BGPSpeaker.Start_BGP_Speaker    --amount 2 --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --prefill=0 --insert=3 --withdraw=1 --updates=single --${BGP_TOOL_LOG_LEVEL}
176     Read_And_Fail_If_Prompt_Is_Seen
177
178 Check_Listening_Connection_Is_Established_Case_3
179     [Documentation]    See TCP (BGP) connection in established state.
180     Check_Speaker_Is_Connected
181
182 Check_Listening_Topology_Is_Filled_Case_3
183     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
184     [Tags]    critical
185     Wait_For_Topology_To_Change_To    ${filled_json}    050_Filled.json
186     [Teardown]    Report_Failure_Due_To_Bug    4634
187
188 Kill_Listening_BGP_Speaker_Case_3
189     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
190     [Tags]    critical
191     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
192     BGPSpeaker.Kill_BGP_Speaker
193     FailFast.Do_Not_Fail_Fast_From_Now_On
194     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
195     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
196
197 Check_For_Empty_Topology_After_Listening_Case_3
198     [Documentation]    Post-condition: Check example-ipv4-topology is empty again.
199     [Tags]    critical
200     Wait_For_Topology_To_Change_To    ${empty_json}    060_Empty.json
201
202 Delete_Bgp_Peer_Configuration
203     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
204     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
205     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
206     # TODO: Do we need to check something else?
207
208 *** Keywords ***
209 Setup_Everything
210     [Documentation]    SSH-login to mininet machine, create HTTP session,
211     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
212     SetupUtils.Setup_Utils_For_Setup_And_Teardown
213     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
214     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
215     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
216     # TODO: Alternatively, create variable in Variables which starts with http.
217     # Both TODOs would probably need to update every suite relying on current Variables.
218     OperatingSystem.Remove_Directory    ${EXPECTED_RESPONSES_FOLDER}    recursive=True
219     OperatingSystem.Remove_Directory    ${ACTUAL_RESPONSES_FOLDER}    recursive=True
220     # The previous suite may have been using the same directories.
221     OperatingSystem.Create_Directory    ${EXPECTED_RESPONSES_FOLDER}
222     OperatingSystem.Create_Directory    ${ACTUAL_RESPONSES_FOLDER}
223     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
224     Utils.Flexible_Mininet_Login
225     SSHKeywords.Require_Python
226     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
227     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
228     ConfigViaRestconf.Setup_Config_Via_Restconf
229     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
230     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.bgpcep
231     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.protocol
232
233 Teardown_Everything
234     [Documentation]    Create and Log the diff between expected and actual responses, make sure Python tool was killed.
235     ...    Tear down imported Resources.
236     ${diff}=    OperatingSystem.Run    diff -dur ${EXPECTED_RESPONSES_FOLDER} ${ACTUAL_RESPONSES_FOLDER}
237     BuiltIn.Log    ${diff}
238     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
239     ConfigViaRestconf.Teardown_Config_Via_Restconf
240     RequestsLibrary.Delete_All_Sessions
241     SSHLibrary.Close_All_Connections
242
243 Wait_For_Topology_To_Change_To
244     [Arguments]    ${json_topology}    ${filename}    ${timeout}=10s    ${refresh}=1s
245     [Documentation]    Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}.
246     ...    Wait until Compare_Topology matches. ${ACTUAL_RESPONSES_FOLDER} will hold its last result.
247     ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${EXPECTED_RESPONSES_FOLDER}
248     BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${refresh}    Compare_Topology    ${topology_normalized}    ${filename}
249
250 Verify_That_Topology_Does_Not_Change_From
251     [Arguments]    ${json_topology}    ${filename}    ${timeout}=10s    ${refresh}=1s
252     [Documentation]    Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}.
253     ...    Verify that Compare_Topology keeps passing. ${ACTUAL_RESPONSES_FOLDER} will hold its last result.
254     ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${EXPECTED_RESPONSES_FOLDER}
255     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${timeout}    ${refresh}    Compare_Topology    ${topology_normalized}    ${filename}
256
257 Compare_Topology
258     [Arguments]    ${expected_normalized}    ${filename}
259     [Documentation]    Get current example-ipv4-topology as json, normalize it, save to ${ACTUAL_RESPONSES_FOLDER}.
260     ...    Check that status code is 200, check that normalized jsons match exactly.
261     ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
262     BuiltIn.Log    ${response.status_code}
263     BuiltIn.Log    ${response.text}
264     ${actual_normalized}=    Normalize_And_Save_Expected_Json    ${response.text}    ${filename}    ${ACTUAL_RESPONSES_FOLDER}
265     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    200
266     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
267
268 Normalize_And_Save_Expected_Json
269     [Arguments]    ${json_text}    ${filename}    ${directory}
270     [Documentation]    Normalize given json using hsf_json library. Log and save the result to given filename under given directory.
271     ${json_normalized}=    hsf_json.Hsf_Json    ${json_text}
272     BuiltIn.Log    ${json_normalized}
273     OperatingSystem.Create_File    ${directory}${/}${filename}    ${json_normalized}
274     # TODO: Should we prepend .json to the filename? When we detect it is not already prepended?
275     [Return]    ${json_normalized}
276
277 Check_Speaker_Is_Not_Connected
278     [Documentation]    Give it a few tries to see zero established connections.
279     BuiltIn.Wait_Until_Keyword_Succeeds    3s    1s    Check_Number_Of_Speaker_Connections    0
280
281 Check_Speaker_Is_Connected
282     [Documentation]    Give it several tries to see exactly one established connection.
283     BuiltIn.Wait_Until_Keyword_Succeeds    5s    1s    Check_Number_Of_Speaker_Connections    1
284
285 Check_Number_Of_Speaker_Connections
286     [Arguments]    ${howmany}
287     [Documentation]    Run netstat in mininet machine and parse it for number of established connections. Check it is ${howmany}.
288     ${output}=    SSHKeywords.Count_Port_Occurences    17900    ESTABLISHED    python
289     BuiltIn.Should_Be_Equal_As_Strings    ${output}    ${howmany}