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
11 ... Brief description of what this suite should do:
12 ... https://wiki.opendaylight.org/view/BGP_LS_PCEP:Lithium_Feature_Tests#How_to_test_2
13 Suite Setup Setup_Everything
14 Suite Teardown Teardown_Everything
15 Test Setup FailFast.Fail_This_Fast_On_Previous_Error
16 Test Teardown FailFast.Start_Failing_Fast_If_This_Failed
17 Library OperatingSystem
18 Library SSHLibrary prompt=]> timeout=10s # FIXME: The prompt should have default value from a common resource, and should be overwritable by pybot -v in scripts.
19 Library RequestsLibrary
20 Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
21 Variables ${CURDIR}/../../../variables/Variables.py
22 Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${MININET}
23 Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
24 Resource ${CURDIR}/../../../libraries/FailFast.robot
25 Resource ${CURDIR}/../../../libraries/KillPythonTool.robot
26 Resource ${CURDIR}/../../../libraries/WaitForFailure.robot
27 Resource ${CURDIR}/../../../libraries/Utils.robot
30 ${directory_for_actual_responses} ${TEMPDIR}/actual
31 ${directory_for_expected_responses} ${TEMPDIR}/expected
32 ${directory_with_template_folders} ${CURDIR}/../../../variables/bgpuser/
35 Check_For_Empty_Topology_Before_Talking
36 [Documentation] Sanity check example-ipv4-topology is up but empty.
38 Wait_For_Topology_To_Change_To ${empty_json} 010_Empty.json timeout=120s
39 # TODO: Verify that 120 seconds is not too short if this suite is run immediatelly after ODL is started.
41 Reconfigure_ODL_To_Accept_Connection
42 [Documentation] Configure BGP peer module with initiate-connection set to false.
43 ${template_as_string}= BuiltIn.Set_Variable {'IP': '${MININET}', 'INITIATE': 'false'}
44 Put_Xml_Template_Folder_Config_Via_Restconf ${directory_with_template_folders}${/}bgp_peer ${template_as_string}
46 Start_Talking_BGP_speaker
47 [Documentation] Start Python speaker to connect to ODL, verify that the tool does not promptly exit.
48 ${command}= BuiltIn.Set_Variable python play.py --amount 2 --myip=${MININET} --myport=17900 --peerip=${CONTROLLER} --peerport=1790
49 # Myport value is needed for checking whether connection at precise port was established.
50 # TODO: Do we want to define ${BGP_PORT} in Variables.py?
51 BuiltIn.Log ${command}
52 ${output}= SSHLibrary.Write ${command}
53 Read_And_Fail_If_Prompt_Is_Seen
55 Check_Talking_Connection_Is_Established
56 [Documentation] See TCP (BGP) connection in established state.
57 # This case is separate from the previous one, to resemble structure of the second half of this suite more closely.
58 Check_Speaker_Is_Connected
60 Check_Talking_Topology_Is_Filled
61 [Documentation] See new routes in example-ipv4-topology as a proof that synchronization was correct.
63 Wait_For_Topology_To_Change_To ${filled_json} 020_Filled.json
65 Kill_Talking_BGP_Speaker
66 [Documentation] Abort the Python speaker. Also, attempt to stop failing fast.
67 [Setup] FailFast.Run_Even_When_Failing_Fast
69 FailFast.Do_Not_Fail_Fast_From_Now_On
70 # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
71 [Teardown] FailFast.Do_Not_Start_Failing_If_This_Failed
73 Check_For_Empty_Topology_After_Talking
74 [Documentation] See example-ipv4-topology empty again.
76 Wait_For_Topology_To_Change_To ${empty_json} 030_Empty.json
78 Start_Listening_BGP_Speaker
79 [Documentation] Start Python speaker in listening mode, verify that the tool does not exit quickly.
80 ${command}= BuiltIn.Set_Variable python play.py --amount 2 --listen --myip=${MININET} --myport=17900 --peerip=${CONTROLLER}
81 # TODO: ${BGP_TOOL_PORT} is probably not worth the trouble.
82 Builtin.Log ${command}
83 ${output}= SSHLibrary.Write ${command}
84 Read_And_Fail_If_Prompt_Is_Seen
86 Check_Listening_Connection_Is_Not_Established_Yet
87 [Documentation] See no TCP connection, as both ODL and tool are in listening mode.
88 Check_Speaker_Is_Not_Connected
90 Check_For_Empty_Topology_Before_Listening
91 [Documentation] Sanity check example-ipv4-topology is still empty.
93 Verify_That_Topology_Does_Not_Change_From ${empty_json} 040_Empty.json
95 Reconfigure_ODL_To_Initiate_Connection
96 [Documentation] Replace BGP peer config module, now with initiate-connection set to true.
97 ${template_as_string}= BuiltIn.Set_Variable {'IP': '${MININET}', 'INITIATE': 'true'}
98 Put_Xml_Template_Folder_Config_Via_Restconf ${directory_with_template_folders}${/}bgp_peer ${template_as_string}
100 Check_Listening_Connection_Is_Established
101 [Documentation] See TCP (BGP) connection in established state.
102 Check_Speaker_Is_Connected
104 Check_Listening_Topology_Is_Filled
105 [Documentation] See new routes in example-ipv4-topology as a proof that synchronization was correct.
107 Wait_For_Topology_To_Change_To ${filled_json} 050_Filled.json
109 Kill_Listening_BGP_Speaker
110 [Documentation] Abort the Python speaker. Also, attempt to stop failing fast.
111 [Setup] FailFast.Run_Even_When_Failing_Fast
113 FailFast.Do_Not_Fail_Fast_From_Now_On
114 # NOTE: It is still possible to remain failing, if both previous and this test failed.
115 [Teardown] FailFast.Do_Not_Start_Failing_If_This_Failed
117 Check_For_Empty_Topology_After_Listening
118 [Documentation] Post-condition: Check example-ipv4-topology is empty again.
120 Wait_For_Topology_To_Change_To ${empty_json} 060_Empty.json
122 Delete_Bgp_Peer_Configuration
123 [Documentation] Revert the BGP configuration to the original state: without any configured peers.
124 Delete_Xml_Template_Folder_Config_Via_Restconf ${directory_with_template_folders}${/}bgp_peer
125 # TODO: Do we need to check something else?
129 [Documentation] SSH-login to mininet machine, save prompt to variable, create HTTP session,
130 ... prepare directories for responses, put Python tool to mininet machine, setup imported resources.
131 SSHLibrary.Open_Connection ${MININET}
132 Flexible SSH Login ${MININET_USER} ${MININET_PASSWORD}
133 ${current_connection}= Get_Connection
134 ${current_prompt}= BuiltIn.Set_Variable ${current_connection.prompt}
135 BuiltIn.Log ${current_prompt}
136 Builtin.Set_Suite_Variable ${prompt} ${current_prompt}
137 RequestsLibrary.Create_Session ses http://${CONTROLLER}:${RESTCONFPORT}${OPERATIONAL_TOPO_API} auth=${AUTH}
138 # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
139 # TODO: Alternatively, create variable in Variables which starts with http.
140 # Both TODOs would probably need to update every suite relying on current Variables.
141 OperatingSystem.Remove_Directory ${directory_for_expected_responses} recursive=True
142 OperatingSystem.Remove_Directory ${directory_for_actual_responses} recursive=True
143 # The previous suite may have been using the same directories.
144 OperatingSystem.Create_Directory ${directory_for_expected_responses}
145 OperatingSystem.Create_Directory ${directory_for_actual_responses}
146 SSHLibrary.Put_File ${CURDIR}/../../../../tools/fastbgp/play.py
147 ConfigViaRestconf.Setup_Config_Via_Restconf
148 FailFast.Do_Not_Fail_Fast_From_Now_On
151 [Documentation] Create and Log the diff between expected and actual responses, make sure Python tool was killed.
152 ... Tear down imported Resources.
153 ${diff}= OperatingSystem.Run diff -dur ${directory_for_expected_responses} ${directory_for_actual_responses}
155 KillPythonTool.Search_And_Kill_Remote_Python 'play\.py'
156 ConfigViaRestconf.Teardown_Config_Via_Restconf
157 RequestsLibrary.Delete_All_Sessions
158 SSHLibrary.Close_All_Connections
160 Wait_For_Topology_To_Change_To
161 [Arguments] ${json_topology} ${filename} ${timeout}=10s ${refresh}=1s
162 [Documentation] Normalize the expected json topology and save it to ${directory_for_expected_responses}.
163 ... Wait until Compare_Topology matches. ${directory_for_actual_responses} will hold its last result.
164 ${topology_normalized}= Normalize_And_Save_Expected_Json ${json_topology} ${filename} ${directory_for_expected_responses}
165 BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} ${refresh} Compare_Topology ${topology_normalized} ${filename}
167 Verify_That_Topology_Does_Not_Change_From
168 [Arguments] ${json_topology} ${filename} ${timeout}=10s ${refresh}=1s
169 [Documentation] Normalize the expected json topology and save it to ${directory_for_expected_responses}.
170 ... Verify that Compare_Topology keeps passing. ${directory_for_actual_responses} will hold its last result.
171 ${topology_normalized}= Normalize_And_Save_Expected_Json ${json_topology} ${filename} ${directory_for_expected_responses}
172 WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout ${timeout} ${refresh} Compare_Topology ${topology_normalized} ${filename}
175 [Arguments] ${expected_normalized} ${filename}
176 [Documentation] Get current example-ipv4-topology as json, normalize it, save to ${directory_for_actual_responses}.
177 ... Check that status code is 200, check that normalized jsons match exactly.
178 ${response}= RequestsLibrary.Get_Request ses topology/example-ipv4-topology
179 BuiltIn.Log ${response.status_code}
180 BuiltIn.Log ${response.text}
181 ${actual_normalized}= Normalize_And_Save_Expected_Json ${response.text} ${filename} ${directory_for_actual_responses}
182 BuiltIn.Should_Be_Equal_As_Strings ${response.status_code} 200
183 BuiltIn.Should_Be_Equal ${actual_normalized} ${expected_normalized}
185 Normalize_And_Save_Expected_Json
186 [Arguments] ${json_text} ${filename} ${directory}
187 [Documentation] Normalize given json using hsf_json library. Log and save the result to given filename under given directory.
188 ${json_normalized}= hsf_json.Hsf_Json ${json_text}
189 BuiltIn.Log ${json_normalized}
190 OperatingSystem.Create_File ${directory}${/}${filename} ${json_normalized}
191 # TODO: Should we prepend .json to the filename? When we detect it is not already prepended?
192 [Return] ${json_normalized}
195 [Documentation] Interrupt play.py, fail if no prompt is seen within SSHLibrary timeout.
196 ... Also, check that TCP connection is no longer established.
198 SSHLibrary.Read_Until_Prompt
199 Check_Speaker_Is_Not_Connected
201 Check_Speaker_Is_Not_Connected
202 [Documentation] Give it a few tries to see zero established connections.
203 BuiltIn.Wait_Until_Keyword_Succeeds 3s 1s Check_Number_Of_Speaker_Connections 0
205 Check_Speaker_Is_Connected
206 [Documentation] Give it several tries to see exactly one established connection.
207 BuiltIn.Wait_Until_Keyword_Succeeds 5s 1s Check_Number_Of_Speaker_Connections 1
209 Check_Number_Of_Speaker_Connections
210 [Arguments] ${howmany}
211 [Documentation] Run netstat in mininet machine and parse it for number of established connections. Check it is ${howmany}.
212 ${output}= SSHLibrary.Execute_Command netstat -npt 2> /dev/null | grep -E ":17900 .+ ESTABLISHED .+python" | wc -l
213 BuiltIn.Should_Be_Equal_As_Strings ${output} ${howmany}
215 Read_And_Fail_If_Prompt_Is_Seen
216 [Documentation] Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
217 BuiltIn.Run_Keyword_And_Expect_Error No match found for '${prompt}' in *. Read_Text_Before_Prompt
219 Read_Text_Before_Prompt
220 [Documentation] Log text gathered by SSHLibrary.Read_Until_Prompt.
221 ... This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
222 ${text}= SSHLibrary.Read_Until_Prompt
226 [Documentation] Construct ctrl+c character and SSH-write it (without endline). Do not read anything yet.
227 # TODO: Place this keyword to some Resource so that it can be re-used in other suites.
228 ${command}= BuiltIn.Evaluate chr(int(3))
229 SSHLibrary.Write_Bare ${command}