blob: fed2694a991c43c83d9d1461283a02be151b03c8 [file] [log] [blame]
Kailash92764922019-07-25 08:21:39 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Kailash92764922019-07-25 08:21:39 -070014# robot test functions
15
16*** Settings ***
17Documentation Library for various utilities
18Library SSHLibrary
Kailash92764922019-07-25 08:21:39 -070019Library String
20Library DateTime
21Library Process
22Library Collections
23Library RequestsLibrary
24Library OperatingSystem
25
26*** Keywords ***
Kailash528f7c02019-07-31 10:55:49 -070027Check CLI Tools Configured
28 [Documentation] Tests that use 'voltctl' and 'kubectl' should execute this keyword in suite setup
29 # check voltctl and kubectl configured
Zack Williamsa8fe75a2020-01-10 14:25:27 -070030 ${voltctl_rc}= Run And Return RC voltctl device list
31 ${kubectl_rc}= Run And Return RC kubectl get pods
Gilles Depatie675a2062019-10-22 12:44:42 -040032 Run Keyword If ${voltctl_rc} != 0 or ${kubectl_rc} != 0 FATAL ERROR
33 ... VOLTCTL and KUBECTL not configured. Please configure before executing tests.
Gilles Depatieb5682f82019-10-31 10:39:45 -040034
35Send File To Onos
Zack Williamsa8fe75a2020-01-10 14:25:27 -070036 [Documentation] Send the content of the file to Onos to selected section of configuration
37 ... using Post Request
38 [Arguments] ${CONFIG_FILE} ${section}
39 ${Headers}= Create Dictionary Content-Type application/json
40 ${File_Data}= OperatingSystem.Get File ${CONFIG_FILE}
41 Log ${Headers}
42 Log ${File_Data}
43 ${resp}= Post Request ONOS
44 ... /onos/v1/network/configuration/${section} headers=${Headers} data=${File_Data}
45 Should Be Equal As Strings ${resp.status_code} 200
Andy Bavier88cd9f62019-11-26 16:22:33 -070046
47Common Test Suite Setup
48 [Documentation] Setup the test suite
49 # BBSim sanity test doesn't need these imports from other repositories
Andy Bavier88cd9f62019-11-26 16:22:33 -070050 Run Keyword If ${external_libs} Import Resource
Andy Baviera2691752019-11-27 12:18:38 -070051 ... ${CURDIR}/../../cord-tester/src/test/cord-api/Framework/Subscriber.robot
Andy Bavier88cd9f62019-11-26 16:22:33 -070052 Run Keyword If ${external_libs} Import Resource
Andy Baviera2691752019-11-27 12:18:38 -070053 ... ${CURDIR}/../../cord-tester/src/test/cord-api/Framework/OLT.robot
Andy Bavier88cd9f62019-11-26 16:22:33 -070054 Run Keyword If ${external_libs} Import Resource
Andy Baviera2691752019-11-27 12:18:38 -070055 ... ${CURDIR}/../../cord-tester/src/test/cord-api/Framework/DHCP.robot
Andy Bavier88cd9f62019-11-26 16:22:33 -070056 Run Keyword If ${external_libs} Import Resource
Andy Baviera2691752019-11-27 12:18:38 -070057 ... ${CURDIR}/../../cord-tester/src/test/cord-api/Framework/Kubernetes.robot
Andy Bavier88cd9f62019-11-26 16:22:33 -070058 Set Global Variable ${KUBECTL_CONFIG} export KUBECONFIG=%{KUBECONFIG}
59 Set Global Variable ${VOLTCTL_CONFIG} export VOLTCONFIG=%{VOLTCONFIG}
60 ${k8s_node_ip}= Evaluate ${nodes}[0].get("ip")
61 ${k8s_node_user}= Evaluate ${nodes}[0].get("user")
62 ${k8s_node_pass}= Evaluate ${nodes}[0].get("pass")
63 Check CLI Tools Configured
64 ${onos_auth}= Create List karaf karaf
65 ${HEADERS} Create Dictionary Content-Type=application/json
66 Create Session ONOS http://${k8s_node_ip}:${ONOS_REST_PORT} auth=${ONOS_AUTH}
67 ${olt_ip}= Evaluate ${olts}[0].get("ip")
68 ${olt_user}= Evaluate ${olts}[0].get("user")
69 ${olt_pass}= Evaluate ${olts}[0].get("pass")
70 ${olt_serial_number}= Evaluate ${olts}[0].get("serial")
71 ${num_onus}= Get Length ${hosts.src}
72 ${num_onus}= Convert to String ${num_onus}
73 #send sadis file to onos
Andy Baviera2691752019-11-27 12:18:38 -070074 ${sadis_file}= Get Variable Value ${sadis.file}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070075 Log To Console \nSadis File:${sadis_file}
Andy Bavier88cd9f62019-11-26 16:22:33 -070076 Run Keyword Unless '${sadis_file}' is '${None}' Send File To Onos ${sadis_file} apps/
77 Set Suite Variable ${num_onus}
78 Set Suite Variable ${olt_serial_number}
79 Set Suite Variable ${olt_ip}
80 Set Suite Variable ${olt_user}
81 Set Suite Variable ${olt_pass}
82 Set Suite Variable ${k8s_node_ip}
83 Set Suite Variable ${k8s_node_user}
84 Set Suite Variable ${k8s_node_pass}
85 @{container_list}= Create List adapter-open-olt adapter-open-onu voltha-api-server
86 ... voltha-ro-core voltha-rw-core-11 voltha-rw-core-12 voltha-ofagent
87 Set Suite Variable ${container_list}
88 ${datetime}= Get Current Date
suraj gour7f6d5fe2019-11-29 10:56:35 +000089 Set Suite Variable ${datetime}
90
91WPA Reassociate
suraj gour7f6d5fe2019-11-29 10:56:35 +000092 [Documentation] Executes a particular wpa_cli reassociate, which performs force reassociation
Zack Williamsa8fe75a2020-01-10 14:25:27 -070093 [Arguments] ${iface} ${ip} ${user} ${pass}=${None}
94 ... ${container_type}=${None} ${container_name}=${None}
suraj gour7f6d5fe2019-11-29 10:56:35 +000095 #Below for loops are used instead of sleep time, to execute reassociate command and check status
Zack Williamsa8fe75a2020-01-10 14:25:27 -070096 FOR ${i} IN RANGE 70
97 ${output}= Login And Run Command On Remote System
98 ... wpa_cli -i ${iface} reassociate ${ip} ${user}
99 ... ${pass} ${container_type} ${container_name}
100 ${passed}= Run Keyword And Return Status Should Contain ${output} OK
101 Run Keyword If ${passed} Exit For Loop
102 END
103 FOR ${i} IN RANGE 70
104 ${output}= Login And Run Command On Remote System
105 ... wpa_cli status | grep SUCCESS ${ip} ${user}
106 ... ${pass} ${container_type} ${container_name}
107 ${passed}= Run Keyword And Return Status Should Contain ${output} SUCCESS
108 Run Keyword If ${passed} Exit For Loop
109 END
110
suraj gour7f6d5fe2019-11-29 10:56:35 +0000111Validate Authentication After Reassociate
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700112 [Arguments] ${auth_pass} ${iface} ${ip} ${user} ${pass}=${None}
113 ... ${container_type}=${None} ${container_name}=${None}
114 [Documentation]
115 ... Executes a particular reassociate request on the RG using wpa_cli.
116 ... auth_pass determines if authentication should pass
suraj gour7f6d5fe2019-11-29 10:56:35 +0000117 WPA Reassociate ${iface} ${ip} ${user} ${pass} ${container_type} ${container_name}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700118 Run Keyword If '${auth_pass}' == 'True' Wait Until Keyword Succeeds ${timeout} 2s
119 ... Check Remote File Contents True /tmp/wpa.log authentication completed successfully
120 ... ${ip} ${user} ${pass} ${container_type} ${container_name}
suraj gour7f6d5fe2019-11-29 10:56:35 +0000121 Run Keyword If '${auth_pass}' == 'False' Sleep 20s
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700122 Run Keyword If '${auth_pass}' == 'False' Check Remote File Contents False /tmp/wpa.log
123 ... authentication completed successfully ${ip} ${user} ${pass}
124 ... ${container_type} ${container_name}
suraj gourd5cfdbb2019-12-13 12:44:55 +0000125
126Send Dhclient Request To Release Assigned IP
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700127 [Arguments] ${iface} ${ip} ${user} ${path_dhcpleasefile} ${pass}=${None}
128 ... ${container_type}=${None} ${container_name}=${None}
suraj gourd5cfdbb2019-12-13 12:44:55 +0000129 [Documentation] Executes a dhclient with option to release ip against a particular interface on the RG (src)
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700130 ${result}= Login And Run Command On Remote System
131 ... dhclient -nw -r ${iface} && rm ${path_dhcpleasefile}/dhclient.* ${ip} ${user}
suraj gourd5cfdbb2019-12-13 12:44:55 +0000132 ... ${pass} ${container_type} ${container_name}
133 Log ${result}
134 #Should Contain ${result} DHCPRELEASE
135 [Return] ${result}
suraj gour1ecfae92019-12-20 15:11:40 +0000136
137Check Remote File Contents For WPA Logs
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700138 [Arguments] ${file_should_exist} ${file} ${pattern} ${ip} ${user} ${pass}=${None}
139 ... ${container_type}=${None} ${container_name}=${None} ${prompt}=~$
suraj gour1ecfae92019-12-20 15:11:40 +0000140 [Documentation] Checks for particular pattern count in a file
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700141 ${result}= Login And Run Command On Remote System
142 ... cat ${file} | grep '${pattern}' | wc -l ${ip} ${user} ${pass}
suraj gour1ecfae92019-12-20 15:11:40 +0000143 ... ${container_type} ${container_name} ${prompt}
144 [Return] ${result}
Gayathri.Selvanee4a91b2020-01-17 06:49:53 +0000145
146Perform Sanity Test
147 [Documentation] This keyword performs Sanity Test Procedure
148 ... Sanity test performs authentication, dhcp and pings for all the ONUs given for the POD
149 ... This keyword can be used to call in any other tests where sanity check is required
150 ... and avoids duplication of code.
151 ${of_id}= Wait Until Keyword Succeeds ${timeout} 15s Validate OLT Device in ONOS ${olt_serial_number}
152 Set Global Variable ${of_id}
153 FOR ${I} IN RANGE 0 ${num_onus}
154 ${src}= Set Variable ${hosts.src[${I}]}
155 ${dst}= Set Variable ${hosts.dst[${I}]}
156 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 5s Validate Device
157 ... ENABLED ACTIVE REACHABLE
158 ... ${src['onu']} onu=True onu_reason=omci-flows-pushed
159 ${onu_device_id}= Get Device ID From SN ${src['onu']}
160 ${onu_port}= Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 2s
161 ... Get ONU Port in ONOS ${src['onu']} ${of_id}
162 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 2s
163 ... Verify Eapol Flows Added For ONU ${k8s_node_ip} ${ONOS_SSH_PORT} ${onu_port}
164 Run Keyword If ${has_dataplane} Run Keyword And Continue On Failure Validate Authentication True
165 ... ${src['dp_iface_name']} wpa_supplicant.conf ${src['ip']} ${src['user']} ${src['pass']}
166 ... ${src['container_type']} ${src['container_name']}
167 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 2
168 ... Verify ONU in AAA-Users ${k8s_node_ip} ${ONOS_SSH_PORT} ${onu_port}
169 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 2
170 ... Execute ONOS CLI Command ${k8s_node_ip} ${ONOS_SSH_PORT}
171 ... volt-add-subscriber-access ${of_id} ${onu_port}
172 Run Keyword If ${has_dataplane} Run Keyword And Continue On Failure Validate DHCP and Ping True
173 ... True ${src['dp_iface_name']} ${src['s_tag']} ${src['c_tag']} ${dst['dp_iface_ip_qinq']}
174 ... ${src['ip']} ${src['user']} ${src['pass']} ${src['container_type']} ${src['container_name']}
175 ... ${dst['dp_iface_name']} ${dst['ip']} ${dst['user']} ${dst['pass']} ${dst['container_type']}
176 ... ${dst['container_name']}
177 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 2s
178 ... Validate Subscriber DHCP Allocation ${k8s_node_ip} ${ONOS_SSH_PORT} ${onu_port}
179 Run Keyword and Ignore Error Get Device Output from Voltha ${onu_device_id}
180 Run Keyword and Ignore Error Collect Logs
181 END
182
183Setup
184 [Documentation] Pre-test Setup
185 #test for empty device list
186 Test Empty Device List
187 Run Keyword If ${has_dataplane} Wait Until Keyword Succeeds 120s 10s Openolt is Up
188 ... ${olt_ip} ${olt_user} ${olt_pass}
189 Sleep 60s
190 #create/preprovision device
191 ${olt_device_id}= Create Device ${olt_ip} ${OLT_PORT}
192 Set Suite Variable ${olt_device_id}
193 #validate olt states
194 Wait Until Keyword Succeeds ${timeout} 5s
195 ... Validate OLT Device PREPROVISIONED UNKNOWN UNKNOWN ${EMPTY} ${olt_device_id}
196 Enable Device ${olt_device_id}
197 Wait Until Keyword Succeeds ${timeout} 5s
198 ... Validate OLT Device ENABLED ACTIVE REACHABLE ${olt_serial_number}
199 ${logical_id}= Get Logical Device ID From SN ${olt_serial_number}
200 Set Suite Variable ${logical_id}
201
202Delete All Devices and Verify
203 [Documentation] Remove any devices from VOLTHA and ONOS
204 # Clear devices from VOLTHA
205 Disable Devices In Voltha Root=true
206 Wait Until Keyword Succeeds ${timeout} 2s Test Devices Disabled In Voltha Root=true
207 Delete Devices In Voltha Root=true
208 Wait Until Keyword Succeeds ${timeout} 2s Test Empty Device List
209 # Clear devices from ONOS
210 Remove All Devices From ONOS
211 ... http://karaf:karaf@${k8s_node_ip}:${ONOS_REST_PORT}
212
213Teardown
214 [Documentation] kills processes and cleans up interfaces on src+dst servers
215 Run Keyword If ${has_dataplane} Clean Up Linux
216 Run Keyword If ${external_libs} Run Keyword and Ignore Error
217 ... Log Kubernetes Containers Logs Since Time
218 ... ${datetime} ${container_list}
219
220Teardown Suite
221 [Documentation] Clean up device if desired
222 Run Keyword If ${teardown_device} Delete All Devices and Verify
223
224Delete Device and Verify
225 [Documentation] Disable -> Delete devices via voltctl and verify its removed
Suchitra Vemuri2fa9bba2020-01-22 17:38:48 -0800226 ${olt_device_id}= Get Device ID From SN ${olt_serial_number}
Gayathri.Selvanee4a91b2020-01-17 06:49:53 +0000227 ${rc} ${output}= Run and Return Rc and Output
228 ... ${VOLTCTL_CONFIG}; voltctl device disable ${olt_device_id}
229 Should Be Equal As Integers ${rc} 0
230 Sleep 5s
231 Wait Until Keyword Succeeds ${timeout} 5s
232 ... Validate OLT Device DISABLED UNKNOWN REACHABLE ${olt_serial_number}
233 ${rc} ${output}= Run and Return Rc and Output
234 ... ${VOLTCTL_CONFIG}; voltctl device delete ${olt_device_id}
235 Sleep 50s
236 Should Be Equal As Integers ${rc} 0
237 Wait Until Keyword Succeeds ${timeout} 5s Validate Device Removed ${olt_device_id}
238
Gayathri.Selvan283a63c2020-01-23 04:09:18 +0000239Repeat Sanity Test
240 [Documentation] This keyword performs Sanity Test Procedure
241 ... Sanity test performs authentication, dhcp and pings for all the ONUs given for the POD
242 ... This keyword can be used to call in any other tests where sanity check is required
243 ... with wpa reassociation
244 ${of_id}= Wait Until Keyword Succeeds ${timeout} 15s Validate OLT Device in ONOS ${olt_serial_number}
245 Set Global Variable ${of_id}
246 FOR ${I} IN RANGE 0 ${num_onus}
247 ${src}= Set Variable ${hosts.src[${I}]}
248 ${dst}= Set Variable ${hosts.dst[${I}]}
Suchitra Vemurid1e27fb2020-02-01 16:34:37 -0800249 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 5s Validate Device
Suchitra Vemuri81e4f022020-02-01 13:16:02 -0800250 ... ENABLED ACTIVE REACHABLE
251 ... ${src['onu']} onu=True onu_reason=omci-flows-pushed
Gayathri.Selvan283a63c2020-01-23 04:09:18 +0000252 ${onu_device_id}= Get Device ID From SN ${src['onu']}
253 ${onu_port}= Wait Until Keyword Succeeds ${timeout} 2s
254 ... Get ONU Port in ONOS ${src['onu']} ${of_id}
255 Wait Until Keyword Succeeds ${timeout} 2s
256 ... Verify Eapol Flows Added For ONU ${k8s_node_ip} ${ONOS_SSH_PORT} ${onu_port}
257 Run Keyword If ${has_dataplane} Run Keyword And Continue On Failure
258 ... Validate Authentication After Reassociate
259 ... True ${src['dp_iface_name']} ${src['ip']} ${src['user']} ${src['pass']}
260 ... ${src['container_type']} ${src['container_name']}
261 Wait Until Keyword Succeeds ${timeout} 2s
262 ... Verify ONU in AAA-Users ${k8s_node_ip} ${ONOS_SSH_PORT} ${onu_port}
263 Wait Until Keyword Succeeds ${timeout} 2s
264 ... Execute ONOS CLI Command ${k8s_node_ip} ${ONOS_SSH_PORT}
265 ... volt-add-subscriber-access ${of_id} ${onu_port}
266 Run Keyword If ${has_dataplane} Run Keyword And Continue On Failure
267 ... Validate DHCP and Ping True True
268 ... ${src['dp_iface_name']} ${src['s_tag']} ${src['c_tag']} ${dst['dp_iface_ip_qinq']}
269 ... ${src['ip']} ${src['user']} ${src['pass']} ${src['container_type']} ${src['container_name']}
270 ... ${dst['dp_iface_name']} ${dst['ip']} ${dst['user']} ${dst['pass']} ${dst['container_type']}
271 ... ${dst['container_name']}
272 Wait Until Keyword Succeeds ${timeout} 2s Run Keyword And Continue On Failure
273 ... Validate Subscriber DHCP Allocation ${k8s_node_ip} ${ONOS_SSH_PORT} ${onu_port}
274 Run Keyword and Ignore Error Get Device Output from Voltha ${onu_device_id}
275 Run Keyword and Ignore Error Collect Logs
276 END
Gayathri.Selvanb6a2b542020-01-24 07:24:23 +0000277
278Collect Logs
279 [Documentation] Collect Logs from voltha and onos cli for various commands
280 Run Keyword and Ignore Error Get Device List from Voltha
281 Run Keyword and Ignore Error Get Device Output from Voltha ${olt_device_id}
282 Run Keyword and Ignore Error Get Logical Device Output from Voltha ${logical_id}
283 Run Keyword If ${external_libs} Get ONOS Status ${k8s_node_ip}
Gayathri.Selvanf68ea4b2020-02-03 07:36:39 +0000284
285Verify ping is succesful except for given device
286 [Arguments] ${num_onus} ${exceptional_onu_id}
287 [Documentation] Checks that ping for all the devices are successful except the given ONU.
288 ${pingStatus} Set Variable True
289 FOR ${I} IN RANGE 0 ${num_onus}
290 ${src}= Set Variable ${hosts.src[${I}]}
291 ${dst}= Set Variable ${hosts.dst[${I}]}
292 ${onu_device_id}= Get Device ID From SN ${src['onu']}
293 ${pingStatus} Run Keyword If '${onu_device_id}' == '${exceptional_onu_id}' Set Variable False
294 Run Keyword And Continue On Failure Wait Until Keyword Succeeds 60s 2s
295 ... Check Ping ${pingStatus} ${dst['dp_iface_ip_qinq']} ${src['dp_iface_name']}
296 ... ${src['ip']} ${src['user']} ${src['pass']} ${src['container_type']} ${src['container_name']}
297 END
Andy Bavier4a8450e2020-02-04 08:58:37 -0700298
299Announce Message
300 [Arguments] ${message}
301 [Documentation] Announce a message that will be picked up by the log aggregator
Andy Bavier1af971b2020-02-05 14:26:21 -0700302 Run Process kubectl run announcer -ti --rm --restart Never --image ubuntu
Andy Bavier4a8450e2020-02-04 08:58:37 -0700303 ... bash -- -c echo; sleep 1; echo ${message}; sleep 1; date --rfc-3339\=n ; sleep 1; echo; sleep 1
Suchitra Vemuria5fa3dd2020-02-04 14:38:49 -0800304
305Clean Up Linux
306 [Documentation] Kill processes and clean up interfaces on src+dst servers
307 FOR ${I} IN RANGE 0 ${num_onus}
308 ${src}= Set Variable ${hosts.src[${I}]}
309 ${dst}= Set Variable ${hosts.dst[${I}]}
310 Run Keyword And Ignore Error Kill Linux Process [w]pa_supplicant ${src['ip']}
311 ... ${src['user']} ${src['pass']} ${src['container_type']} ${src['container_name']}
312 Run Keyword And Ignore Error Kill Linux Process [d]hclient ${src['ip']}
313 ... ${src['user']} ${src['pass']} ${src['container_type']} ${src['container_name']}
314 Run Keyword If '${dst['ip']}' != '${None}' Run Keyword And Ignore Error
315 ... Kill Linux Process [d]hcpd ${dst['ip']} ${dst['user']}
316 ... ${dst['pass']} ${dst['container_type']} ${dst['container_name']}
317 Delete IP Addresses from Interface on Remote Host ${src['dp_iface_name']} ${src['ip']}
318 ... ${src['user']} ${src['pass']} ${src['container_type']} ${src['container_name']}
319 Run Keyword If '${dst['ip']}' != '${None}' Delete Interface on Remote Host
320 ... ${dst['dp_iface_name']}.${src['s_tag']} ${dst['ip']} ${dst['user']} ${dst['pass']}
321 ... ${dst['container_type']} ${dst['container_name']}
322 END