blob: 0051e288d6415e4383e5633cf8966bb7c5b477d5 [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.
Kailash6f5acb62019-08-28 14:38:45 -070014# voltctl common functions
15
16*** Settings ***
17Documentation Library for various utilities
18Library SSHLibrary
Kailash6f5acb62019-08-28 14:38:45 -070019Library String
20Library DateTime
21Library Process
22Library Collections
23Library RequestsLibrary
24Library OperatingSystem
25
26*** Keywords ***
Gilles Depatieb5682f82019-10-31 10:39:45 -040027Test Empty Device List
Zack Williamsa8fe75a2020-01-10 14:25:27 -070028 [Documentation] Verify that there are no devices in the system
29 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -040030 Should Be Equal As Integers ${rc} 0
31 ${jsondata}= To Json ${output}
32 Log ${jsondata}
33 ${length}= Get Length ${jsondata}
David Bainbridgef81cd642019-11-20 00:14:47 +000034 Should Be Equal As Integers ${length} 0
Gilles Depatieb5682f82019-10-31 10:39:45 -040035
Kailash6f5acb62019-08-28 14:38:45 -070036Create Device
37 [Arguments] ${ip} ${port}
You Wang2b550642019-10-07 14:39:48 -070038 [Documentation] Creates a device in VOLTHA
Kailash6f5acb62019-08-28 14:38:45 -070039 #create/preprovision device
Gilles Depatie675a2062019-10-22 12:44:42 -040040 ${rc} ${device_id}= Run and Return Rc and Output
41 ... ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${ip}:${port}
Kailash6f5acb62019-08-28 14:38:45 -070042 Should Be Equal As Integers ${rc} 0
43 [Return] ${device_id}
44
45Enable Device
46 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -070047 [Documentation] Enables a device in VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -070048 ${rc} ${output}= Run and Return Rc and Output
49 ... ${VOLTCTL_CONFIG}; voltctl device enable ${device_id}
Kailash6f5acb62019-08-28 14:38:45 -070050 Should Be Equal As Integers ${rc} 0
51
Suchitra Vemuri6db89412019-11-14 14:52:54 -080052Disable Device
53 [Arguments] ${device_id}
Hardik Windlassaaea3402020-03-10 19:45:45 +053054 [Documentation] Disables a device in VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -070055 ${rc} ${output}= Run and Return Rc and Output
56 ... ${VOLTCTL_CONFIG}; voltctl device disable ${device_id}
Suchitra Vemuri6db89412019-11-14 14:52:54 -080057 Should Be Equal As Integers ${rc} 0
58
Hardik Windlassaaea3402020-03-10 19:45:45 +053059Delete Device
60 [Arguments] ${device_id}
61 [Documentation] Deletes a device in VOLTHA
62 ${rc} ${output}= Run and Return Rc and Output
63 ... ${VOLTCTL_CONFIG}; voltctl device delete ${device_id}
64 Should Be Equal As Integers ${rc} 0
65
Hemadf003682020-04-28 21:22:22 +053066Reboot Device
67 [Arguments] ${device_id}
68 [Documentation] Reboot the OLT using voltctl command
69 ${rc} ${output}= Run and Return Rc and Output
70 ... ${VOLTCTL_CONFIG}; voltctl device reboot ${device_id}
71 Should Be Equal As Integers ${rc} 0
72
David Bainbridgef81cd642019-11-20 00:14:47 +000073Disable Devices In Voltha
74 [Documentation] Disables all the known devices in voltha
75 [Arguments] ${filter}
76 ${arg}= Set Variable ${EMPTY}
77 ${arg}= Run Keyword If len('${filter}'.strip()) != 0 Set Variable --filter ${filter}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070078 ${rc} ${devices}= Run and Return Rc and Output
79 ... ${VOLTCTL_CONFIG}; voltctl device list ${arg} --orderby Root -q | xargs echo -n
David Bainbridgef81cd642019-11-20 00:14:47 +000080 Should Be Equal As Integers ${rc} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -070081 ${rc} ${output}= Run Keyword If len('${devices}') != 0 Run and Return Rc and Output
82 ... ${VOLTCTL_CONFIG}; voltctl device disable ${devices}
David Bainbridgef81cd642019-11-20 00:14:47 +000083 Run Keyword If len('${devices}') != 0 Should Be Equal As Integers ${rc} 0
84
85Test Devices Disabled In Voltha
86 [Documentation] Tests to verify that all devices in VOLTHA are disabled
87 [Arguments] ${filter}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070088 ${rc} ${count}= Run and Return Rc and Output
89 ... ${VOLTCTL_CONFIG}; voltctl device list --filter '${filter},AdminState!=DISABLED' -q | wc -l
David Bainbridgef81cd642019-11-20 00:14:47 +000090 Should Be Equal As Integers ${rc} 0
91 Should Be Equal As Integers ${count} 0
92
93Delete Devices In Voltha
94 [Documentation] Disables all the known devices in voltha
95 [Arguments] ${filter}
96 ${arg}= Set Variable ${EMPTY}
97 ${arg}= Run Keyword If len('${filter}'.strip()) != 0 Set Variable --filter ${filter}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070098 ${rc} ${devices}= Run and Return Rc and Output
99 ... ${VOLTCTL_CONFIG}; voltctl device list ${arg} --orderby Root -q | xargs echo -n
David Bainbridgef81cd642019-11-20 00:14:47 +0000100 Should Be Equal As Integers ${rc} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700101 ${rc} ${output}= Run Keyword If len('${devices}') != 0 Run and Return Rc and Output
102 ... ${VOLTCTL_CONFIG}; voltctl device delete ${devices}
David Bainbridgef81cd642019-11-20 00:14:47 +0000103 Run Keyword If len('${devices}') != 0 Should Be Equal As Integers ${rc} 0
104
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700105Get Device Flows from Voltha
106 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700107 [Documentation] Gets device flows from VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700108 ${rc} ${output}= Run and Return Rc and Output
109 ... ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700110 Should Be Equal As Integers ${rc} 0
111 [Return] ${output}
112
113Get Logical Device Output from Voltha
114 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700115 [Documentation] Gets logicaldevice flows and ports from VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700116 ${rc1} ${flows}= Run and Return Rc and Output
117 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device_id}
118 ${rc2} ${ports}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800119 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice port list ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700120 Log ${flows}
121 Log ${ports}
122 Should Be Equal As Integers ${rc1} 0
123 Should Be Equal As Integers ${rc2} 0
124
125Get Device Output from Voltha
126 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700127 [Documentation] Gets device flows and ports from VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700128 ${rc1} ${flows}= Run and Return Rc and Output
129 ... ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
130 ${rc2} ${ports}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800131 ... ${VOLTCTL_CONFIG}; voltctl device port list ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700132 Log ${flows}
133 Log ${ports}
134 Should Be Equal As Integers ${rc1} 0
135 Should Be Equal As Integers ${rc2} 0
136
Suchitra Vemuri1a970a62019-11-26 12:52:16 -0800137Get Device List from Voltha
138 [Documentation] Gets Device List Output from Voltha
139 ${rc1} ${devices}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list
140 Log ${devices}
141 Should Be Equal As Integers ${rc1} 0
142
Kailash6f5acb62019-08-28 14:38:45 -0700143Validate Device
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700144 [Documentation]
ubuntu6b6e7d42020-03-02 12:35:42 -0800145 ... Parses the output of "voltctl device list" and inspects a device ${id}, specified as either
146 ... the serial number or device ID. Arguments are matched for device states of: "admin_state",
147 ... "oper_status", and "connect_status"
148 [Arguments] ${admin_state} ${oper_status} ${connect_status}
149 ... ${id}=${EMPTY} ${onu_reason}=${EMPTY} ${onu}=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400150 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
151 Should Be Equal As Integers ${rc} 0
Kailash6f5acb62019-08-28 14:38:45 -0700152 ${jsondata}= To Json ${output}
Kailash6f5acb62019-08-28 14:38:45 -0700153 ${length}= Get Length ${jsondata}
ubuntu6b6e7d42020-03-02 12:35:42 -0800154 ${matched}= Set Variable False
Zack Williamsec53a1b2019-09-16 15:50:52 -0700155 FOR ${INDEX} IN RANGE 0 ${length}
156 ${value}= Get From List ${jsondata} ${INDEX}
157 ${astate}= Get From Dictionary ${value} adminstate
158 ${opstatus}= Get From Dictionary ${value} operstatus
159 ${cstatus}= Get From Dictionary ${value} connectstatus
160 ${sn}= Get From Dictionary ${value} serialnumber
Gilles Depatieb5682f82019-10-31 10:39:45 -0400161 ${devId}= Get From Dictionary ${value} id
Zack Williamsec53a1b2019-09-16 15:50:52 -0700162 ${mib_state}= Get From Dictionary ${value} reason
ubuntu6b6e7d42020-03-02 12:35:42 -0800163 ${matched}= Set Variable If '${sn}' == '${id}' or '${devId}' == '${id}' True False
Andy Bavierb63f6d22020-03-12 15:34:37 -0700164 Exit For Loop If ${matched}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700165 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700166 Should Be True ${matched} No match found for ${id} to validate device
Matteo Scandolo5e10b282019-11-25 10:54:32 -0700167 Log ${value}
ubuntu6b6e7d42020-03-02 12:35:42 -0800168 Should Be Equal '${astate}' '${admin_state}' Device ${sn} admin_state != ${admin_state}
Gilles Depatie675a2062019-10-22 12:44:42 -0400169 ... values=False
ubuntu6b6e7d42020-03-02 12:35:42 -0800170 Should Be Equal '${opstatus}' '${oper_status}' Device ${sn} oper_status != ${oper_status}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400171 ... values=False
ubuntu6b6e7d42020-03-02 12:35:42 -0800172 Should Be Equal '${cstatus}' '${connect_status}' Device ${sn} conn_status != ${connect_status}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400173 ... values=False
174 Run Keyword If '${onu}' == 'True' Should Be Equal '${mib_state}' '${onu_reason}'
ubuntu6b6e7d42020-03-02 12:35:42 -0800175 ... Device ${sn} mib_state incorrect (${mib_state}) values=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400176
177Validate OLT Device
ubuntu6b6e7d42020-03-02 12:35:42 -0800178 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${id}=${EMPTY}
179 [Documentation] Parses the output of "voltctl device list" and inspects device ${id}, specified
180 ... as either its serial numbner or device ID. Match on OLT Serial number or Device Id and inspect states
181 Validate Device ${admin_state} ${oper_status} ${connect_status} ${id}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400182
183Validate ONU Devices
184 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${List_ONU_Serial}
Andy Bavierf1f26ed2020-03-18 10:59:07 -0700185 ... ${onu_reason}=omci-flows-pushed
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700186 [Documentation] Parses the output of "voltctl device list" and inspects device ${List_ONU_Serial}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400187 ... Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect
188 ... states including MIB state
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700189 FOR ${serial_number} IN @{List_ONU_Serial}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400190 Validate Device ${admin_state} ${oper_status} ${connect_status} ${serial_number}
Andy Bavierf1f26ed2020-03-18 10:59:07 -0700191 ... onu_reason=${onu_reason} onu=True
Debasish28130d02020-03-16 11:05:26 +0000192 END
193
Gilles Depatieb5682f82019-10-31 10:39:45 -0400194Validate Device Port Types
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700195 [Documentation]
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800196 ... Parses the output of voltctl device port list <device_id> and matches the port types listed
Andy Bavier90eb1a12020-03-26 11:54:35 -0700197 [Arguments] ${device_id} ${pon_type} ${ethernet_type} ${all_active}=True
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700198 ${rc} ${output}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800199 ... ${VOLTCTL_CONFIG}; voltctl device port list ${device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400200 Should Be Equal As Integers ${rc} 0
201 ${jsondata}= To Json ${output}
202 Log ${jsondata}
203 ${length}= Get Length ${jsondata}
204 FOR ${INDEX} IN RANGE 0 ${length}
205 ${value}= Get From List ${jsondata} ${INDEX}
206 ${astate}= Get From Dictionary ${value} adminstate
207 ${opstatus}= Get From Dictionary ${value} operstatus
208 ${type}= Get From Dictionary ${value} type
Hemaf64d34c2020-03-25 00:40:17 +0530209 Should Be Equal '${astate}' 'ENABLED' Device ${device_id} port admin_state != ENABLED values=False
Andy Bavier90eb1a12020-03-26 11:54:35 -0700210 Run Keyword If ${all_active} Should Be Equal '${opstatus}' 'ACTIVE'
211 ... Device ${device_id} port oper_status != ACTIVE values=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400212 Should Be True '${type}' == '${pon_type}' or '${type}' == '${ethernet_type}'
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700213 ... Device ${device_id} port type is neither ${pon_type} or ${ethernet_type}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400214 END
215
216Validate OLT Port Types
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800217 [Documentation] Parses the output of voltctl device port list ${olt_device_id} and matches the port types listed
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700218 [Arguments] ${pon_type} ${ethernet_type}
219 Validate Device Port Types ${olt_device_id} ${pon_type} ${ethernet_type}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400220
221Validate ONU Port Types
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700222 [Arguments] ${List_ONU_Serial} ${pon_type} ${ethernet_type}
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800223 [Documentation] Parses the output of voltctl device port list for each ONU SN listed in ${List_ONU_Serial}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700224 ... and matches the port types listed
Gilles Depatieb5682f82019-10-31 10:39:45 -0400225 FOR ${serial_number} IN @{List_ONU_Serial}
226 ${onu_dev_id}= Get Device ID From SN ${serial_number}
Andy Bavier90eb1a12020-03-26 11:54:35 -0700227 # Only first UNI port is ACTIVE; the rest are in DISCOVERED operstatus
228 Validate Device Port Types ${onu_dev_id} ${pon_type} ${ethernet_type} all_active=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400229 END
230
231Validate Device Flows
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000232 [Arguments] ${device_id} ${flow_count}=${EMPTY}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400233 [Documentation] Parses the output of voltctl device flows <device_id> and expects flow count > 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700234 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400235 Should Be Equal As Integers ${rc} 0
236 ${jsondata}= To Json ${output}
237 Log ${jsondata}
238 ${length}= Get Length ${jsondata}
239 Log 'Number of flows = ' ${length}
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000240 Run Keyword If '${flow_count}' == '${EMPTY}' Should Be True ${length} > 0
Gilles Depatieb5682f82019-10-31 10:39:45 -0400241 ... Number of flows for ${device_id} was 0
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000242 ... ELSE Should Be True ${length} == ${flow_count}
243 ... Number of flows for ${device_id} was not ${flow_count}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400244
245Validate OLT Flows
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000246 [Arguments] ${flow_count}=${EMPTY}
247 [Documentation] Parses the output of voltctl device flows ${olt_device_id}
248 ... and expects flow count == ${flow_count}
249 Validate Device Flows ${olt_device_id} ${flow_count}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400250
251Validate ONU Flows
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000252 [Arguments] ${List_ONU_Serial} ${flow_count}=${EMPTY}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400253 [Documentation] Parses the output of voltctl device flows for each ONU SN listed in ${List_ONU_Serial}
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000254 ... and expects flow count == ${flow_count}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700255 FOR ${serial_number} IN @{List_ONU_Serial}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400256 ${onu_dev_id}= Get Device ID From SN ${serial_number}
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000257 Validate Device Flows ${onu_dev_id} ${flow_count}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400258 END
259
260Validate Logical Device
261 [Documentation] Validate Logical Device is listed
262 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
263 Should Be Equal As Integers ${rc} 0
264 ${jsondata}= To Json ${output}
265 Log ${jsondata}
266 ${length}= Get Length ${jsondata}
267 FOR ${INDEX} IN RANGE 0 ${length}
268 ${value}= Get From List ${jsondata} ${INDEX}
269 ${devid}= Get From Dictionary ${value} id
270 ${rootdev}= Get From Dictionary ${value} rootdeviceid
271 ${sn}= Get From Dictionary ${value} serialnumber
272 Exit For Loop
273 END
274 Should Be Equal '${rootdev}' '${olt_device_id}' Root Device does not match ${olt_device_id} values=False
275 Should Be Equal '${sn}' '${BBSIM_OLT_SN}' Logical Device ${sn} does not match ${BBSIM_OLT_SN}
276 ... values=False
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700277 [Return] ${devid}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400278
279Validate Logical Device Ports
280 [Arguments] ${logical_device_id}
281 [Documentation] Validate Logical Device Ports are listed and are > 0
282 ${rc} ${output}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800283 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice port list ${logical_device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400284 Should Be Equal As Integers ${rc} 0
285 ${jsondata}= To Json ${output}
286 Log ${jsondata}
287 ${length}= Get Length ${jsondata}
288 Should Be True ${length} > 0 Number of ports for ${logical_device_id} was 0
289
290Validate Logical Device Flows
291 [Arguments] ${logical_device_id}
292 [Documentation] Validate Logical Device Flows are listed and are > 0
293 ${rc} ${output}= Run and Return Rc and Output
294 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${logical_device_id} -o json
295 Should Be Equal As Integers ${rc} 0
296 ${jsondata}= To Json ${output}
297 Log ${jsondata}
298 ${length}= Get Length ${jsondata}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700299 Should Be True ${length} > 0 Number of flows for ${logical_device_id} was 0
Gilles Depatieb5682f82019-10-31 10:39:45 -0400300
301Retrieve Peer List From OLT
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700302 [Arguments] ${olt_peer_list}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400303 [Documentation] Retrieve the list of peer device id list from port list
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700304 ${rc} ${output}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800305 ... ${VOLTCTL_CONFIG}; voltctl device port list ${olt_device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400306 Should Be Equal As Integers ${rc} 0
307 ${jsondata}= To Json ${output}
308 Log ${jsondata}
309 ${length}= Get Length ${jsondata}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700310 ${matched}= Set Variable False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400311 FOR ${INDEX} IN RANGE 0 ${length}
312 ${value}= Get From List ${jsondata} ${INDEX}
313 ${type}= Get From Dictionary ${value} type
314 ${peers}= Get From Dictionary ${value} peers
Andy Bavierb63f6d22020-03-12 15:34:37 -0700315 ${matched}= Set Variable If '${type}' == 'PON_OLT' True False
316 Exit For Loop If ${matched}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400317 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700318 Should Be True ${matched} No PON port found for OLT ${olt_device_id}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400319 ${length}= Get Length ${peers}
320 FOR ${INDEX} IN RANGE 0 ${length}
321 ${value}= Get From List ${peers} ${INDEX}
322 ${peer_id}= Get From Dictionary ${value} deviceid
323 Append To List ${olt_peer_list} ${peer_id}
324 END
325
326Validate OLT Peer Id List
327 [Arguments] ${olt_peer_id_list}
328 [Documentation] Match each entry in the ${olt_peer_id_list} against ONU device ids.
329 FOR ${peer_id} IN @{olt_peer_id_list}
330 Match OLT Peer Id ${peer_id}
331 END
332
333Match OLT Peer Id
334 [Arguments] ${olt_peer_id}
335 [Documentation] Lookup the OLT Peer Id in against the list of ONU device Ids
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700336 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400337 Should Be Equal As Integers ${rc} 0
338 ${jsondata}= To Json ${output}
339 Log ${jsondata}
340 ${length}= Get Length ${jsondata}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700341 ${matched}= Set Variable False
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700342 FOR ${INDEX} IN RANGE 0 ${length}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400343 ${value}= Get From List ${jsondata} ${INDEX}
344 ${devid}= Get From Dictionary ${value} id
Andy Bavierb63f6d22020-03-12 15:34:37 -0700345 ${matched}= Set Variable If '${devid}' == '${olt_peer_id}' True False
346 Exit For Loop If ${matched}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400347 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700348 Should Be True ${matched} Peer id ${olt_peer_id} does not match any ONU device id
Gilles Depatieb5682f82019-10-31 10:39:45 -0400349
350Validate ONU Peer Id
351 [Arguments] ${olt_device_id} ${List_ONU_Serial}
352 [Documentation] Match each ONU peer to that of the OLT device id
353 FOR ${onu_serial} IN @{List_ONU_Serial}
354 ${onu_dev_id}= Get Device ID From SN ${onu_serial}
355 Match ONU Peer Id ${onu_dev_id}
356 END
357
358Match ONU Peer Id
359 [Arguments] ${onu_dev_id}
360 [Documentation] Match an ONU peer to that of the OLT device id
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800361 ${rc} ${output}= Run and Return Rc and Output
362 ... ${VOLTCTL_CONFIG}; voltctl device port list ${onu_dev_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400363 Should Be Equal As Integers ${rc} 0
364 ${jsondata}= To Json ${output}
365 Log ${jsondata}
366 ${length}= Get Length ${jsondata}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700367 ${matched}= Set Variable False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400368 FOR ${INDEX} IN RANGE 0 ${length}
369 ${value}= Get From List ${jsondata} ${INDEX}
370 ${type}= Get From Dictionary ${value} type
371 ${peers}= Get From Dictionary ${value} peers
Andy Bavierb63f6d22020-03-12 15:34:37 -0700372 ${matched}= Set Variable If '${type}' == 'PON_ONU' True False
373 Exit For Loop If ${matched}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400374 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700375 Should Be True ${matched} No PON port found for ONU ${onu_dev_id}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400376 ${length}= Get Length ${peers}
377 FOR ${INDEX} IN RANGE 0 ${length}
378 ${value}= Get From List ${peers} ${INDEX}
379 ${peer_id}= Get From Dictionary ${value} deviceid
380 END
381 Should Be Equal '${peer_id}' '${olt_device_id}'
382 ... Mismatch between ONU peer ${peer_id} and OLT device id ${olt_device_id} values=False
Kailash6f5acb62019-08-28 14:38:45 -0700383
Kailash6f5acb62019-08-28 14:38:45 -0700384Get Device ID From SN
385 [Arguments] ${serial_number}
386 [Documentation] Gets the device id by matching for ${serial_number}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700387 ${rc} ${id}= Run and Return Rc and Output
Andy Bavier8fca0452019-12-16 15:30:11 -0700388 ... ${VOLTCTL_CONFIG}; voltctl device list --filter=SerialNumber=${serial_number} --format='{{.Id}}'
389 Should Be Equal As Integers ${rc} 0
390 Log ${id}
Kailash6f5acb62019-08-28 14:38:45 -0700391 [Return] ${id}
392
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700393Get Logical Device ID From SN
394 [Arguments] ${serial_number}
395 [Documentation] Gets the device id by matching for ${serial_number}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700396 ${rc} ${id}= Run and Return Rc and Output
Andy Bavier8fca0452019-12-16 15:30:11 -0700397 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice list --filter=SerialNumber=${serial_number} --format='{{.Id}}'
398 Should Be Equal As Integers ${rc} 0
399 Log ${id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700400 [Return] ${id}
401
Gilles Depatieb5682f82019-10-31 10:39:45 -0400402Build ONU SN List
403 [Arguments] ${serial_numbers}
404 [Documentation] Appends all ONU SNs to the ${serial_numbers} list
405 FOR ${INDEX} IN RANGE 0 ${num_onus}
406 Append To List ${serial_numbers} ${hosts.src[${INDEX}].onu}
407 END
408
409Get SN From Device ID
410 [Arguments] ${device_id}
411 [Documentation] Gets the device id by matching for ${device_id}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700412 ${rc} ${sn}= Run and Return Rc and Output
Andy Bavier8fca0452019-12-16 15:30:11 -0700413 ... ${VOLTCTL_CONFIG}; voltctl device list --filter=Id=${device_id} --format='{{.SerialNumber}}'
Gilles Depatieb5682f82019-10-31 10:39:45 -0400414 Should Be Equal As Integers ${rc} 0
Andy Bavier8fca0452019-12-16 15:30:11 -0700415 Log ${sn}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400416 [Return] ${sn}
417
Scott Baker60e570d2020-02-02 22:10:13 -0800418Get Parent ID From Device ID
419 [Arguments] ${device_id}
420 [Documentation] Gets the device id by matching for ${device_id}
421 ${rc} ${pid}= Run and Return Rc and Output
422 ... ${VOLTCTL_CONFIG}; voltctl device list --filter=Id=${device_id} --format='{{.ParentId}}'
423 Should Be Equal As Integers ${rc} 0
424 Log ${pid}
425 [Return] ${pid}
426
Kailash6f5acb62019-08-28 14:38:45 -0700427Validate Device Removed
428 [Arguments] ${id}
429 [Documentation] Verifys that device, ${serial_number}, has been removed
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700430 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
Andy Bavier8fca0452019-12-16 15:30:11 -0700431 Should Be Equal As Integers ${rc} 0
Kailash6f5acb62019-08-28 14:38:45 -0700432 ${jsondata}= To Json ${output}
433 Log ${jsondata}
434 ${length}= Get Length ${jsondata}
435 @{ids}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -0700436 FOR ${INDEX} IN RANGE 0 ${length}
437 ${value}= Get From List ${jsondata} ${INDEX}
438 ${device_id}= Get From Dictionary ${value} id
439 Append To List ${ids} ${device_id}
440 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700441 List Should Not Contain Value ${ids} ${id}
Suchitra Vemuricd2f64f2020-02-18 18:30:27 -0800442
443Reboot ONU
444 [Arguments] ${onu_id} ${src} ${dst}
445 [Documentation] Using voltctl command reboot ONU and verify that ONU comes up to running state
446 ${rc} ${devices}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device reboot ${onu_id}
447 Should Be Equal As Integers ${rc} 0
448 Run Keyword and Ignore Error Wait Until Keyword Succeeds 60s 1s Validate Device
449 ... ENABLED DISCOVERED UNREACHABLE ${onu_id} onu=True