blob: 6130584b32d2b83de47180a854c794e69deadfa3 [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
Matteo Scandolo142e6272020-04-29 17:36:59 -070025Resource ./utils.robot
Matteo Scandoloeb26a842020-05-08 10:06:24 -070026Resource ./flows.robot
Kailash6f5acb62019-08-28 14:38:45 -070027
28*** Keywords ***
Gilles Depatieb5682f82019-10-31 10:39:45 -040029Test Empty Device List
Zack Williamsa8fe75a2020-01-10 14:25:27 -070030 [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
Gilles Depatieb5682f82019-10-31 10:39:45 -040032 Should Be Equal As Integers ${rc} 0
33 ${jsondata}= To Json ${output}
34 Log ${jsondata}
35 ${length}= Get Length ${jsondata}
David Bainbridgef81cd642019-11-20 00:14:47 +000036 Should Be Equal As Integers ${length} 0
Gilles Depatieb5682f82019-10-31 10:39:45 -040037
Kailash6f5acb62019-08-28 14:38:45 -070038Create Device
Matteo Scandolo142e6272020-04-29 17:36:59 -070039 [Arguments] ${ip} ${port} ${type}=openolt
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
Matteo Scandolo142e6272020-04-29 17:36:59 -070043 ... ${VOLTCTL_CONFIG}; voltctl device create -t ${type} -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
Zack Williamsa8fe75a2020-01-10 14:25:27 -070050 ${rc} ${output}= Run and Return Rc and Output
51 ... ${VOLTCTL_CONFIG}; voltctl device enable ${device_id}
Kailash6f5acb62019-08-28 14:38:45 -070052 Should Be Equal As Integers ${rc} 0
53
Suchitra Vemuri6db89412019-11-14 14:52:54 -080054Disable Device
55 [Arguments] ${device_id}
Hardik Windlassaaea3402020-03-10 19:45:45 +053056 [Documentation] Disables a device in VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -070057 ${rc} ${output}= Run and Return Rc and Output
58 ... ${VOLTCTL_CONFIG}; voltctl device disable ${device_id}
Suchitra Vemuri6db89412019-11-14 14:52:54 -080059 Should Be Equal As Integers ${rc} 0
60
Hardik Windlassaaea3402020-03-10 19:45:45 +053061Delete Device
62 [Arguments] ${device_id}
63 [Documentation] Deletes a device in VOLTHA
64 ${rc} ${output}= Run and Return Rc and Output
65 ... ${VOLTCTL_CONFIG}; voltctl device delete ${device_id}
66 Should Be Equal As Integers ${rc} 0
67
Hemadf003682020-04-28 21:22:22 +053068Reboot Device
69 [Arguments] ${device_id}
70 [Documentation] Reboot the OLT using voltctl command
71 ${rc} ${output}= Run and Return Rc and Output
72 ... ${VOLTCTL_CONFIG}; voltctl device reboot ${device_id}
73 Should Be Equal As Integers ${rc} 0
74
David Bainbridgef81cd642019-11-20 00:14:47 +000075Disable Devices In Voltha
76 [Documentation] Disables all the known devices in voltha
77 [Arguments] ${filter}
78 ${arg}= Set Variable ${EMPTY}
79 ${arg}= Run Keyword If len('${filter}'.strip()) != 0 Set Variable --filter ${filter}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070080 ${rc} ${devices}= Run and Return Rc and Output
81 ... ${VOLTCTL_CONFIG}; voltctl device list ${arg} --orderby Root -q | xargs echo -n
David Bainbridgef81cd642019-11-20 00:14:47 +000082 Should Be Equal As Integers ${rc} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -070083 ${rc} ${output}= Run Keyword If len('${devices}') != 0 Run and Return Rc and Output
84 ... ${VOLTCTL_CONFIG}; voltctl device disable ${devices}
David Bainbridgef81cd642019-11-20 00:14:47 +000085 Run Keyword If len('${devices}') != 0 Should Be Equal As Integers ${rc} 0
86
87Test Devices Disabled In Voltha
88 [Documentation] Tests to verify that all devices in VOLTHA are disabled
89 [Arguments] ${filter}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070090 ${rc} ${count}= Run and Return Rc and Output
91 ... ${VOLTCTL_CONFIG}; voltctl device list --filter '${filter},AdminState!=DISABLED' -q | wc -l
David Bainbridgef81cd642019-11-20 00:14:47 +000092 Should Be Equal As Integers ${rc} 0
93 Should Be Equal As Integers ${count} 0
94
95Delete Devices In Voltha
96 [Documentation] Disables all the known devices in voltha
97 [Arguments] ${filter}
98 ${arg}= Set Variable ${EMPTY}
99 ${arg}= Run Keyword If len('${filter}'.strip()) != 0 Set Variable --filter ${filter}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700100 ${rc} ${devices}= Run and Return Rc and Output
101 ... ${VOLTCTL_CONFIG}; voltctl device list ${arg} --orderby Root -q | xargs echo -n
David Bainbridgef81cd642019-11-20 00:14:47 +0000102 Should Be Equal As Integers ${rc} 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700103 ${rc} ${output}= Run Keyword If len('${devices}') != 0 Run and Return Rc and Output
104 ... ${VOLTCTL_CONFIG}; voltctl device delete ${devices}
David Bainbridgef81cd642019-11-20 00:14:47 +0000105 Run Keyword If len('${devices}') != 0 Should Be Equal As Integers ${rc} 0
106
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700107Get Device Flows from Voltha
108 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700109 [Documentation] Gets device flows from VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700110 ${rc} ${output}= Run and Return Rc and Output
111 ... ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700112 Should Be Equal As Integers ${rc} 0
113 [Return] ${output}
114
115Get Logical Device Output from Voltha
116 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700117 [Documentation] Gets logicaldevice flows and ports from VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700118 ${rc1} ${flows}= Run and Return Rc and Output
119 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device_id}
120 ${rc2} ${ports}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800121 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice port list ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700122 Log ${flows}
123 Log ${ports}
124 Should Be Equal As Integers ${rc1} 0
125 Should Be Equal As Integers ${rc2} 0
126
127Get Device Output from Voltha
128 [Arguments] ${device_id}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700129 [Documentation] Gets device flows and ports from VOLTHA
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700130 ${rc1} ${flows}= Run and Return Rc and Output
131 ... ${VOLTCTL_CONFIG}; voltctl device flows ${device_id}
132 ${rc2} ${ports}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800133 ... ${VOLTCTL_CONFIG}; voltctl device port list ${device_id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700134 Log ${flows}
135 Log ${ports}
136 Should Be Equal As Integers ${rc1} 0
137 Should Be Equal As Integers ${rc2} 0
138
Suchitra Vemuri1a970a62019-11-26 12:52:16 -0800139Get Device List from Voltha
140 [Documentation] Gets Device List Output from Voltha
141 ${rc1} ${devices}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list
142 Log ${devices}
143 Should Be Equal As Integers ${rc1} 0
144
Matteo Scandolo616daab2020-05-13 11:49:24 -0700145Get Device List from Voltha by type
146 [Documentation] Gets Device List Output from Voltha applying filtering by device type
147 [Arguments] ${type}
148 ${rc1} ${devices}= Run and Return Rc and Output
149 ... ${VOLTCTL_CONFIG}; voltctl device list -f Type=${type} -o json
150 Log ${devices}
151 Should Be Equal As Integers ${rc1} 0
152 Return From Keyword ${devices}
153
Matteo Scandolo142e6272020-04-29 17:36:59 -0700154Get Logical Device List from Voltha
155 [Documentation] Gets Logical Device List Output from Voltha (in json format)
156 ${rc1} ${devices}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
157 Log ${devices}
158 Should Be Equal As Integers ${rc1} 0
159 Return From Keyword ${devices}
160
Kailash6f5acb62019-08-28 14:38:45 -0700161Validate Device
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700162 [Documentation]
ubuntu6b6e7d42020-03-02 12:35:42 -0800163 ... Parses the output of "voltctl device list" and inspects a device ${id}, specified as either
164 ... the serial number or device ID. Arguments are matched for device states of: "admin_state",
165 ... "oper_status", and "connect_status"
166 [Arguments] ${admin_state} ${oper_status} ${connect_status}
167 ... ${id}=${EMPTY} ${onu_reason}=${EMPTY} ${onu}=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400168 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
169 Should Be Equal As Integers ${rc} 0
Kailash6f5acb62019-08-28 14:38:45 -0700170 ${jsondata}= To Json ${output}
Kailash6f5acb62019-08-28 14:38:45 -0700171 ${length}= Get Length ${jsondata}
ubuntu6b6e7d42020-03-02 12:35:42 -0800172 ${matched}= Set Variable False
Zack Williamsec53a1b2019-09-16 15:50:52 -0700173 FOR ${INDEX} IN RANGE 0 ${length}
174 ${value}= Get From List ${jsondata} ${INDEX}
Scott Baker780b65f2020-05-22 14:03:15 -0700175 ${jsonCamelCaseFieldnames}= Run Keyword And Return Status
176 ... Dictionary Should Contain Key ${value} adminState
177 ${astate}= Run Keyword If ${jsonCamelCaseFieldNames}
178 ... Get From Dictionary ${value} adminState
179 ... ELSE
180 ... Get From Dictionary ${value} adminstate
181 ${opstatus}= Run Keyword If ${jsonCamelCaseFieldNames}
182 ... Get From Dictionary ${value} operStatus
183 ... ELSE
184 ... Get From Dictionary ${value} operstatus
185 ${cstatus}= Run Keyword If ${jsonCamelCaseFieldNames}
186 ... Get From Dictionary ${value} connectStatus
187 ... ELSE
188 ... Get From Dictionary ${value} connectstatus
189 ${sn}= Run Keyword If ${jsonCamelCaseFieldNames}
190 ... Get From Dictionary ${value} serialNumber
191 ... ELSE
192 ... Get From Dictionary ${value} serialnumber
Gilles Depatieb5682f82019-10-31 10:39:45 -0400193 ${devId}= Get From Dictionary ${value} id
Zack Williamsec53a1b2019-09-16 15:50:52 -0700194 ${mib_state}= Get From Dictionary ${value} reason
ubuntu6b6e7d42020-03-02 12:35:42 -0800195 ${matched}= Set Variable If '${sn}' == '${id}' or '${devId}' == '${id}' True False
Andy Bavierb63f6d22020-03-12 15:34:37 -0700196 Exit For Loop If ${matched}
Zack Williamsec53a1b2019-09-16 15:50:52 -0700197 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700198 Should Be True ${matched} No match found for ${id} to validate device
Matteo Scandolo5e10b282019-11-25 10:54:32 -0700199 Log ${value}
ubuntu6b6e7d42020-03-02 12:35:42 -0800200 Should Be Equal '${astate}' '${admin_state}' Device ${sn} admin_state != ${admin_state}
Gilles Depatie675a2062019-10-22 12:44:42 -0400201 ... values=False
ubuntu6b6e7d42020-03-02 12:35:42 -0800202 Should Be Equal '${opstatus}' '${oper_status}' Device ${sn} oper_status != ${oper_status}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400203 ... values=False
ubuntu6b6e7d42020-03-02 12:35:42 -0800204 Should Be Equal '${cstatus}' '${connect_status}' Device ${sn} conn_status != ${connect_status}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400205 ... values=False
206 Run Keyword If '${onu}' == 'True' Should Be Equal '${mib_state}' '${onu_reason}'
ubuntu6b6e7d42020-03-02 12:35:42 -0800207 ... Device ${sn} mib_state incorrect (${mib_state}) values=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400208
209Validate OLT Device
ubuntu6b6e7d42020-03-02 12:35:42 -0800210 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${id}=${EMPTY}
211 [Documentation] Parses the output of "voltctl device list" and inspects device ${id}, specified
212 ... as either its serial numbner or device ID. Match on OLT Serial number or Device Id and inspect states
213 Validate Device ${admin_state} ${oper_status} ${connect_status} ${id}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400214
215Validate ONU Devices
216 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${List_ONU_Serial}
Andy Bavierf1f26ed2020-03-18 10:59:07 -0700217 ... ${onu_reason}=omci-flows-pushed
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700218 [Documentation] Parses the output of "voltctl device list" and inspects device ${List_ONU_Serial}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400219 ... Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect
220 ... states including MIB state
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700221 FOR ${serial_number} IN @{List_ONU_Serial}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400222 Validate Device ${admin_state} ${oper_status} ${connect_status} ${serial_number}
Andy Bavierf1f26ed2020-03-18 10:59:07 -0700223 ... onu_reason=${onu_reason} onu=True
Debasish28130d02020-03-16 11:05:26 +0000224 END
225
Gilles Depatieb5682f82019-10-31 10:39:45 -0400226Validate Device Port Types
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700227 [Documentation]
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800228 ... Parses the output of voltctl device port list <device_id> and matches the port types listed
Andy Bavier90eb1a12020-03-26 11:54:35 -0700229 [Arguments] ${device_id} ${pon_type} ${ethernet_type} ${all_active}=True
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700230 ${rc} ${output}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800231 ... ${VOLTCTL_CONFIG}; voltctl device port list ${device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400232 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}
Scott Baker780b65f2020-05-22 14:03:15 -0700238 ${jsonCamelCaseFieldnames}= Run Keyword And Return Status
239 ... Dictionary Should Contain Key ${value} adminState
240 ${astate}= Run Keyword If ${jsonCamelCaseFieldNames}
241 ... ${astate}= Get From Dictionary ${value} adminState
242 ... ELSE
243 ... ${astate}= Get From Dictionary ${value} adminstate
244 ${opstatus}= Run Keyword If ${jsonCamelCaseFieldNames}
245 ... Get From Dictionary ${value} operStatus
246 ... ELSE
247 ... ${astate}= Get From Dictionary ${value} operstatus
Gilles Depatieb5682f82019-10-31 10:39:45 -0400248 ${type}= Get From Dictionary ${value} type
Hemaf64d34c2020-03-25 00:40:17 +0530249 Should Be Equal '${astate}' 'ENABLED' Device ${device_id} port admin_state != ENABLED values=False
Andy Bavier90eb1a12020-03-26 11:54:35 -0700250 Run Keyword If ${all_active} Should Be Equal '${opstatus}' 'ACTIVE'
251 ... Device ${device_id} port oper_status != ACTIVE values=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400252 Should Be True '${type}' == '${pon_type}' or '${type}' == '${ethernet_type}'
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700253 ... Device ${device_id} port type is neither ${pon_type} or ${ethernet_type}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400254 END
255
256Validate OLT Port Types
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800257 [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 -0700258 [Arguments] ${pon_type} ${ethernet_type}
259 Validate Device Port Types ${olt_device_id} ${pon_type} ${ethernet_type}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400260
261Validate ONU Port Types
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700262 [Arguments] ${List_ONU_Serial} ${pon_type} ${ethernet_type}
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800263 [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 -0700264 ... and matches the port types listed
Gilles Depatieb5682f82019-10-31 10:39:45 -0400265 FOR ${serial_number} IN @{List_ONU_Serial}
266 ${onu_dev_id}= Get Device ID From SN ${serial_number}
Andy Bavier90eb1a12020-03-26 11:54:35 -0700267 # Only first UNI port is ACTIVE; the rest are in DISCOVERED operstatus
268 Validate Device Port Types ${onu_dev_id} ${pon_type} ${ethernet_type} all_active=False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400269 END
270
271Validate Device Flows
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000272 [Arguments] ${device_id} ${flow_count}=${EMPTY}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400273 [Documentation] Parses the output of voltctl device flows <device_id> and expects flow count > 0
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700274 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device flows ${device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400275 Should Be Equal As Integers ${rc} 0
276 ${jsondata}= To Json ${output}
277 Log ${jsondata}
278 ${length}= Get Length ${jsondata}
279 Log 'Number of flows = ' ${length}
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000280 Run Keyword If '${flow_count}' == '${EMPTY}' Should Be True ${length} > 0
Gilles Depatieb5682f82019-10-31 10:39:45 -0400281 ... Number of flows for ${device_id} was 0
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000282 ... ELSE Should Be True ${length} == ${flow_count}
283 ... Number of flows for ${device_id} was not ${flow_count}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400284
285Validate OLT Flows
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000286 [Arguments] ${flow_count}=${EMPTY}
287 [Documentation] Parses the output of voltctl device flows ${olt_device_id}
288 ... and expects flow count == ${flow_count}
289 Validate Device Flows ${olt_device_id} ${flow_count}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400290
291Validate ONU Flows
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000292 [Arguments] ${List_ONU_Serial} ${flow_count}=${EMPTY}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400293 [Documentation] Parses the output of voltctl device flows for each ONU SN listed in ${List_ONU_Serial}
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000294 ... and expects flow count == ${flow_count}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700295 FOR ${serial_number} IN @{List_ONU_Serial}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400296 ${onu_dev_id}= Get Device ID From SN ${serial_number}
Hardik Windlassa3d04b92020-02-17 15:06:05 +0000297 Validate Device Flows ${onu_dev_id} ${flow_count}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400298 END
299
TorstenThieme401af432020-06-11 15:53:53 +0000300Validate ONU Devices With Duration
301 [Documentation]
302 ... Parses the output of "voltctl device list" and inspects all devices ${List_ONU_Serial},
303 ... Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect
304 ... states including MIB state.
305 [Arguments] ${admin_state} ${oper_status} ${connect_status} ${onu_reason}
306 ... ${List_ONU_Serial} ${startTime} ${print2console}=False ${output_file}=${EMPTY}
307 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
308 Should Be Equal As Integers ${rc} 0
309 ${timeCurrent} = Get Current Date
310 ${timeTotalMs} = Subtract Date From Date ${timeCurrent} ${startTime} result_format=number
311 ${jsondata}= To Json ${output}
312 ${length}= Get Length ${jsondata}
313 FOR ${INDEX} IN RANGE 0 ${length}
314 ${matched}= Set Variable False
315 ${value}= Get From List ${jsondata} ${INDEX}
316 ${jsonCamelCaseFieldnames}= Run Keyword And Return Status
317 ... Dictionary Should Contain Key ${value} adminState
318 ${astate}= Run Keyword If ${jsonCamelCaseFieldNames}
319 ... Get From Dictionary ${value} adminState
320 ... ELSE
321 ... Get From Dictionary ${value} adminstate
322 ${opstatus}= Run Keyword If ${jsonCamelCaseFieldNames}
323 ... Get From Dictionary ${value} operStatus
324 ... ELSE
325 ... Get From Dictionary ${value} operstatus
326 ${cstatus}= Run Keyword If ${jsonCamelCaseFieldNames}
327 ... Get From Dictionary ${value} connectStatus
328 ... ELSE
329 ... Get From Dictionary ${value} connectstatus
330 ${sn}= Run Keyword If ${jsonCamelCaseFieldNames}
331 ... Get From Dictionary ${value} serialNumber
332 ... ELSE
333 ... Get From Dictionary ${value} serialnumber
334 ${mib_state}= Get From Dictionary ${value} reason
335 ${onu_id}= Get Index From List ${List_ONU_Serial} ${sn}
336 ${matched}= Set Variable If -1 != ${onu_id} True False
337 ${matched}= Set Variable If '${astate}' == '${admin_state}' ${matched} False
338 ${matched}= Set Variable If '${opstatus}' == '${oper_status}' ${matched} False
339 ${matched}= Set Variable If '${cstatus}' == '${connect_status}' ${matched} False
340 ${matched}= Set Variable If '${mib_state}' == '${onu_reason}' ${matched} False
341 Run Keyword If ${matched} and ${print2console} Log
342 ... \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec. console=yes
343 Run Keyword If ${matched} and ('${output_file}'!='${EMPTY}') Append To File ${output_file}
344 ... \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec.
345 Run Keyword If ${matched} Remove Values From List ${List_ONU_Serial} ${sn}
346 END
347 Should Be Empty ${List_ONU_Serial} List ${List_ONU_Serial} not empty
348
TorstenThieme9949b172020-06-16 10:00:15 +0000349Validate ONU Devices MIB State With Duration
350 [Documentation]
351 ... Parses the output of "voltctl device list" and inspects all devices ${List_ONU_Serial},
352 ... Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect MIB state.
353 [Arguments] ${onu_reason}
354 ... ${List_ONU_Serial} ${startTime} ${print2console}=False ${output_file}=${EMPTY}
355 ${type} = Set Variable brcm_openomci_onu
356 ${rc} ${output}= Run and Return Rc and Output
357 ... ${VOLTCTL_CONFIG}; voltctl device list -f Type=${type} -f Reason=${onu_reason} --format '{{.SerialNumber}}'
358 Should Be Equal As Integers ${rc} 0
359 ${timeCurrent} = Get Current Date
360 ${timeTotalMs} = Subtract Date From Date ${timeCurrent} ${startTime} result_format=number
361 @{outputdata} = Split String ${output}
362 ${outputlength} = Get Length ${outputdata}
363 ${onulength} = Get Length ${List_ONU_Serial}
364 ${Matches} = Run Keyword If ${outputlength}<=${onulength}
365 ... Compare Lists ${outputdata} ${List_ONU_Serial}
366 ... ELSE Compare Lists ${List_ONU_Serial} ${outputdata}
367 ${length} = Get Length ${Matches}
368 FOR ${INDEX} IN RANGE 0 ${length}
369 ${sn}= Get From List ${Matches} ${INDEX}
370 Run Keyword If ${print2console} Log
371 ... \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec. console=yes
372 Run Keyword If ('${output_file}'!='${EMPTY}') Append To File ${output_file}
373 ... \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec.
374 Remove Values From List ${List_ONU_Serial} ${sn}
375 END
376 Should Be Empty ${List_ONU_Serial} List ${List_ONU_Serial} not empty
377
378Compare Lists
379 [Documentation]
380 ... Compares both lists and put all matches in the returned list
381 [Arguments] ${ListIterate} ${ListCompare}
382 @{list} = Create List
383 ${length} = Get Length ${ListIterate}
384 FOR ${INDEX} IN RANGE 0 ${length}
385 ${sn}= Get From List ${ListIterate} ${INDEX}
386 ${onu_id}= Get Index From List ${ListCompare} ${sn}
387 Run Keyword If -1 != ${onu_id} Append To List ${list} ${sn}
388 END
389 [Return] ${list}
390
Gilles Depatieb5682f82019-10-31 10:39:45 -0400391Validate Logical Device
392 [Documentation] Validate Logical Device is listed
393 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
394 Should Be Equal As Integers ${rc} 0
395 ${jsondata}= To Json ${output}
396 Log ${jsondata}
397 ${length}= Get Length ${jsondata}
398 FOR ${INDEX} IN RANGE 0 ${length}
399 ${value}= Get From List ${jsondata} ${INDEX}
400 ${devid}= Get From Dictionary ${value} id
Scott Baker2ab2a0c2020-06-05 12:51:47 -0700401 ${rootdev}= Get From Dictionary ${value} rootDeviceId
402 ${desc}= Get From Dictionary ${value} desc
403 ${sn}= Get From Dictionary ${desc} serialNum
Gilles Depatieb5682f82019-10-31 10:39:45 -0400404 Exit For Loop
405 END
406 Should Be Equal '${rootdev}' '${olt_device_id}' Root Device does not match ${olt_device_id} values=False
407 Should Be Equal '${sn}' '${BBSIM_OLT_SN}' Logical Device ${sn} does not match ${BBSIM_OLT_SN}
408 ... values=False
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700409 [Return] ${devid}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400410
411Validate Logical Device Ports
412 [Arguments] ${logical_device_id}
413 [Documentation] Validate Logical Device Ports are listed and are > 0
414 ${rc} ${output}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800415 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice port list ${logical_device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400416 Should Be Equal As Integers ${rc} 0
417 ${jsondata}= To Json ${output}
418 Log ${jsondata}
419 ${length}= Get Length ${jsondata}
420 Should Be True ${length} > 0 Number of ports for ${logical_device_id} was 0
421
422Validate Logical Device Flows
423 [Arguments] ${logical_device_id}
424 [Documentation] Validate Logical Device Flows are listed and are > 0
425 ${rc} ${output}= Run and Return Rc and Output
426 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${logical_device_id} -o json
427 Should Be Equal As Integers ${rc} 0
428 ${jsondata}= To Json ${output}
429 Log ${jsondata}
430 ${length}= Get Length ${jsondata}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700431 Should Be True ${length} > 0 Number of flows for ${logical_device_id} was 0
Gilles Depatieb5682f82019-10-31 10:39:45 -0400432
433Retrieve Peer List From OLT
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700434 [Arguments] ${olt_peer_list}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400435 [Documentation] Retrieve the list of peer device id list from port list
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700436 ${rc} ${output}= Run and Return Rc and Output
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800437 ... ${VOLTCTL_CONFIG}; voltctl device port list ${olt_device_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400438 Should Be Equal As Integers ${rc} 0
439 ${jsondata}= To Json ${output}
440 Log ${jsondata}
441 ${length}= Get Length ${jsondata}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700442 ${matched}= Set Variable False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400443 FOR ${INDEX} IN RANGE 0 ${length}
444 ${value}= Get From List ${jsondata} ${INDEX}
445 ${type}= Get From Dictionary ${value} type
446 ${peers}= Get From Dictionary ${value} peers
Andy Bavierb63f6d22020-03-12 15:34:37 -0700447 ${matched}= Set Variable If '${type}' == 'PON_OLT' True False
448 Exit For Loop If ${matched}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400449 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700450 Should Be True ${matched} No PON port found for OLT ${olt_device_id}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400451 ${length}= Get Length ${peers}
452 FOR ${INDEX} IN RANGE 0 ${length}
453 ${value}= Get From List ${peers} ${INDEX}
454 ${peer_id}= Get From Dictionary ${value} deviceid
455 Append To List ${olt_peer_list} ${peer_id}
456 END
457
458Validate OLT Peer Id List
459 [Arguments] ${olt_peer_id_list}
460 [Documentation] Match each entry in the ${olt_peer_id_list} against ONU device ids.
461 FOR ${peer_id} IN @{olt_peer_id_list}
462 Match OLT Peer Id ${peer_id}
463 END
464
465Match OLT Peer Id
466 [Arguments] ${olt_peer_id}
467 [Documentation] Lookup the OLT Peer Id in against the list of ONU device Ids
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700468 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400469 Should Be Equal As Integers ${rc} 0
470 ${jsondata}= To Json ${output}
471 Log ${jsondata}
472 ${length}= Get Length ${jsondata}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700473 ${matched}= Set Variable False
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700474 FOR ${INDEX} IN RANGE 0 ${length}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400475 ${value}= Get From List ${jsondata} ${INDEX}
476 ${devid}= Get From Dictionary ${value} id
Andy Bavierb63f6d22020-03-12 15:34:37 -0700477 ${matched}= Set Variable If '${devid}' == '${olt_peer_id}' True False
478 Exit For Loop If ${matched}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400479 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700480 Should Be True ${matched} Peer id ${olt_peer_id} does not match any ONU device id
Gilles Depatieb5682f82019-10-31 10:39:45 -0400481
482Validate ONU Peer Id
483 [Arguments] ${olt_device_id} ${List_ONU_Serial}
484 [Documentation] Match each ONU peer to that of the OLT device id
485 FOR ${onu_serial} IN @{List_ONU_Serial}
486 ${onu_dev_id}= Get Device ID From SN ${onu_serial}
487 Match ONU Peer Id ${onu_dev_id}
488 END
489
490Match ONU Peer Id
491 [Arguments] ${onu_dev_id}
492 [Documentation] Match an ONU peer to that of the OLT device id
David K. Bainbridgebd5ebd22020-02-04 10:01:18 -0800493 ${rc} ${output}= Run and Return Rc and Output
494 ... ${VOLTCTL_CONFIG}; voltctl device port list ${onu_dev_id} -o json
Gilles Depatieb5682f82019-10-31 10:39:45 -0400495 Should Be Equal As Integers ${rc} 0
496 ${jsondata}= To Json ${output}
497 Log ${jsondata}
498 ${length}= Get Length ${jsondata}
Andy Bavierb63f6d22020-03-12 15:34:37 -0700499 ${matched}= Set Variable False
Gilles Depatieb5682f82019-10-31 10:39:45 -0400500 FOR ${INDEX} IN RANGE 0 ${length}
501 ${value}= Get From List ${jsondata} ${INDEX}
502 ${type}= Get From Dictionary ${value} type
503 ${peers}= Get From Dictionary ${value} peers
Andy Bavierb63f6d22020-03-12 15:34:37 -0700504 ${matched}= Set Variable If '${type}' == 'PON_ONU' True False
505 Exit For Loop If ${matched}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400506 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700507 Should Be True ${matched} No PON port found for ONU ${onu_dev_id}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400508 ${length}= Get Length ${peers}
509 FOR ${INDEX} IN RANGE 0 ${length}
510 ${value}= Get From List ${peers} ${INDEX}
511 ${peer_id}= Get From Dictionary ${value} deviceid
512 END
513 Should Be Equal '${peer_id}' '${olt_device_id}'
514 ... Mismatch between ONU peer ${peer_id} and OLT device id ${olt_device_id} values=False
Kailash6f5acb62019-08-28 14:38:45 -0700515
Kailash6f5acb62019-08-28 14:38:45 -0700516Get Device ID From SN
517 [Arguments] ${serial_number}
518 [Documentation] Gets the device id by matching for ${serial_number}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700519 ${rc} ${id}= Run and Return Rc and Output
Andy Bavier8fca0452019-12-16 15:30:11 -0700520 ... ${VOLTCTL_CONFIG}; voltctl device list --filter=SerialNumber=${serial_number} --format='{{.Id}}'
521 Should Be Equal As Integers ${rc} 0
522 Log ${id}
Kailash6f5acb62019-08-28 14:38:45 -0700523 [Return] ${id}
524
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700525Get Logical Device ID From SN
526 [Arguments] ${serial_number}
527 [Documentation] Gets the device id by matching for ${serial_number}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700528 ${rc} ${id}= Run and Return Rc and Output
Scott Baker2ab2a0c2020-06-05 12:51:47 -0700529 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice list --filter=Desc.SerialNum=${serial_number} --format='{{.Id}}'
Andy Bavier8fca0452019-12-16 15:30:11 -0700530 Should Be Equal As Integers ${rc} 0
531 Log ${id}
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700532 [Return] ${id}
533
Gilles Depatieb5682f82019-10-31 10:39:45 -0400534Build ONU SN List
535 [Arguments] ${serial_numbers}
536 [Documentation] Appends all ONU SNs to the ${serial_numbers} list
537 FOR ${INDEX} IN RANGE 0 ${num_onus}
538 Append To List ${serial_numbers} ${hosts.src[${INDEX}].onu}
539 END
540
541Get SN From Device ID
542 [Arguments] ${device_id}
543 [Documentation] Gets the device id by matching for ${device_id}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700544 ${rc} ${sn}= Run and Return Rc and Output
Andy Bavier8fca0452019-12-16 15:30:11 -0700545 ... ${VOLTCTL_CONFIG}; voltctl device list --filter=Id=${device_id} --format='{{.SerialNumber}}'
Gilles Depatieb5682f82019-10-31 10:39:45 -0400546 Should Be Equal As Integers ${rc} 0
Andy Bavier8fca0452019-12-16 15:30:11 -0700547 Log ${sn}
Gilles Depatieb5682f82019-10-31 10:39:45 -0400548 [Return] ${sn}
549
Scott Baker60e570d2020-02-02 22:10:13 -0800550Get Parent ID From Device ID
551 [Arguments] ${device_id}
552 [Documentation] Gets the device id by matching for ${device_id}
553 ${rc} ${pid}= Run and Return Rc and Output
554 ... ${VOLTCTL_CONFIG}; voltctl device list --filter=Id=${device_id} --format='{{.ParentId}}'
555 Should Be Equal As Integers ${rc} 0
556 Log ${pid}
557 [Return] ${pid}
558
Kailash6f5acb62019-08-28 14:38:45 -0700559Validate Device Removed
560 [Arguments] ${id}
561 [Documentation] Verifys that device, ${serial_number}, has been removed
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700562 ${rc} ${output}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device list -o json
Andy Bavier8fca0452019-12-16 15:30:11 -0700563 Should Be Equal As Integers ${rc} 0
Kailash6f5acb62019-08-28 14:38:45 -0700564 ${jsondata}= To Json ${output}
565 Log ${jsondata}
566 ${length}= Get Length ${jsondata}
567 @{ids}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -0700568 FOR ${INDEX} IN RANGE 0 ${length}
569 ${value}= Get From List ${jsondata} ${INDEX}
570 ${device_id}= Get From Dictionary ${value} id
571 Append To List ${ids} ${device_id}
572 END
Suchitra Vemuri00d147d2019-09-13 13:07:32 -0700573 List Should Not Contain Value ${ids} ${id}
Suchitra Vemuricd2f64f2020-02-18 18:30:27 -0800574
575Reboot ONU
576 [Arguments] ${onu_id} ${src} ${dst}
577 [Documentation] Using voltctl command reboot ONU and verify that ONU comes up to running state
578 ${rc} ${devices}= Run and Return Rc and Output ${VOLTCTL_CONFIG}; voltctl device reboot ${onu_id}
579 Should Be Equal As Integers ${rc} 0
580 Run Keyword and Ignore Error Wait Until Keyword Succeeds 60s 1s Validate Device
581 ... ENABLED DISCOVERED UNREACHABLE ${onu_id} onu=True
Matteo Scandolo142e6272020-04-29 17:36:59 -0700582
583Assert ONUs in Voltha
584 [Arguments] ${count}
585 [Documentation] Check that a certain number of devices reached the ACTIVE/ENABLE state
586 ${rc1} ${devices}= Run and Return Rc and Output
587 ... ${VOLTCTL_CONFIG}; voltctl device list | grep -v OLT | grep ACTIVE | wc -l
588 Should Be Equal As Integers ${rc1} 0
589 Should Be Equal As Integers ${devices} ${count}
590
591Wait for ONUs in VOLTHA
592 [Arguments] ${count}
593 [Documentation] Waits until a certain number of devices reached the ACTIVE/ENABLE state
594 Wait Until Keyword Succeeds 10m 5s Assert ONUs In Voltha ${count}
595
596Count Logical Devices flows
597 [Documentation] Count the flows across logical devices in VOLTHA
598 [Arguments] ${targetFlows}
599 ${output}= Get Logical Device List From Voltha
600 ${logical_devices}= To Json ${output}
601 ${total_flows}= Set Variable 0
602 FOR ${device} IN @{logical_devices}
603 ${rc} ${flows}= Run and Return Rc and Output
604 ... ${VOLTCTL_CONFIG}; voltctl logicaldevice flows ${device['id']} | grep -v ID | wc -l
605 Should Be Equal As Integers ${rc} 0
606 ${total_flows}= Evaluate ${total_flows} + ${flows}
607 END
Matteo Scandolo616daab2020-05-13 11:49:24 -0700608 ${msg}= Format String Found {total_flows} flows of {targetFlows} expected
609 ... total_flows=${total_flows} targetFlows=${targetFlows}
610 Log ${msg}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700611 Should Be Equal As Integers ${targetFlows} ${total_flows}
612
613Wait for Logical Devices flows
614 [Documentation] Waits until the flows have been provisioned in the logical device
615 [Arguments] ${workflow} ${uni_count} ${olt_count} ${provisioned}
Andrea Campanella70cf0a72020-05-27 10:55:15 +0200616 ... ${withEapol} ${withDhcp} ${withIgmp} ${withLldp}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700617 ${targetFlows}= Calculate flows by workflow ${workflow} ${uni_count} ${olt_count} ${provisioned}
Andrea Campanella70cf0a72020-05-27 10:55:15 +0200618 ... ${withEapol} ${withDhcp} ${withIgmp} ${withLldp}
Matteo Scandolo142e6272020-04-29 17:36:59 -0700619 Log ${targetFlows}
620 # TODO extend Validate Logical Device Flows to check the correct number of flows
621 Wait Until Keyword Succeeds 10m 5s Count Logical Devices flows ${targetFlows}
622
Matteo Scandolo616daab2020-05-13 11:49:24 -0700623Count OpenOLT Device Flows
624 [Documentation] Count the flows across openolt devices in VOLTHA
625 [Arguments] ${targetFlows}
626 ${output}= Get Device List from Voltha by type openolt
627 ${devices}= To Json ${output}
628 ${total_flows}= Set Variable 0
629 FOR ${device} IN @{devices}
630 ${rc} ${flows}= Run and Return Rc and Output
631 ... ${VOLTCTL_CONFIG}; voltctl device flows ${device['id']} | grep -v ID | wc -l
632 Should Be Equal As Integers ${rc} 0
633 ${total_flows}= Evaluate ${total_flows} + ${flows}
634 END
635 ${msg}= Format String Found {total_flows} flows of {targetFlows} expected
636 ... total_flows=${total_flows} targetFlows=${targetFlows}
637 Log ${msg}
638 Should Be Equal As Integers ${targetFlows} ${total_flows}
639
640Wait for OpenOLT Devices flows
641 [Documentation] Waits until the flows have been provisioned in the openolt devices
642 [Arguments] ${workflow} ${uni_count} ${olt_count} ${provisioned}
Andrea Campanella70cf0a72020-05-27 10:55:15 +0200643 ... ${withEapol} ${withDhcp} ${withIgmp} ${withLldp}
Matteo Scandolo616daab2020-05-13 11:49:24 -0700644 # In the physical device we only have 2 data plane flows (on the PON) instead of 4
Matteo Scandolo96dbe432020-05-28 10:51:57 -0700645 ${beforeFlows}= Calculate flows by workflow ${workflow} ${uni_count} ${olt_count} ${provisioned}
646 ... ${withEapol} ${withDhcp} ${withIgmp} ${withLldp}
647 ${afterFlows}= Evaluate ${beforeFlows} - (${uni_count} * 2)
648 ${targetFlows}= Set Variable If $provisioned=='true' ${afterFlows} ${beforeFlows}
Matteo Scandolo616daab2020-05-13 11:49:24 -0700649 Log ${targetFlows}
650 Wait Until Keyword Succeeds 10m 5s Count OpenOLT Device Flows ${targetFlows}