blob: 71da9a129dae0475a7a68ef99036639ef381110f [file] [log] [blame]
Kailash6f5acb62019-08-28 14:38:45 -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.
14
15# voltctl common functions
16
17*** Settings ***
18Documentation Library for various utilities
19Library SSHLibrary
20Library HttpLibrary.HTTP
21Library String
22Library DateTime
23Library Process
24Library Collections
25Library RequestsLibrary
26Library OperatingSystem
27
28*** Keywords ***
Gilles Depatieb5682f82019-10-31 10:39:45 -040029Test Empty Device List
30 [Documentation] Verify that there are no devices in the system
31 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
32 Should Be Equal As Integers ${rc} 0
33 ${jsondata}= To Json ${output}
34 Log ${jsondata}
35 ${length}= Get Length ${jsondata}
36 [Return] ${length}
37
Kailash6f5acb62019-08-28 14:38:45 -070038Create Device
39 [Arguments] ${ip} ${port}
You Wang2b550642019-10-07 14:39:48 -070040 [Documentation] Creates a device in VOLTHA
Kailash6f5acb62019-08-28 14:38:45 -070041 #create/preprovision device
Gilles Depatie675a2062019-10-22 12:44:42 -040042 ${rc} ${device_id}= Run and Return Rc and Output
43 ... ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port}
Kailash6f5acb62019-08-28 14:38:45 -070044 Should Be Equal As Integers ${rc} 0
45 [Return] ${device_id}
46
47Enable Device
48 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070049 [Documentation] Enables a device in VOLTHA
Kailash6f5acb62019-08-28 14:38:45 -070050 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device enable ${device_id}
51 Should Be Equal As Integers ${rc} 0
52
Suchitra Vemuri6db89412019-11-14 14:52:54 -080053Disable Device
54 [Arguments] ${device_id}
55 [Documentation] Enables a device in VOLTHA
56 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device disable ${device_id}
57 Should Be Equal As Integers ${rc} 0
58
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070059Get Device Flows from Voltha
60 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070061 [Documentation] Gets device flows from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070062 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
63 Should Be Equal As Integers ${rc} 0
64 [Return] ${output}
65
66Get Logical Device Output from Voltha
67 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070068 [Documentation] Gets logicaldevice flows and ports from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070069 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device_id}
70 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice ports ${device_id}
71 Log ${flows}
72 Log ${ports}
73 Should Be Equal As Integers ${rc1} 0
74 Should Be Equal As Integers ${rc2} 0
75
76Get Device Output from Voltha
77 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070078 [Documentation] Gets device flows and ports from VOLTHA
Suchitra Vemuri00d147d2019-09-13 13:07:32 -070079 ${rc1} ${flows}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
80 ${rc2} ${ports}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${device_id}
81 Log ${flows}
82 Log ${ports}
83 Should Be Equal As Integers ${rc1} 0
84 Should Be Equal As Integers ${rc2} 0
85
Suchitra Vemuri1a970a62019-11-26 12:52:16 -080086Get Device List from Voltha
87 [Documentation] Gets Device List Output from Voltha
88 ${rc1} ${devices}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list
89 Log ${devices}
90 Should Be Equal As Integers ${rc1} 0
91
Kailash6f5acb62019-08-28 14:38:45 -070092Validate Device
Gilles Depatieb5682f82019-10-31 10:39:45 -040093 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${serial_number}=${EMPTY} ${device_id}=${EMPTY}
94 ... ${onu_reason}=${EMPTY} ${onu}=False
95 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number} and ${device_id}
Kailash6f5acb62019-08-28 14:38:45 -070096 ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status"
Gilles Depatieb5682f82019-10-31 10:39:45 -040097 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
98 Should Be Equal As Integers ${rc} 0
Kailash6f5acb62019-08-28 14:38:45 -070099 ${jsondata}= To Json ${output}
Kailash6f5acb62019-08-28 14:38:45 -0700100 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700101 FOR ${INDEX} IN RANGE 0 ${length}
102 ${value}= Get From List ${jsondata} ${INDEX}
103 ${astate}= Get From Dictionary ${value} adminstate
104 ${opstatus}= Get From Dictionary ${value} operstatus
105 ${cstatus}= Get From Dictionary ${value} connectstatus
106 ${sn}= Get From Dictionary ${value} serialnumber
Gilles Depatieb5682f82019-10-31 10:39:45 -0400107 ${devId}= Get From Dictionary ${value} id
Zack Williamsec53a1b2019-09-16 15:50:52 -0700108 ${mib_state}= Get From Dictionary ${value} reason
Gilles Depatieb5682f82019-10-31 10:39:45 -0400109 Run Keyword If '${sn}' == '${serial_number}' or '${devId}' == '${device_id}' Exit For Loop
Zack Williamsec53a1b2019-09-16 15:50:52 -0700110 END
Matteo Scandolo5e10b282019-11-25 10:54:32 -0700111 Log ${value}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400112 Should Be Equal '${astate}' '${admin_state}' Device ${serial_number} admin_state != ${admin_state}
Gilles Depatie675a2062019-10-22 12:44:42 -0400113 ... values=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400114 Should Be Equal '${opstatus}' '${oper_status}' Device ${serial_number} oper_status != ${oper_status}
115 ... values=False
116 Should Be Equal '${cstatus}' '${connect_status}' Device ${serial_number} conn_status != ${connect_status}
117 ... values=False
118 Run Keyword If '${onu}' == 'True' Should Be Equal '${mib_state}' '${onu_reason}'
119 ... Device ${serial_number} mib_state incorrect (${mib_state}) values=False
120
121Validate OLT Device
122 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${serial_number}=${EMPTY}
123 ... ${device_id}=${EMPTY}
124 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number} and/or
125 ... ${device_id} Match on OLT Serial number or Device Id and inspect states
126 Validate Device ${admin_state} ${oper_status} ${connect_status} ${serial_number} ${device_id}
127
128Validate ONU Devices
129 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${List_ONU_Serial}
130 [Documentation] Parses the output of "voltctl device list" and inspects device ${List_ONU_Serial}
131 ... Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect
132 ... states including MIB state
133 FOR ${serial_number} IN @{List_ONU_Serial}
134 Validate Device ${admin_state} ${oper_status} ${connect_status} ${serial_number}
135 ... onu_reason=omci-flows-pushed onu=True
136 END
137
138Validate Device Port Types
139 [Arguments] ${device_id} ${pon_type} ${ethernet_type}
140 [Documentation] Parses the output of voltctl device ports <device_id> and matches the port types listed
141 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${device_id} -o json
142 Should Be Equal As Integers ${rc} 0
143 ${jsondata}= To Json ${output}
144 Log ${jsondata}
145 ${length}= Get Length ${jsondata}
146 FOR ${INDEX} IN RANGE 0 ${length}
147 ${value}= Get From List ${jsondata} ${INDEX}
148 ${astate}= Get From Dictionary ${value} adminstate
149 ${opstatus}= Get From Dictionary ${value} operstatus
150 ${type}= Get From Dictionary ${value} type
151 Should Be Equal '${astate}' 'ENABLED' Device ${device_id} port admin_state != ENABLED values=False
152 Should Be Equal '${opstatus}' 'ACTIVE' Device ${device_id} port oper_status != ACTIVE values=False
153 Should Be True '${type}' == '${pon_type}' or '${type}' == '${ethernet_type}'
154 ... Device ${device_id} port type is neither ${pon_type} or ${ethernet_type}
155 END
156
157Validate OLT Port Types
158 [Documentation] Parses the output of voltctl device ports ${olt_device_id} and matches the port types listed
159 [Arguments] ${pon_type} ${ethernet_type}
160 Validate Device Port Types ${olt_device_id} ${pon_type} ${ethernet_type}
161
162Validate ONU Port Types
163 [Arguments] ${List_ONU_Serial} ${pon_type} ${ethernet_type}
164 [Documentation] Parses the output of voltctl device ports for each ONU SN listed in ${List_ONU_Serial}
165 ... and matches the port types listed
166 FOR ${serial_number} IN @{List_ONU_Serial}
167 ${onu_dev_id}= Get Device ID From SN ${serial_number}
168 Validate Device Port Types ${onu_dev_id} ${pon_type} ${ethernet_type}
169 END
170
171Validate Device Flows
172 [Arguments] ${device_id} ${test}=${EMPTY}
173 [Documentation] Parses the output of voltctl device flows <device_id> and expects flow count > 0
174 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id} -o json
175 Should Be Equal As Integers ${rc} 0
176 ${jsondata}= To Json ${output}
177 Log ${jsondata}
178 ${length}= Get Length ${jsondata}
179 Log 'Number of flows = ' ${length}
180 Run Keyword If '${test}' == '${EMPTY}' Should Be True ${length} > 0
181 ... Number of flows for ${device_id} was 0
182 ... ELSE Should Be True ${length} == ${test}
183 ... Number of flows for ${device_id} was not ${test}
184
185Validate OLT Flows
186 [Documentation] Parses the output of voltctl device flows ${olt_device_id} and expects flow count > 0
187 Validate Device Flows ${olt_device_id}
188
189Validate ONU Flows
190 [Arguments] ${List_ONU_Serial} ${test}
191 [Documentation] Parses the output of voltctl device flows for each ONU SN listed in ${List_ONU_Serial}
192 ... and expects flow count == 0
193 FOR ${serial_number} IN @{List_ONU_Serial}
194 ${onu_dev_id}= Get Device ID From SN ${serial_number}
195 Validate Device Flows ${onu_dev_id} ${test}
196 END
197
198Validate Logical Device
199 [Documentation] Validate Logical Device is listed
200 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
201 Should Be Equal As Integers ${rc} 0
202 ${jsondata}= To Json ${output}
203 Log ${jsondata}
204 ${length}= Get Length ${jsondata}
205 FOR ${INDEX} IN RANGE 0 ${length}
206 ${value}= Get From List ${jsondata} ${INDEX}
207 ${devid}= Get From Dictionary ${value} id
208 ${rootdev}= Get From Dictionary ${value} rootdeviceid
209 ${sn}= Get From Dictionary ${value} serialnumber
210 Exit For Loop
211 END
212 Should Be Equal '${rootdev}' '${olt_device_id}' Root Device does not match ${olt_device_id} values=False
213 Should Be Equal '${sn}' '${BBSIM_OLT_SN}' Logical Device ${sn} does not match ${BBSIM_OLT_SN}
214 ... values=False
215 [Return] ${devid}
216
217Validate Logical Device Ports
218 [Arguments] ${logical_device_id}
219 [Documentation] Validate Logical Device Ports are listed and are > 0
220 ${rc} ${output}= Run and Return Rc and Output
221 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice ports ${logical_device_id} -o json
222 Should Be Equal As Integers ${rc} 0
223 ${jsondata}= To Json ${output}
224 Log ${jsondata}
225 ${length}= Get Length ${jsondata}
226 Should Be True ${length} > 0 Number of ports for ${logical_device_id} was 0
227
228Validate Logical Device Flows
229 [Arguments] ${logical_device_id}
230 [Documentation] Validate Logical Device Flows are listed and are > 0
231 ${rc} ${output}= Run and Return Rc and Output
232 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${logical_device_id} -o json
233 Should Be Equal As Integers ${rc} 0
234 ${jsondata}= To Json ${output}
235 Log ${jsondata}
236 ${length}= Get Length ${jsondata}
237 Should Be True ${length} > 0 Number of flows for ${logical_device_id} was 0
238
239Retrieve Peer List From OLT
240 [Arguments] ${olt_peer_list}
241 [Documentation] Retrieve the list of peer device id list from port list
242 ${rc} ${output}= Run and Return Rc and Output
243 ... ${VOLTCTL_CONFIG}; voltctl device ports ${olt_device_id} -o json
244 Should Be Equal As Integers ${rc} 0
245 ${jsondata}= To Json ${output}
246 Log ${jsondata}
247 ${length}= Get Length ${jsondata}
248 FOR ${INDEX} IN RANGE 0 ${length}
249 ${value}= Get From List ${jsondata} ${INDEX}
250 ${type}= Get From Dictionary ${value} type
251 ${peers}= Get From Dictionary ${value} peers
252 Run Keyword If '${type}' == 'PON_OLT' Exit For Loop
253 END
254 ${length}= Get Length ${peers}
255 FOR ${INDEX} IN RANGE 0 ${length}
256 ${value}= Get From List ${peers} ${INDEX}
257 ${peer_id}= Get From Dictionary ${value} deviceid
258 Append To List ${olt_peer_list} ${peer_id}
259 END
260
261Validate OLT Peer Id List
262 [Arguments] ${olt_peer_id_list}
263 [Documentation] Match each entry in the ${olt_peer_id_list} against ONU device ids.
264 FOR ${peer_id} IN @{olt_peer_id_list}
265 Match OLT Peer Id ${peer_id}
266 END
267
268Match OLT Peer Id
269 [Arguments] ${olt_peer_id}
270 [Documentation] Lookup the OLT Peer Id in against the list of ONU device Ids
271 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
272 Should Be Equal As Integers ${rc} 0
273 ${jsondata}= To Json ${output}
274 Log ${jsondata}
275 ${length}= Get Length ${jsondata}
276 FOR ${INDEX} IN RANGE 0 ${length}
277 ${value}= Get From List ${jsondata} ${INDEX}
278 ${devid}= Get From Dictionary ${value} id
279 Run Keyword If '${devid}' == '${olt_peer_id}' Exit For Loop
280 Run Keyword If '${INDEX}' == '${length}' Fail Peer id ${olt_peer_id} does not match any ONU device id;
281 END
282
283Validate ONU Peer Id
284 [Arguments] ${olt_device_id} ${List_ONU_Serial}
285 [Documentation] Match each ONU peer to that of the OLT device id
286 FOR ${onu_serial} IN @{List_ONU_Serial}
287 ${onu_dev_id}= Get Device ID From SN ${onu_serial}
288 Match ONU Peer Id ${onu_dev_id}
289 END
290
291Match ONU Peer Id
292 [Arguments] ${onu_dev_id}
293 [Documentation] Match an ONU peer to that of the OLT device id
294 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${onu_dev_id} -o json
295 Should Be Equal As Integers ${rc} 0
296 ${jsondata}= To Json ${output}
297 Log ${jsondata}
298 ${length}= Get Length ${jsondata}
299 FOR ${INDEX} IN RANGE 0 ${length}
300 ${value}= Get From List ${jsondata} ${INDEX}
301 ${type}= Get From Dictionary ${value} type
302 ${peers}= Get From Dictionary ${value} peers
303 Run Keyword If '${type}' == 'PON_ONU' Exit For Loop
304 END
305 ${length}= Get Length ${peers}
306 FOR ${INDEX} IN RANGE 0 ${length}
307 ${value}= Get From List ${peers} ${INDEX}
308 ${peer_id}= Get From Dictionary ${value} deviceid
309 END
310 Should Be Equal '${peer_id}' '${olt_device_id}'
311 ... Mismatch between ONU peer ${peer_id} and OLT device id ${olt_device_id} values=False
Kailash6f5acb62019-08-28 14:38:45 -0700312
Kailash6f5acb62019-08-28 14:38:45 -0700313Get Device ID From SN
314 [Arguments] ${serial_number}
315 [Documentation] Gets the device id by matching for ${serial_number}
316 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
317 ${jsondata}= To Json ${output}
318 Log ${jsondata}
319 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700320 FOR ${INDEX} IN RANGE 0 ${length}
321 ${value}= Get From List ${jsondata} ${INDEX}
322 ${id}= Get From Dictionary ${value} id
323 ${sn}= Get From Dictionary ${value} serialnumber
324 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
325 END
Kailash6f5acb62019-08-28 14:38:45 -0700326 [Return] ${id}
327
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700328Get Logical Device ID From SN
329 [Arguments] ${serial_number}
330 [Documentation] Gets the device id by matching for ${serial_number}
331 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
332 ${jsondata}= To Json ${output}
333 Log ${jsondata}
334 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700335 FOR ${INDEX} IN RANGE 0 ${length}
336 ${value}= Get From List ${jsondata} ${INDEX}
337 ${id}= Get From Dictionary ${value} parentid
338 ${sn}= Get From Dictionary ${value} serialnumber
339 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
340 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700341 [Return] ${id}
342
Gilles Depatieb5682f82019-10-31 10:39:45 -0400343Build ONU SN List
344 [Arguments] ${serial_numbers}
345 [Documentation] Appends all ONU SNs to the ${serial_numbers} list
346 FOR ${INDEX} IN RANGE 0 ${num_onus}
347 Append To List ${serial_numbers} ${hosts.src[${INDEX}].onu}
348 END
349
350Get SN From Device ID
351 [Arguments] ${device_id}
352 [Documentation] Gets the device id by matching for ${device_id}
353 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
354 Should Be Equal As Integers ${rc} 0
355 ${jsondata}= To Json ${output}
356 Log ${jsondata}
357 ${length}= Get Length ${jsondata}
358 FOR ${INDEX} IN RANGE 0 ${length}
359 ${value}= Get From List ${jsondata} ${INDEX}
360 ${id}= Get From Dictionary ${value} id
361 ${sn}= Get From Dictionary ${value} serialnumber
362 Run Keyword If '${id}' == '${device_id}' Exit For Loop
363 END
364 [Return] ${sn}
365
Kailash6f5acb62019-08-28 14:38:45 -0700366Validate Device Removed
367 [Arguments] ${id}
368 [Documentation] Verifys that device, ${serial_number}, has been removed
369 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
370 ${jsondata}= To Json ${output}
371 Log ${jsondata}
372 ${length}= Get Length ${jsondata}
373 @{ids}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -0700374 FOR ${INDEX} IN RANGE 0 ${length}
375 ${value}= Get From List ${jsondata} ${INDEX}
376 ${device_id}= Get From Dictionary ${value} id
377 Append To List ${ids} ${device_id}
378 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700379 List Should Not Contain Value ${ids} ${id}