blob: ba1313e85420ae229eaa4ecc4204611b3401c94e [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
Kailash6f5acb62019-08-28 14:38:45 -070086Validate Device
Gilles Depatieb5682f82019-10-31 10:39:45 -040087 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${serial_number}=${EMPTY} ${device_id}=${EMPTY}
88 ... ${onu_reason}=${EMPTY} ${onu}=False
89 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number} and ${device_id}
Kailash6f5acb62019-08-28 14:38:45 -070090 ... Arguments are matched for device states of: "admin_state", "oper_status", and "connect_status"
Gilles Depatieb5682f82019-10-31 10:39:45 -040091 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
92 Should Be Equal As Integers ${rc} 0
Kailash6f5acb62019-08-28 14:38:45 -070093 ${jsondata}= To Json ${output}
Kailash6f5acb62019-08-28 14:38:45 -070094 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -070095 FOR ${INDEX} IN RANGE 0 ${length}
96 ${value}= Get From List ${jsondata} ${INDEX}
97 ${astate}= Get From Dictionary ${value} adminstate
98 ${opstatus}= Get From Dictionary ${value} operstatus
99 ${cstatus}= Get From Dictionary ${value} connectstatus
100 ${sn}= Get From Dictionary ${value} serialnumber
Gilles Depatieb5682f82019-10-31 10:39:45 -0400101 ${devId}= Get From Dictionary ${value} id
Zack Williamsec53a1b2019-09-16 15:50:52 -0700102 ${mib_state}= Get From Dictionary ${value} reason
Gilles Depatieb5682f82019-10-31 10:39:45 -0400103 Run Keyword If '${sn}' == '${serial_number}' or '${devId}' == '${device_id}' Exit For Loop
Zack Williamsec53a1b2019-09-16 15:50:52 -0700104 END
Matteo Scandolo5e10b282019-11-25 10:54:32 -0700105 Log ${value}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400106 Should Be Equal '${astate}' '${admin_state}' Device ${serial_number} admin_state != ${admin_state}
Gilles Depatie675a2062019-10-22 12:44:42 -0400107 ... values=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400108 Should Be Equal '${opstatus}' '${oper_status}' Device ${serial_number} oper_status != ${oper_status}
109 ... values=False
110 Should Be Equal '${cstatus}' '${connect_status}' Device ${serial_number} conn_status != ${connect_status}
111 ... values=False
112 Run Keyword If '${onu}' == 'True' Should Be Equal '${mib_state}' '${onu_reason}'
113 ... Device ${serial_number} mib_state incorrect (${mib_state}) values=False
114
115Validate OLT Device
116 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${serial_number}=${EMPTY}
117 ... ${device_id}=${EMPTY}
118 [Documentation] Parses the output of "voltctl device list" and inspects device ${serial_number} and/or
119 ... ${device_id} Match on OLT Serial number or Device Id and inspect states
120 Validate Device ${admin_state} ${oper_status} ${connect_status} ${serial_number} ${device_id}
121
122Validate ONU Devices
123 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${List_ONU_Serial}
124 [Documentation] Parses the output of "voltctl device list" and inspects device ${List_ONU_Serial}
125 ... Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect
126 ... states including MIB state
127 FOR ${serial_number} IN @{List_ONU_Serial}
128 Validate Device ${admin_state} ${oper_status} ${connect_status} ${serial_number}
129 ... onu_reason=omci-flows-pushed onu=True
130 END
131
132Validate Device Port Types
133 [Arguments] ${device_id} ${pon_type} ${ethernet_type}
134 [Documentation] Parses the output of voltctl device ports <device_id> and matches the port types listed
135 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${device_id} -o json
136 Should Be Equal As Integers ${rc} 0
137 ${jsondata}= To Json ${output}
138 Log ${jsondata}
139 ${length}= Get Length ${jsondata}
140 FOR ${INDEX} IN RANGE 0 ${length}
141 ${value}= Get From List ${jsondata} ${INDEX}
142 ${astate}= Get From Dictionary ${value} adminstate
143 ${opstatus}= Get From Dictionary ${value} operstatus
144 ${type}= Get From Dictionary ${value} type
145 Should Be Equal '${astate}' 'ENABLED' Device ${device_id} port admin_state != ENABLED values=False
146 Should Be Equal '${opstatus}' 'ACTIVE' Device ${device_id} port oper_status != ACTIVE values=False
147 Should Be True '${type}' == '${pon_type}' or '${type}' == '${ethernet_type}'
148 ... Device ${device_id} port type is neither ${pon_type} or ${ethernet_type}
149 END
150
151Validate OLT Port Types
152 [Documentation] Parses the output of voltctl device ports ${olt_device_id} and matches the port types listed
153 [Arguments] ${pon_type} ${ethernet_type}
154 Validate Device Port Types ${olt_device_id} ${pon_type} ${ethernet_type}
155
156Validate ONU Port Types
157 [Arguments] ${List_ONU_Serial} ${pon_type} ${ethernet_type}
158 [Documentation] Parses the output of voltctl device ports for each ONU SN listed in ${List_ONU_Serial}
159 ... and matches the port types listed
160 FOR ${serial_number} IN @{List_ONU_Serial}
161 ${onu_dev_id}= Get Device ID From SN ${serial_number}
162 Validate Device Port Types ${onu_dev_id} ${pon_type} ${ethernet_type}
163 END
164
165Validate Device Flows
166 [Arguments] ${device_id} ${test}=${EMPTY}
167 [Documentation] Parses the output of voltctl device flows <device_id> and expects flow count > 0
168 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id} -o json
169 Should Be Equal As Integers ${rc} 0
170 ${jsondata}= To Json ${output}
171 Log ${jsondata}
172 ${length}= Get Length ${jsondata}
173 Log 'Number of flows = ' ${length}
174 Run Keyword If '${test}' == '${EMPTY}' Should Be True ${length} > 0
175 ... Number of flows for ${device_id} was 0
176 ... ELSE Should Be True ${length} == ${test}
177 ... Number of flows for ${device_id} was not ${test}
178
179Validate OLT Flows
180 [Documentation] Parses the output of voltctl device flows ${olt_device_id} and expects flow count > 0
181 Validate Device Flows ${olt_device_id}
182
183Validate ONU Flows
184 [Arguments] ${List_ONU_Serial} ${test}
185 [Documentation] Parses the output of voltctl device flows for each ONU SN listed in ${List_ONU_Serial}
186 ... and expects flow count == 0
187 FOR ${serial_number} IN @{List_ONU_Serial}
188 ${onu_dev_id}= Get Device ID From SN ${serial_number}
189 Validate Device Flows ${onu_dev_id} ${test}
190 END
191
192Validate Logical Device
193 [Documentation] Validate Logical Device is listed
194 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
195 Should Be Equal As Integers ${rc} 0
196 ${jsondata}= To Json ${output}
197 Log ${jsondata}
198 ${length}= Get Length ${jsondata}
199 FOR ${INDEX} IN RANGE 0 ${length}
200 ${value}= Get From List ${jsondata} ${INDEX}
201 ${devid}= Get From Dictionary ${value} id
202 ${rootdev}= Get From Dictionary ${value} rootdeviceid
203 ${sn}= Get From Dictionary ${value} serialnumber
204 Exit For Loop
205 END
206 Should Be Equal '${rootdev}' '${olt_device_id}' Root Device does not match ${olt_device_id} values=False
207 Should Be Equal '${sn}' '${BBSIM_OLT_SN}' Logical Device ${sn} does not match ${BBSIM_OLT_SN}
208 ... values=False
209 [Return] ${devid}
210
211Validate Logical Device Ports
212 [Arguments] ${logical_device_id}
213 [Documentation] Validate Logical Device Ports are listed and are > 0
214 ${rc} ${output}= Run and Return Rc and Output
215 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice ports ${logical_device_id} -o json
216 Should Be Equal As Integers ${rc} 0
217 ${jsondata}= To Json ${output}
218 Log ${jsondata}
219 ${length}= Get Length ${jsondata}
220 Should Be True ${length} > 0 Number of ports for ${logical_device_id} was 0
221
222Validate Logical Device Flows
223 [Arguments] ${logical_device_id}
224 [Documentation] Validate Logical Device Flows are listed and are > 0
225 ${rc} ${output}= Run and Return Rc and Output
226 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${logical_device_id} -o json
227 Should Be Equal As Integers ${rc} 0
228 ${jsondata}= To Json ${output}
229 Log ${jsondata}
230 ${length}= Get Length ${jsondata}
231 Should Be True ${length} > 0 Number of flows for ${logical_device_id} was 0
232
233Retrieve Peer List From OLT
234 [Arguments] ${olt_peer_list}
235 [Documentation] Retrieve the list of peer device id list from port list
236 ${rc} ${output}= Run and Return Rc and Output
237 ... ${VOLTCTL_CONFIG}; voltctl device ports ${olt_device_id} -o json
238 Should Be Equal As Integers ${rc} 0
239 ${jsondata}= To Json ${output}
240 Log ${jsondata}
241 ${length}= Get Length ${jsondata}
242 FOR ${INDEX} IN RANGE 0 ${length}
243 ${value}= Get From List ${jsondata} ${INDEX}
244 ${type}= Get From Dictionary ${value} type
245 ${peers}= Get From Dictionary ${value} peers
246 Run Keyword If '${type}' == 'PON_OLT' Exit For Loop
247 END
248 ${length}= Get Length ${peers}
249 FOR ${INDEX} IN RANGE 0 ${length}
250 ${value}= Get From List ${peers} ${INDEX}
251 ${peer_id}= Get From Dictionary ${value} deviceid
252 Append To List ${olt_peer_list} ${peer_id}
253 END
254
255Validate OLT Peer Id List
256 [Arguments] ${olt_peer_id_list}
257 [Documentation] Match each entry in the ${olt_peer_id_list} against ONU device ids.
258 FOR ${peer_id} IN @{olt_peer_id_list}
259 Match OLT Peer Id ${peer_id}
260 END
261
262Match OLT Peer Id
263 [Arguments] ${olt_peer_id}
264 [Documentation] Lookup the OLT Peer Id in against the list of ONU device Ids
265 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
266 Should Be Equal As Integers ${rc} 0
267 ${jsondata}= To Json ${output}
268 Log ${jsondata}
269 ${length}= Get Length ${jsondata}
270 FOR ${INDEX} IN RANGE 0 ${length}
271 ${value}= Get From List ${jsondata} ${INDEX}
272 ${devid}= Get From Dictionary ${value} id
273 Run Keyword If '${devid}' == '${olt_peer_id}' Exit For Loop
274 Run Keyword If '${INDEX}' == '${length}' Fail Peer id ${olt_peer_id} does not match any ONU device id;
275 END
276
277Validate ONU Peer Id
278 [Arguments] ${olt_device_id} ${List_ONU_Serial}
279 [Documentation] Match each ONU peer to that of the OLT device id
280 FOR ${onu_serial} IN @{List_ONU_Serial}
281 ${onu_dev_id}= Get Device ID From SN ${onu_serial}
282 Match ONU Peer Id ${onu_dev_id}
283 END
284
285Match ONU Peer Id
286 [Arguments] ${onu_dev_id}
287 [Documentation] Match an ONU peer to that of the OLT device id
288 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device ports ${onu_dev_id} -o json
289 Should Be Equal As Integers ${rc} 0
290 ${jsondata}= To Json ${output}
291 Log ${jsondata}
292 ${length}= Get Length ${jsondata}
293 FOR ${INDEX} IN RANGE 0 ${length}
294 ${value}= Get From List ${jsondata} ${INDEX}
295 ${type}= Get From Dictionary ${value} type
296 ${peers}= Get From Dictionary ${value} peers
297 Run Keyword If '${type}' == 'PON_ONU' Exit For Loop
298 END
299 ${length}= Get Length ${peers}
300 FOR ${INDEX} IN RANGE 0 ${length}
301 ${value}= Get From List ${peers} ${INDEX}
302 ${peer_id}= Get From Dictionary ${value} deviceid
303 END
304 Should Be Equal '${peer_id}' '${olt_device_id}'
305 ... Mismatch between ONU peer ${peer_id} and OLT device id ${olt_device_id} values=False
Kailash6f5acb62019-08-28 14:38:45 -0700306
Kailash6f5acb62019-08-28 14:38:45 -0700307Get Device ID From SN
308 [Arguments] ${serial_number}
309 [Documentation] Gets the device id by matching for ${serial_number}
310 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
311 ${jsondata}= To Json ${output}
312 Log ${jsondata}
313 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700314 FOR ${INDEX} IN RANGE 0 ${length}
315 ${value}= Get From List ${jsondata} ${INDEX}
316 ${id}= Get From Dictionary ${value} id
317 ${sn}= Get From Dictionary ${value} serialnumber
318 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
319 END
Kailash6f5acb62019-08-28 14:38:45 -0700320 [Return] ${id}
321
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700322Get Logical Device ID From SN
323 [Arguments] ${serial_number}
324 [Documentation] Gets the device id by matching for ${serial_number}
325 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
326 ${jsondata}= To Json ${output}
327 Log ${jsondata}
328 ${length}= Get Length ${jsondata}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700329 FOR ${INDEX} IN RANGE 0 ${length}
330 ${value}= Get From List ${jsondata} ${INDEX}
331 ${id}= Get From Dictionary ${value} parentid
332 ${sn}= Get From Dictionary ${value} serialnumber
333 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
334 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700335 [Return] ${id}
336
Gilles Depatieb5682f82019-10-31 10:39:45 -0400337Build ONU SN List
338 [Arguments] ${serial_numbers}
339 [Documentation] Appends all ONU SNs to the ${serial_numbers} list
340 FOR ${INDEX} IN RANGE 0 ${num_onus}
341 Append To List ${serial_numbers} ${hosts.src[${INDEX}].onu}
342 END
343
344Get SN From Device ID
345 [Arguments] ${device_id}
346 [Documentation] Gets the device id by matching for ${device_id}
347 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
348 Should Be Equal As Integers ${rc} 0
349 ${jsondata}= To Json ${output}
350 Log ${jsondata}
351 ${length}= Get Length ${jsondata}
352 FOR ${INDEX} IN RANGE 0 ${length}
353 ${value}= Get From List ${jsondata} ${INDEX}
354 ${id}= Get From Dictionary ${value} id
355 ${sn}= Get From Dictionary ${value} serialnumber
356 Run Keyword If '${id}' == '${device_id}' Exit For Loop
357 END
358 [Return] ${sn}
359
Kailash6f5acb62019-08-28 14:38:45 -0700360Validate Device Removed
361 [Arguments] ${id}
362 [Documentation] Verifys that device, ${serial_number}, has been removed
363 ${output}= Run ${VOLTCTL_CONFIG}; voltctl device list -o json
364 ${jsondata}= To Json ${output}
365 Log ${jsondata}
366 ${length}= Get Length ${jsondata}
367 @{ids}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -0700368 FOR ${INDEX} IN RANGE 0 ${length}
369 ${value}= Get From List ${jsondata} ${INDEX}
370 ${device_id}= Get From Dictionary ${value} id
371 Append To List ${ids} ${device_id}
372 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700373 List Should Not Contain Value ${ids} ${id}