blob: 138971553ebd11620b751553cdd03d155c9f5ba0 [file] [log] [blame]
TorstenThiemed4f48962020-12-08 12:17:19 +00001# Copyright 2020 - present Open Networking Foundation
TorstenThiemefd7e7ba2020-11-06 13:57:57 +00002#
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.
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000014
15*** Settings ***
16Documentation Library for various openonu-go-adpter utilities
17
TorstenThiemed4f48962020-12-08 12:17:19 +000018*** Variables ***
19${defaultstackname} minimal
20
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000021*** Keywords ***
22Do Power On ONU Device
23 [Documentation] This keyword power on all onus.
24 ${namespace}= Set Variable voltha
25 FOR ${I} IN RANGE 0 ${num_all_onus}
26 ${src}= Set Variable ${hosts.src[${I}]}
Holger Hildebrandt23147742020-11-16 10:13:21 +000027 ${result}= Exec Pod In Kube ${namespace} bbsim bbsimctl onu poweron ${src['onu']}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000028 Should Contain ${result} successfully msg=Can not poweron ${src['onu']} values=False
29 END
30
31Do Current State Test
32 [Documentation] This keyword checks the passed state of the given onu.
33 [Arguments] ${state} ${onu} ${reqadminstate}=${EMPTY} ${reqoperstatus}=${EMPTY}
34 ... ${reqconnectstatus}=${EMPTY}
35 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Map State ${state}
36 ${admin_state}= Set Variable If '${reqadminstate}'!='${EMPTY}' ${reqadminstate} ${admin_state}
37 ${oper_status}= Set Variable If '${reqoperstatus}'!='${EMPTY}' ${reqoperstatus} ${oper_status}
38 ${connect_status}= Set Variable If '${reqconnectstatus}'!='${EMPTY}' ${reqconnectstatus}
39 ... ${connect_status}
40 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
41 ... Validate Device ${admin_state} ${oper_status} ${connect_status}
42 ... ${onu} onu=True onu_reason=${onu_state}
43
44Do Current State Test All Onus
45 [Documentation] This keyword checks the passed state of all onus.
46 ... Hint: ${timeStart} will be not evaluated here!
47 [Arguments] ${state} ${reqadminstate}=${EMPTY} ${reqoperstatus}=${EMPTY} ${reqconnectstatus}=${EMPTY}
48 ... ${alternativeonustate}=${EMPTY}
49 ${list_onus} Create List
50 Build ONU SN List ${list_onus}
51 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Map State ${state}
52 ${admin_state}= Set Variable If '${reqadminstate}'!='${EMPTY}' ${reqadminstate} ${admin_state}
53 ${oper_status}= Set Variable If '${reqoperstatus}'!='${EMPTY}' ${reqoperstatus} ${oper_status}
54 ${connect_status}= Set Variable If '${reqconnectstatus}'!='${EMPTY}' ${reqconnectstatus}
55 ... ${connect_status}
56 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
57 ... Validate ONU Devices With Duration
58 ... ${admin_state} ${oper_status} ${connect_status}
TorstenThieme52ef8392020-11-10 13:42:26 +000059 ... ${onu_state} ${list_onus} ${timeStart} alternate_reason=${alternativeonustate}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000060
61Do Current Reason Test All Onus
62 [Documentation] This keyword checks the passed state of all onus.
63 ... Hint: ${timeStart} will be not evaluated here!
64 [Arguments] ${state}
65 ${list_onus} Create List
66 Build ONU SN List ${list_onus}
67 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Map State ${state}
68 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
69 ... Validate ONU Devices MIB State With Duration
70 ... ${onu_state} ${list_onus} ${timeStart}
71
72Log Ports
73 [Documentation] This keyword logs all port data available in ONOS of first port per ONU
74 [Arguments] ${onlyenabled}=False
75 ${cmd} Set Variable If ${onlyenabled} ports -e ports
76 ${onu_ports}= Execute ONOS CLI Command on open connection ${onos_ssh_connection} ${cmd}
77 ${lines} = Get Lines Matching Regexp ${onu_ports} .*portName=BBSM[0-9]{8}-1
78 Log ${lines}
79
80Kill Adaptor
81 [Documentation] This keyword kills the passed adaptor.
82 [Arguments] ${namespace} ${name}
83 ${cmd} Catenate
84 ... kubectl exec -it -n voltha $(kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}')
85 ... -- /bin/sh -c "kill 1"
86 ${rc} ${output}= Run and Return Rc and Output ${cmd}
87 Log ${output}
88
89Verify MIB Template Data Available
90 [Documentation] This keyword verifies MIB Template Data stored in etcd
91 ${namespace}= Set Variable default
TorstenThiemed4f48962020-12-08 12:17:19 +000092 ${podname}= Set Variable etcd
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000093 ${commandget} Catenate
Matteo Scandolo341b9372020-12-09 14:15:06 -080094 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +000095 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000096 Should Not Be Empty ${result} No MIB Template Data stored in etcd!
97
98Delete MIB Template Data
99 [Documentation] This keyword deletes MIB Template Data stored in etcd
100 ${namespace}= Set Variable default
101 ${podname}= Set Variable etcd
102 ${commanddel} Catenate
Matteo Scandolo341b9372020-12-09 14:15:06 -0800103 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/voltha/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000104 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commanddel}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000105 Sleep 3s
106 ${commandget} Catenate
Matteo Scandolo341b9372020-12-09 14:15:06 -0800107 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000108 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000109 Should Be Empty ${result} Could not delete MIB Template Data stored in etcd!
110
TorstenThieme17756ea2020-11-11 14:09:47 +0000111Validate Onu Data In Etcd
112 [Documentation] This keyword validates openonu-go-adapter Data stored in etcd.
113 ... It checks unique of serial_number and combination of pon, onu and uni in tp_path.
114 ... Furthermore it evaluates the values of onu_id and uni_id with values read from tp_path.
115 ... Number of etcd entries has to match with the passed number.
116 [Arguments] ${nbofetcddata}=${num_all_onus}
TorstenThiemed4f48962020-12-08 12:17:19 +0000117 ${stackname}= Get Stack Name
TorstenThieme17756ea2020-11-11 14:09:47 +0000118 ${etcddata}= Get ONU Go Adapter ETCD Data
TorstenThiemed4f48962020-12-08 12:17:19 +0000119 ${etcddata}= Remove Lines Containing String ${etcddata} service/${stackname}/openonu \n
TorstenThieme17756ea2020-11-11 14:09:47 +0000120 #prepare result for json convert
121 ${result}= Prepare ONU Go Adapter ETCD Data For Json ${etcddata}
122 ${jsondata}= To Json ${result}
123 ${length}= Get Length ${jsondata}
124 log ${jsondata}
125 Run Keyword And Continue On Failure Should Be Equal As Integers ${length} ${nbofetcddata}
126 ... msg=Number etcd data (${length}) does not match required (${nbofetcddata})!
127 ${pononuuniidlist}= Create List
128 ${serialnumberlist}= Create List
129 FOR ${INDEX} IN RANGE 0 ${length}
130 ${value}= Get From List ${jsondata} ${INDEX}
Girish Gowdra97f8d062020-11-17 15:48:23 -0800131 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
132 # When testing multi-tcont this may need some adjustment.
133 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000134 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
135 ${list_id}= Get Index From List ${pononuuniidlist} ${pononuuniid}
136 Should Be Equal As Integers ${list_id} -1
137 ... msg=Combination of Pon, Onu and Uni (${pononuuniid}) exist multiple in etcd data!
138 Append To List ${pononuuniidlist} ${pononuuniid}
139 Validate Onu Id ${value}
140 Validate Uni Id ${value}
141 ${serial_number}= Get From Dictionary ${value} serial_number
142 ${list_id}= Get Index From List ${serialnumberlist} ${serial_number}
143 Should Be Equal As Integers ${list_id} -1
144 ... msg=Serial number (${serial_number}) exists multiple in etcd data!
145 Append To List ${serialnumberlist} ${serial_number}
146 END
147
TorstenThieme52ef8392020-11-10 13:42:26 +0000148Validate Vlan Rules In Etcd
149 [Documentation] This keyword validates Vlan rules of openonu-go-adapter Data stored in etcd.
150 ... It checks the given number of cookie_slice, match_vid (=4096) and set_vid.
151 ... Furthermore it returns a list of all set_vid.
152 ... In case of a passed dictionary containing set_vids these will be checked for to
153 ... current set-vid depending on setvidequal (True=equal, False=not equal).
154 [Arguments] ${nbofcookieslice}=1 ${reqmatchvid}=4096 ${prevvlanrules}=${NONE} ${setvidequal}=False
TorstenThiemed4f48962020-12-08 12:17:19 +0000155 ${stackname}= Get Stack Name
TorstenThieme52ef8392020-11-10 13:42:26 +0000156 ${etcddata}= Get ONU Go Adapter ETCD Data
TorstenThiemed4f48962020-12-08 12:17:19 +0000157 ${etcddata}= Remove Lines Containing String ${etcddata} service/${stackname}/openonu \n
TorstenThieme52ef8392020-11-10 13:42:26 +0000158 #prepare result for json convert
159 ${result}= Prepare ONU Go Adapter ETCD Data For Json ${etcddata}
160 ${jsondata}= To Json ${result}
161 ${length}= Get Length ${jsondata}
162 log ${jsondata}
163 ${vlan_rules}= Create Dictionary
164 FOR ${INDEX} IN RANGE 0 ${length}
165 ${value}= Get From List ${jsondata} ${INDEX}
Girish Gowdra295c1692020-11-19 10:51:53 -0800166 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
167 # When testing multi-tcont this may need some adjustment.
168 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme52ef8392020-11-10 13:42:26 +0000169 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
170 ${cookieslice}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]} cookie_slice
171 #@{cookieslicelist}= Split String ${cookieslice} ,
172 ${foundcookieslices}= Get Length ${cookieslice}
173 Should Be Equal As Integers ${foundcookieslices} ${nbofcookieslice}
174 ${matchvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
175 ... match_vid
176 Should Be Equal As Integers ${matchvid} ${reqmatchvid}
177 ${setvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
178 ... set_vid
179 ${evalresult}= Evaluate 2 <= ${setvid} <= 4095
180 Should Be True ${evalresult} msg=set_vid out of range (${setvid})!
181 Set To Dictionary ${vlan_rules} ${pononuuniid} ${setvid}
182 ${oldsetvidvalid} Set Variable If ${prevvlanrules} is ${NONE} False True
183 ${prevsetvid}= Set Variable If ${oldsetvidvalid} ${prevvlanrules['${pononuuniid}']}
184 Run Keyword If ${oldsetvidvalid} and ${setvidequal}
185 ... Should Be Equal As Integers ${prevsetvid} ${setvid}
186 ... ELSE IF ${oldsetvidvalid} and not ${setvidequal}
187 ... Should Not Be Equal As Integers ${prevsetvid} ${setvid}
188 END
189 log Many ${vlan_rules}
190 [Return] ${vlan_rules}
191
192Get ONU Go Adapter ETCD Data
193 [Documentation] This keyword delivers openonu-go-adapter Data stored in etcd
194 ${namespace}= Set Variable default
195 ${podname}= Set Variable etcd
TorstenThiemed4f48962020-12-08 12:17:19 +0000196 ${stackname}= Get Stack Name
TorstenThieme52ef8392020-11-10 13:42:26 +0000197 ${commandget} Catenate
TorstenThiemed4f48962020-12-08 12:17:19 +0000198 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix --prefix service/${stackname}/openonu'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000199 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThieme52ef8392020-11-10 13:42:26 +0000200 log ${result}
201 [Return] ${result}
202
203Prepare ONU Go Adapter ETCD Data For Json
204 [Documentation] This keyword prepares openonu-go-adapter Data stored in etcd for converting
205 ... to json
206 [Arguments] ${etcddata}
207 #prepare result for json convert
208 ${prepresult}= Replace String ${etcddata} \n ,
209 ${prepresult}= Strip String ${prepresult} mode=right characters=,
210 ${prepresult}= Set Variable [${prepresult}]
211 log ${prepresult}
212 [Return] ${prepresult}
213
214Remove Lines Containing String
215 [Documentation] This keyword deletes all lines from given string containing passed remove string
216 [Arguments] ${string} ${toremove} ${appendtoremoveline}
217 ${lines}= Get Lines Containing String ${string} ${toremove}
218 ${length}= Get Line Count ${lines}
219 ${firstline}= Set Variable False
220 FOR ${INDEX} IN RANGE 0 ${length}
221 ${String2remove} Get Line ${lines} ${INDEX}
222 ${String2remove} Set Variable ${String2remove}${appendtoremoveline}
223 ${string}= Remove String ${string} ${String2remove}
224 END
225 log ${string}
226 [Return] ${string}
227
228Read Pon Onu Uni String
229 [Documentation] This keyword builds a thre digit string using Pon, Onu and Uni value of given tp-path taken
230 ... taken from etcd data of onu go adapter
231 [Arguments] ${tp_path}
TorstenThieme52ef8392020-11-10 13:42:26 +0000232 ${tppathlines}= Replace String ${tp_path} / \n
233 ${pon}= Get Value Of Tp Path Element ${tppathlines} pon
234 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
235 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
236 ${valuesid}= Set Variable ${pon}/${onu}/${uni}
237 log ${valuesid}
238 [Return] ${valuesid}
239
240Get Value Of Tp Path Element
TorstenThieme17756ea2020-11-11 14:09:47 +0000241 [Documentation] This keyword delivers numeric value of given tp path element.
TorstenThieme52ef8392020-11-10 13:42:26 +0000242 [Arguments] ${tp_path_lines} ${element}
243 ${value}= Get Lines Containing String ${tp_path_lines} ${element}-\{
244 ${value}= Remove String ${value} ${element}-\{
245 ${value}= Remove String ${value} \}
246 log ${value}
247 [Return] ${value}
248
TorstenThieme17756ea2020-11-11 14:09:47 +0000249Validate Onu Id
250 [Documentation] This keyword validates ONU Id of passed etcd data.
251 [Arguments] ${value}
Girish Gowdra295c1692020-11-19 10:51:53 -0800252 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
253 # When testing multi-tcont this may need some adjustment.
254 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000255 ${tppathlines}= Replace String ${tp_path} / \n
256 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
257 ${onu_id}= Get From Dictionary ${value} onu_id
258 Should Be Equal As Integers ${onu} ${onu_id}
259 ... msg=Onu-Id (${onu_id}) does not match onu (${onu}) from tp_path in etcd data!
260 Should Be True ${onu_id}>=1
261
262Validate Uni Id
263 [Documentation] This keyword validates UNI Id of passed etcd data.
264 [Arguments] ${value}
Girish Gowdra295c1692020-11-19 10:51:53 -0800265 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
266 # When testing multi-tcont this may need some adjustment.
267 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000268 ${tppathlines}= Replace String ${tp_path} / \n
269 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
270 ${uni_id}= Get From Dictionary ${value['uni_config'][0]} uni_id
271 Should Be Equal As Integers ${uni} ${uni_id}
272 ... msg=Uni-Id (${uni_id}) does not match onu (${uni}) from tp_path in etcd data!
TorstenThieme52ef8392020-11-10 13:42:26 +0000273
TorstenThiemed4f48962020-12-08 12:17:19 +0000274Get Stack Name
275 [Documentation] This keyword delivers the stack name read from environment variable NAME if present.
276 ${env_name}= Get Environment Variable NAME default=${defaultstackname}
277 # while Get Environment Variable does not work correctly, a manual correction follows
278 ${env_name}= Set Variable If "${env_name}"=="${EMPTY}" ${defaultstackname} ${env_name}
279 [Return] ${env_name}
280
281Wait for Ports in ONOS for all OLTs
282 [Documentation] Waits untill a certain number of ports are enabled in all ONOS
283 [Arguments] ${onos_ssh_connection} ${count} ${filter} ${max_wait_time}=10m
284 FOR ${J} IN RANGE 0 ${num_olts}
285 ${olt_serial_number}= Set Variable ${list_olts}[${J}][sn]
286 ${onu_count}= Set Variable ${list_olts}[${J}][onucount]
287 ${of_id}= Wait Until Keyword Succeeds ${timeout} 15s Validate OLT Device in ONOS
288 ... ${olt_serial_number}
289 Set Global Variable ${of_id}
290 Wait for Ports in ONOS ${onos_ssh_connection} ${count} ${of_id} BBSM ${max_wait_time}
291 END
292
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000293Map State
294 [Documentation] This keyword converts the passed numeric value or name of a onu state to its state values.
295 [Arguments] ${state}
296 # create state lists with corresponding return values
297 # ADMIN-STATE OPER-STATUS CONNECT-STATUS ONU-STATE (number/name)
298 ${state1} Create List ENABLED ACTIVATING REACHABLE 1 activating-onu
299 ${state2} Create List ENABLED ACTIVATING REACHABLE 2 starting-openomci
300 ${state3} Create List ENABLED ACTIVATING REACHABLE 3 discovery-mibsync-complete
301 ${state4} Create List ENABLED ACTIVE REACHABLE 4 initial-mib-downloaded
302 ${state5} Create List ENABLED ACTIVE REACHABLE 5 tech-profile-config-download-success
303 ${state6} Create List ENABLED ACTIVE REACHABLE 6 omci-flows-pushed
304 ${state7} Create List DISABLED UNKNOWN REACHABLE 7 omci-admin-lock
305 ${state8} Create List ENABLED ACTIVE REACHABLE 8 onu-reenabled
306 ${state9} Create List ENABLED DISCOVERED UNREACHABLE 9 stopping-openomci
307 ${state10} Create List ENABLED DISCOVERED REACHABLE 10 rebooting
308 ${state11} Create List ENABLED DISCOVERED REACHABLE 11 omci-flows-deleted
309 ${state12} Create List DISABLED UNKNOWN REACHABLE 12 tech-profile-config-delete-success
310 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Set Variable If
311 ... '${state}'=='1' or '${state}'=='activating-onu' ${state1}
312 ... '${state}'=='2' or '${state}'=='starting-openomci' ${state2}
313 ... '${state}'=='3' or '${state}'=='discovery-mibsync-complete' ${state3}
314 ... '${state}'=='4' or '${state}'=='initial-mib-downloaded' ${state4}
315 ... '${state}'=='5' or '${state}'=='tech-profile-config-download-success' ${state5}
316 ... '${state}'=='6' or '${state}'=='omci-flows-pushed' ${state6}
317 ... '${state}'=='7' or '${state}'=='omci-admin-lock' ${state7}
318 ... '${state}'=='8' or '${state}'=='onu-reenabled' ${state8}
319 ... '${state}'=='9' or '${state}'=='stopping-openomci' ${state9}
320 ... '${state}'=='10' or '${state}'=='rebooting' ${state10}
321 ... '${state}'=='11' or '${state}'=='omci-flows-deleted' ${state11}
322 ... '${state}'=='12' or '${state}'=='tech-profile-config-delete-success' ${state12}
323 [Return] ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}