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