blob: 53ce5ec037c61561af7effecf5cc2f7d6ca80f10 [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
93 ${stackname}= Get Stack Name
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000094 ${commandget} Catenate
TorstenThiemed4f48962020-12-08 12:17:19 +000095 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/${stackname}/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +000096 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000097 Should Not Be Empty ${result} No MIB Template Data stored in etcd!
98
99Delete MIB Template Data
100 [Documentation] This keyword deletes MIB Template Data stored in etcd
101 ${namespace}= Set Variable default
102 ${podname}= Set Variable etcd
TorstenThiemed4f48962020-12-08 12:17:19 +0000103 ${stackname}= Get Stack Name
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000104 ${commanddel} Catenate
TorstenThiemed4f48962020-12-08 12:17:19 +0000105 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/${stackname}/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000106 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commanddel}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000107 Sleep 3s
108 ${commandget} Catenate
TorstenThiemed4f48962020-12-08 12:17:19 +0000109 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/${stackname}/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000110 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000111 Should Be Empty ${result} Could not delete MIB Template Data stored in etcd!
112
TorstenThieme17756ea2020-11-11 14:09:47 +0000113Validate Onu Data In Etcd
114 [Documentation] This keyword validates openonu-go-adapter Data stored in etcd.
115 ... It checks unique of serial_number and combination of pon, onu and uni in tp_path.
116 ... Furthermore it evaluates the values of onu_id and uni_id with values read from tp_path.
117 ... Number of etcd entries has to match with the passed number.
118 [Arguments] ${nbofetcddata}=${num_all_onus}
TorstenThiemed4f48962020-12-08 12:17:19 +0000119 ${stackname}= Get Stack Name
TorstenThieme17756ea2020-11-11 14:09:47 +0000120 ${etcddata}= Get ONU Go Adapter ETCD Data
TorstenThiemed4f48962020-12-08 12:17:19 +0000121 ${etcddata}= Remove Lines Containing String ${etcddata} service/${stackname}/openonu \n
TorstenThieme17756ea2020-11-11 14:09:47 +0000122 #prepare result for json convert
123 ${result}= Prepare ONU Go Adapter ETCD Data For Json ${etcddata}
124 ${jsondata}= To Json ${result}
125 ${length}= Get Length ${jsondata}
126 log ${jsondata}
127 Run Keyword And Continue On Failure Should Be Equal As Integers ${length} ${nbofetcddata}
128 ... msg=Number etcd data (${length}) does not match required (${nbofetcddata})!
129 ${pononuuniidlist}= Create List
130 ${serialnumberlist}= Create List
131 FOR ${INDEX} IN RANGE 0 ${length}
132 ${value}= Get From List ${jsondata} ${INDEX}
Girish Gowdra97f8d062020-11-17 15:48:23 -0800133 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
134 # When testing multi-tcont this may need some adjustment.
135 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000136 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
137 ${list_id}= Get Index From List ${pononuuniidlist} ${pononuuniid}
138 Should Be Equal As Integers ${list_id} -1
139 ... msg=Combination of Pon, Onu and Uni (${pononuuniid}) exist multiple in etcd data!
140 Append To List ${pononuuniidlist} ${pononuuniid}
141 Validate Onu Id ${value}
142 Validate Uni Id ${value}
143 ${serial_number}= Get From Dictionary ${value} serial_number
144 ${list_id}= Get Index From List ${serialnumberlist} ${serial_number}
145 Should Be Equal As Integers ${list_id} -1
146 ... msg=Serial number (${serial_number}) exists multiple in etcd data!
147 Append To List ${serialnumberlist} ${serial_number}
148 END
149
TorstenThieme52ef8392020-11-10 13:42:26 +0000150Validate Vlan Rules In Etcd
151 [Documentation] This keyword validates Vlan rules of openonu-go-adapter Data stored in etcd.
152 ... It checks the given number of cookie_slice, match_vid (=4096) and set_vid.
153 ... Furthermore it returns a list of all set_vid.
154 ... In case of a passed dictionary containing set_vids these will be checked for to
155 ... current set-vid depending on setvidequal (True=equal, False=not equal).
156 [Arguments] ${nbofcookieslice}=1 ${reqmatchvid}=4096 ${prevvlanrules}=${NONE} ${setvidequal}=False
TorstenThiemed4f48962020-12-08 12:17:19 +0000157 ${stackname}= Get Stack Name
TorstenThieme52ef8392020-11-10 13:42:26 +0000158 ${etcddata}= Get ONU Go Adapter ETCD Data
TorstenThiemed4f48962020-12-08 12:17:19 +0000159 ${etcddata}= Remove Lines Containing String ${etcddata} service/${stackname}/openonu \n
TorstenThieme52ef8392020-11-10 13:42:26 +0000160 #prepare result for json convert
161 ${result}= Prepare ONU Go Adapter ETCD Data For Json ${etcddata}
162 ${jsondata}= To Json ${result}
163 ${length}= Get Length ${jsondata}
164 log ${jsondata}
165 ${vlan_rules}= Create Dictionary
166 FOR ${INDEX} IN RANGE 0 ${length}
167 ${value}= Get From List ${jsondata} ${INDEX}
Girish Gowdra295c1692020-11-19 10:51:53 -0800168 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
169 # When testing multi-tcont this may need some adjustment.
170 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme52ef8392020-11-10 13:42:26 +0000171 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
172 ${cookieslice}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]} cookie_slice
173 #@{cookieslicelist}= Split String ${cookieslice} ,
174 ${foundcookieslices}= Get Length ${cookieslice}
175 Should Be Equal As Integers ${foundcookieslices} ${nbofcookieslice}
176 ${matchvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
177 ... match_vid
178 Should Be Equal As Integers ${matchvid} ${reqmatchvid}
179 ${setvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
180 ... set_vid
181 ${evalresult}= Evaluate 2 <= ${setvid} <= 4095
182 Should Be True ${evalresult} msg=set_vid out of range (${setvid})!
183 Set To Dictionary ${vlan_rules} ${pononuuniid} ${setvid}
184 ${oldsetvidvalid} Set Variable If ${prevvlanrules} is ${NONE} False True
185 ${prevsetvid}= Set Variable If ${oldsetvidvalid} ${prevvlanrules['${pononuuniid}']}
186 Run Keyword If ${oldsetvidvalid} and ${setvidequal}
187 ... Should Be Equal As Integers ${prevsetvid} ${setvid}
188 ... ELSE IF ${oldsetvidvalid} and not ${setvidequal}
189 ... Should Not Be Equal As Integers ${prevsetvid} ${setvid}
190 END
191 log Many ${vlan_rules}
192 [Return] ${vlan_rules}
193
194Get ONU Go Adapter ETCD Data
195 [Documentation] This keyword delivers openonu-go-adapter Data stored in etcd
196 ${namespace}= Set Variable default
197 ${podname}= Set Variable etcd
TorstenThiemed4f48962020-12-08 12:17:19 +0000198 ${stackname}= Get Stack Name
TorstenThieme52ef8392020-11-10 13:42:26 +0000199 ${commandget} Catenate
TorstenThiemed4f48962020-12-08 12:17:19 +0000200 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix --prefix service/${stackname}/openonu'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000201 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThieme52ef8392020-11-10 13:42:26 +0000202 log ${result}
203 [Return] ${result}
204
205Prepare ONU Go Adapter ETCD Data For Json
206 [Documentation] This keyword prepares openonu-go-adapter Data stored in etcd for converting
207 ... to json
208 [Arguments] ${etcddata}
209 #prepare result for json convert
210 ${prepresult}= Replace String ${etcddata} \n ,
211 ${prepresult}= Strip String ${prepresult} mode=right characters=,
212 ${prepresult}= Set Variable [${prepresult}]
213 log ${prepresult}
214 [Return] ${prepresult}
215
216Remove Lines Containing String
217 [Documentation] This keyword deletes all lines from given string containing passed remove string
218 [Arguments] ${string} ${toremove} ${appendtoremoveline}
219 ${lines}= Get Lines Containing String ${string} ${toremove}
220 ${length}= Get Line Count ${lines}
221 ${firstline}= Set Variable False
222 FOR ${INDEX} IN RANGE 0 ${length}
223 ${String2remove} Get Line ${lines} ${INDEX}
224 ${String2remove} Set Variable ${String2remove}${appendtoremoveline}
225 ${string}= Remove String ${string} ${String2remove}
226 END
227 log ${string}
228 [Return] ${string}
229
230Read Pon Onu Uni String
231 [Documentation] This keyword builds a thre digit string using Pon, Onu and Uni value of given tp-path taken
232 ... taken from etcd data of onu go adapter
233 [Arguments] ${tp_path}
TorstenThieme52ef8392020-11-10 13:42:26 +0000234 ${tppathlines}= Replace String ${tp_path} / \n
235 ${pon}= Get Value Of Tp Path Element ${tppathlines} pon
236 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
237 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
238 ${valuesid}= Set Variable ${pon}/${onu}/${uni}
239 log ${valuesid}
240 [Return] ${valuesid}
241
242Get Value Of Tp Path Element
TorstenThieme17756ea2020-11-11 14:09:47 +0000243 [Documentation] This keyword delivers numeric value of given tp path element.
TorstenThieme52ef8392020-11-10 13:42:26 +0000244 [Arguments] ${tp_path_lines} ${element}
245 ${value}= Get Lines Containing String ${tp_path_lines} ${element}-\{
246 ${value}= Remove String ${value} ${element}-\{
247 ${value}= Remove String ${value} \}
248 log ${value}
249 [Return] ${value}
250
TorstenThieme17756ea2020-11-11 14:09:47 +0000251Validate Onu Id
252 [Documentation] This keyword validates ONU Id of passed etcd data.
253 [Arguments] ${value}
Girish Gowdra295c1692020-11-19 10:51:53 -0800254 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
255 # When testing multi-tcont this may need some adjustment.
256 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000257 ${tppathlines}= Replace String ${tp_path} / \n
258 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
259 ${onu_id}= Get From Dictionary ${value} onu_id
260 Should Be Equal As Integers ${onu} ${onu_id}
261 ... msg=Onu-Id (${onu_id}) does not match onu (${onu}) from tp_path in etcd data!
262 Should Be True ${onu_id}>=1
263
264Validate Uni Id
265 [Documentation] This keyword validates UNI Id of passed etcd data.
266 [Arguments] ${value}
Girish Gowdra295c1692020-11-19 10:51:53 -0800267 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
268 # When testing multi-tcont this may need some adjustment.
269 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000270 ${tppathlines}= Replace String ${tp_path} / \n
271 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
272 ${uni_id}= Get From Dictionary ${value['uni_config'][0]} uni_id
273 Should Be Equal As Integers ${uni} ${uni_id}
274 ... msg=Uni-Id (${uni_id}) does not match onu (${uni}) from tp_path in etcd data!
TorstenThieme52ef8392020-11-10 13:42:26 +0000275
TorstenThiemed4f48962020-12-08 12:17:19 +0000276Get Stack Name
277 [Documentation] This keyword delivers the stack name read from environment variable NAME if present.
278 ${env_name}= Get Environment Variable NAME default=${defaultstackname}
279 # while Get Environment Variable does not work correctly, a manual correction follows
280 ${env_name}= Set Variable If "${env_name}"=="${EMPTY}" ${defaultstackname} ${env_name}
281 [Return] ${env_name}
282
283Wait for Ports in ONOS for all OLTs
284 [Documentation] Waits untill a certain number of ports are enabled in all ONOS
285 [Arguments] ${onos_ssh_connection} ${count} ${filter} ${max_wait_time}=10m
286 FOR ${J} IN RANGE 0 ${num_olts}
287 ${olt_serial_number}= Set Variable ${list_olts}[${J}][sn]
288 ${onu_count}= Set Variable ${list_olts}[${J}][onucount]
289 ${of_id}= Wait Until Keyword Succeeds ${timeout} 15s Validate OLT Device in ONOS
290 ... ${olt_serial_number}
291 Set Global Variable ${of_id}
292 Wait for Ports in ONOS ${onos_ssh_connection} ${count} ${of_id} BBSM ${max_wait_time}
293 END
294
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000295Map State
296 [Documentation] This keyword converts the passed numeric value or name of a onu state to its state values.
297 [Arguments] ${state}
298 # create state lists with corresponding return values
299 # ADMIN-STATE OPER-STATUS CONNECT-STATUS ONU-STATE (number/name)
300 ${state1} Create List ENABLED ACTIVATING REACHABLE 1 activating-onu
301 ${state2} Create List ENABLED ACTIVATING REACHABLE 2 starting-openomci
302 ${state3} Create List ENABLED ACTIVATING REACHABLE 3 discovery-mibsync-complete
303 ${state4} Create List ENABLED ACTIVE REACHABLE 4 initial-mib-downloaded
304 ${state5} Create List ENABLED ACTIVE REACHABLE 5 tech-profile-config-download-success
305 ${state6} Create List ENABLED ACTIVE REACHABLE 6 omci-flows-pushed
306 ${state7} Create List DISABLED UNKNOWN REACHABLE 7 omci-admin-lock
307 ${state8} Create List ENABLED ACTIVE REACHABLE 8 onu-reenabled
308 ${state9} Create List ENABLED DISCOVERED UNREACHABLE 9 stopping-openomci
309 ${state10} Create List ENABLED DISCOVERED REACHABLE 10 rebooting
310 ${state11} Create List ENABLED DISCOVERED REACHABLE 11 omci-flows-deleted
311 ${state12} Create List DISABLED UNKNOWN REACHABLE 12 tech-profile-config-delete-success
312 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Set Variable If
313 ... '${state}'=='1' or '${state}'=='activating-onu' ${state1}
314 ... '${state}'=='2' or '${state}'=='starting-openomci' ${state2}
315 ... '${state}'=='3' or '${state}'=='discovery-mibsync-complete' ${state3}
316 ... '${state}'=='4' or '${state}'=='initial-mib-downloaded' ${state4}
317 ... '${state}'=='5' or '${state}'=='tech-profile-config-download-success' ${state5}
318 ... '${state}'=='6' or '${state}'=='omci-flows-pushed' ${state6}
319 ... '${state}'=='7' or '${state}'=='omci-admin-lock' ${state7}
320 ... '${state}'=='8' or '${state}'=='onu-reenabled' ${state8}
321 ... '${state}'=='9' or '${state}'=='stopping-openomci' ${state9}
322 ... '${state}'=='10' or '${state}'=='rebooting' ${state10}
323 ... '${state}'=='11' or '${state}'=='omci-flows-deleted' ${state11}
324 ... '${state}'=='12' or '${state}'=='tech-profile-config-delete-success' ${state12}
325 [Return] ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}