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