blob: 1ff38d59defa29cfde02420334bd3c9be566ccc3 [file] [log] [blame]
TorstenThiemefd7e7ba2020-11-06 13:57:57 +00001# Copyright 2020-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# voltctl common functions
15
16*** Settings ***
17Documentation Library for various openonu-go-adpter utilities
18
19*** Keywords ***
20Do Power On ONU Device
21 [Documentation] This keyword power on all onus.
22 ${namespace}= Set Variable voltha
23 FOR ${I} IN RANGE 0 ${num_all_onus}
24 ${src}= Set Variable ${hosts.src[${I}]}
Holger Hildebrandt23147742020-11-16 10:13:21 +000025 ${result}= Exec Pod In Kube ${namespace} bbsim bbsimctl onu poweron ${src['onu']}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000026 Should Contain ${result} successfully msg=Can not poweron ${src['onu']} values=False
27 END
28
29Do Current State Test
30 [Documentation] This keyword checks the passed state of the given onu.
31 [Arguments] ${state} ${onu} ${reqadminstate}=${EMPTY} ${reqoperstatus}=${EMPTY}
32 ... ${reqconnectstatus}=${EMPTY}
33 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Map State ${state}
34 ${admin_state}= Set Variable If '${reqadminstate}'!='${EMPTY}' ${reqadminstate} ${admin_state}
35 ${oper_status}= Set Variable If '${reqoperstatus}'!='${EMPTY}' ${reqoperstatus} ${oper_status}
36 ${connect_status}= Set Variable If '${reqconnectstatus}'!='${EMPTY}' ${reqconnectstatus}
37 ... ${connect_status}
38 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
39 ... Validate Device ${admin_state} ${oper_status} ${connect_status}
40 ... ${onu} onu=True onu_reason=${onu_state}
41
42Do Current State Test All Onus
43 [Documentation] This keyword checks the passed state of all onus.
44 ... Hint: ${timeStart} will be not evaluated here!
45 [Arguments] ${state} ${reqadminstate}=${EMPTY} ${reqoperstatus}=${EMPTY} ${reqconnectstatus}=${EMPTY}
46 ... ${alternativeonustate}=${EMPTY}
47 ${list_onus} Create List
48 Build ONU SN List ${list_onus}
49 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Map State ${state}
50 ${admin_state}= Set Variable If '${reqadminstate}'!='${EMPTY}' ${reqadminstate} ${admin_state}
51 ${oper_status}= Set Variable If '${reqoperstatus}'!='${EMPTY}' ${reqoperstatus} ${oper_status}
52 ${connect_status}= Set Variable If '${reqconnectstatus}'!='${EMPTY}' ${reqconnectstatus}
53 ... ${connect_status}
54 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
55 ... Validate ONU Devices With Duration
56 ... ${admin_state} ${oper_status} ${connect_status}
TorstenThieme52ef8392020-11-10 13:42:26 +000057 ... ${onu_state} ${list_onus} ${timeStart} alternate_reason=${alternativeonustate}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000058
59Do Current Reason Test All Onus
60 [Documentation] This keyword checks the passed state of all onus.
61 ... Hint: ${timeStart} will be not evaluated here!
62 [Arguments] ${state}
63 ${list_onus} Create List
64 Build ONU SN List ${list_onus}
65 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Map State ${state}
66 Run Keyword And Continue On Failure Wait Until Keyword Succeeds ${timeout} 50ms
67 ... Validate ONU Devices MIB State With Duration
68 ... ${onu_state} ${list_onus} ${timeStart}
69
70Log Ports
71 [Documentation] This keyword logs all port data available in ONOS of first port per ONU
72 [Arguments] ${onlyenabled}=False
73 ${cmd} Set Variable If ${onlyenabled} ports -e ports
74 ${onu_ports}= Execute ONOS CLI Command on open connection ${onos_ssh_connection} ${cmd}
75 ${lines} = Get Lines Matching Regexp ${onu_ports} .*portName=BBSM[0-9]{8}-1
76 Log ${lines}
77
78Kill Adaptor
79 [Documentation] This keyword kills the passed adaptor.
80 [Arguments] ${namespace} ${name}
81 ${cmd} Catenate
82 ... kubectl exec -it -n voltha $(kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}')
83 ... -- /bin/sh -c "kill 1"
84 ${rc} ${output}= Run and Return Rc and Output ${cmd}
85 Log ${output}
86
87Verify MIB Template Data Available
88 [Documentation] This keyword verifies MIB Template Data stored in etcd
89 ${namespace}= Set Variable default
90 ${podname}= Set Variable etcd
91 ${commandget} Catenate
92 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +000093 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +000094 Should Not Be Empty ${result} No MIB Template Data stored in etcd!
95
96Delete MIB Template Data
97 [Documentation] This keyword deletes MIB Template Data stored in etcd
98 ${namespace}= Set Variable default
99 ${podname}= Set Variable etcd
100 ${commanddel} Catenate
101 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/voltha/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000102 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commanddel}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000103 Sleep 3s
104 ${commandget} Catenate
105 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000106 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000107 Should Be Empty ${result} Could not delete MIB Template Data stored in etcd!
108
TorstenThieme17756ea2020-11-11 14:09:47 +0000109Validate Onu Data In Etcd
110 [Documentation] This keyword validates openonu-go-adapter Data stored in etcd.
111 ... It checks unique of serial_number and combination of pon, onu and uni in tp_path.
112 ... Furthermore it evaluates the values of onu_id and uni_id with values read from tp_path.
113 ... Number of etcd entries has to match with the passed number.
114 [Arguments] ${nbofetcddata}=${num_all_onus}
115 ${etcddata}= Get ONU Go Adapter ETCD Data
116 ${etcddata}= Remove Lines Containing String ${etcddata} service/voltha/openonu \n
117 #prepare result for json convert
118 ${result}= Prepare ONU Go Adapter ETCD Data For Json ${etcddata}
119 ${jsondata}= To Json ${result}
120 ${length}= Get Length ${jsondata}
121 log ${jsondata}
122 Run Keyword And Continue On Failure Should Be Equal As Integers ${length} ${nbofetcddata}
123 ... msg=Number etcd data (${length}) does not match required (${nbofetcddata})!
124 ${pononuuniidlist}= Create List
125 ${serialnumberlist}= Create List
126 FOR ${INDEX} IN RANGE 0 ${length}
127 ${value}= Get From List ${jsondata} ${INDEX}
Girish Gowdra97f8d062020-11-17 15:48:23 -0800128 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
129 # When testing multi-tcont this may need some adjustment.
130 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000131 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
132 ${list_id}= Get Index From List ${pononuuniidlist} ${pononuuniid}
133 Should Be Equal As Integers ${list_id} -1
134 ... msg=Combination of Pon, Onu and Uni (${pononuuniid}) exist multiple in etcd data!
135 Append To List ${pononuuniidlist} ${pononuuniid}
136 Validate Onu Id ${value}
137 Validate Uni Id ${value}
138 ${serial_number}= Get From Dictionary ${value} serial_number
139 ${list_id}= Get Index From List ${serialnumberlist} ${serial_number}
140 Should Be Equal As Integers ${list_id} -1
141 ... msg=Serial number (${serial_number}) exists multiple in etcd data!
142 Append To List ${serialnumberlist} ${serial_number}
143 END
144
TorstenThieme52ef8392020-11-10 13:42:26 +0000145Validate Vlan Rules In Etcd
146 [Documentation] This keyword validates Vlan rules of openonu-go-adapter Data stored in etcd.
147 ... It checks the given number of cookie_slice, match_vid (=4096) and set_vid.
148 ... Furthermore it returns a list of all set_vid.
149 ... In case of a passed dictionary containing set_vids these will be checked for to
150 ... current set-vid depending on setvidequal (True=equal, False=not equal).
151 [Arguments] ${nbofcookieslice}=1 ${reqmatchvid}=4096 ${prevvlanrules}=${NONE} ${setvidequal}=False
152 ${etcddata}= Get ONU Go Adapter ETCD Data
153 ${etcddata}= Remove Lines Containing String ${etcddata} service/voltha/openonu \n
154 #prepare result for json convert
155 ${result}= Prepare ONU Go Adapter ETCD Data For Json ${etcddata}
156 ${jsondata}= To Json ${result}
157 ${length}= Get Length ${jsondata}
158 log ${jsondata}
159 ${vlan_rules}= Create Dictionary
160 FOR ${INDEX} IN RANGE 0 ${length}
161 ${value}= Get From List ${jsondata} ${INDEX}
Girish Gowdra295c1692020-11-19 10:51:53 -0800162 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
163 # When testing multi-tcont this may need some adjustment.
164 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme52ef8392020-11-10 13:42:26 +0000165 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
166 ${cookieslice}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]} cookie_slice
167 #@{cookieslicelist}= Split String ${cookieslice} ,
168 ${foundcookieslices}= Get Length ${cookieslice}
169 Should Be Equal As Integers ${foundcookieslices} ${nbofcookieslice}
170 ${matchvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
171 ... match_vid
172 Should Be Equal As Integers ${matchvid} ${reqmatchvid}
173 ${setvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
174 ... set_vid
175 ${evalresult}= Evaluate 2 <= ${setvid} <= 4095
176 Should Be True ${evalresult} msg=set_vid out of range (${setvid})!
177 Set To Dictionary ${vlan_rules} ${pononuuniid} ${setvid}
178 ${oldsetvidvalid} Set Variable If ${prevvlanrules} is ${NONE} False True
179 ${prevsetvid}= Set Variable If ${oldsetvidvalid} ${prevvlanrules['${pononuuniid}']}
180 Run Keyword If ${oldsetvidvalid} and ${setvidequal}
181 ... Should Be Equal As Integers ${prevsetvid} ${setvid}
182 ... ELSE IF ${oldsetvidvalid} and not ${setvidequal}
183 ... Should Not Be Equal As Integers ${prevsetvid} ${setvid}
184 END
185 log Many ${vlan_rules}
186 [Return] ${vlan_rules}
187
188Get ONU Go Adapter ETCD Data
189 [Documentation] This keyword delivers openonu-go-adapter Data stored in etcd
190 ${namespace}= Set Variable default
191 ${podname}= Set Variable etcd
192 ${commandget} Catenate
193 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix --prefix service/voltha/openonu'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000194 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThieme52ef8392020-11-10 13:42:26 +0000195 log ${result}
196 [Return] ${result}
197
198Prepare ONU Go Adapter ETCD Data For Json
199 [Documentation] This keyword prepares openonu-go-adapter Data stored in etcd for converting
200 ... to json
201 [Arguments] ${etcddata}
202 #prepare result for json convert
203 ${prepresult}= Replace String ${etcddata} \n ,
204 ${prepresult}= Strip String ${prepresult} mode=right characters=,
205 ${prepresult}= Set Variable [${prepresult}]
206 log ${prepresult}
207 [Return] ${prepresult}
208
209Remove Lines Containing String
210 [Documentation] This keyword deletes all lines from given string containing passed remove string
211 [Arguments] ${string} ${toremove} ${appendtoremoveline}
212 ${lines}= Get Lines Containing String ${string} ${toremove}
213 ${length}= Get Line Count ${lines}
214 ${firstline}= Set Variable False
215 FOR ${INDEX} IN RANGE 0 ${length}
216 ${String2remove} Get Line ${lines} ${INDEX}
217 ${String2remove} Set Variable ${String2remove}${appendtoremoveline}
218 ${string}= Remove String ${string} ${String2remove}
219 END
220 log ${string}
221 [Return] ${string}
222
223Read Pon Onu Uni String
224 [Documentation] This keyword builds a thre digit string using Pon, Onu and Uni value of given tp-path taken
225 ... taken from etcd data of onu go adapter
226 [Arguments] ${tp_path}
TorstenThieme52ef8392020-11-10 13:42:26 +0000227 ${tppathlines}= Replace String ${tp_path} / \n
228 ${pon}= Get Value Of Tp Path Element ${tppathlines} pon
229 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
230 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
231 ${valuesid}= Set Variable ${pon}/${onu}/${uni}
232 log ${valuesid}
233 [Return] ${valuesid}
234
235Get Value Of Tp Path Element
TorstenThieme17756ea2020-11-11 14:09:47 +0000236 [Documentation] This keyword delivers numeric value of given tp path element.
TorstenThieme52ef8392020-11-10 13:42:26 +0000237 [Arguments] ${tp_path_lines} ${element}
238 ${value}= Get Lines Containing String ${tp_path_lines} ${element}-\{
239 ${value}= Remove String ${value} ${element}-\{
240 ${value}= Remove String ${value} \}
241 log ${value}
242 [Return] ${value}
243
TorstenThieme17756ea2020-11-11 14:09:47 +0000244Validate Onu Id
245 [Documentation] This keyword validates ONU Id of passed etcd data.
246 [Arguments] ${value}
Girish Gowdra295c1692020-11-19 10:51:53 -0800247 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
248 # When testing multi-tcont this may need some adjustment.
249 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000250 ${tppathlines}= Replace String ${tp_path} / \n
251 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
252 ${onu_id}= Get From Dictionary ${value} onu_id
253 Should Be Equal As Integers ${onu} ${onu_id}
254 ... msg=Onu-Id (${onu_id}) does not match onu (${onu}) from tp_path in etcd data!
255 Should Be True ${onu_id}>=1
256
257Validate Uni Id
258 [Documentation] This keyword validates UNI Id of passed etcd data.
259 [Arguments] ${value}
Girish Gowdra295c1692020-11-19 10:51:53 -0800260 # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
261 # When testing multi-tcont this may need some adjustment.
262 ${tp_path}= Get From Dictionary ${value['uni_config'][0]['PersTpPathMap']} 64
TorstenThieme17756ea2020-11-11 14:09:47 +0000263 ${tppathlines}= Replace String ${tp_path} / \n
264 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
265 ${uni_id}= Get From Dictionary ${value['uni_config'][0]} uni_id
266 Should Be Equal As Integers ${uni} ${uni_id}
267 ... msg=Uni-Id (${uni_id}) does not match onu (${uni}) from tp_path in etcd data!
TorstenThieme52ef8392020-11-10 13:42:26 +0000268
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000269Map State
270 [Documentation] This keyword converts the passed numeric value or name of a onu state to its state values.
271 [Arguments] ${state}
272 # create state lists with corresponding return values
273 # ADMIN-STATE OPER-STATUS CONNECT-STATUS ONU-STATE (number/name)
274 ${state1} Create List ENABLED ACTIVATING REACHABLE 1 activating-onu
275 ${state2} Create List ENABLED ACTIVATING REACHABLE 2 starting-openomci
276 ${state3} Create List ENABLED ACTIVATING REACHABLE 3 discovery-mibsync-complete
277 ${state4} Create List ENABLED ACTIVE REACHABLE 4 initial-mib-downloaded
278 ${state5} Create List ENABLED ACTIVE REACHABLE 5 tech-profile-config-download-success
279 ${state6} Create List ENABLED ACTIVE REACHABLE 6 omci-flows-pushed
280 ${state7} Create List DISABLED UNKNOWN REACHABLE 7 omci-admin-lock
281 ${state8} Create List ENABLED ACTIVE REACHABLE 8 onu-reenabled
282 ${state9} Create List ENABLED DISCOVERED UNREACHABLE 9 stopping-openomci
283 ${state10} Create List ENABLED DISCOVERED REACHABLE 10 rebooting
284 ${state11} Create List ENABLED DISCOVERED REACHABLE 11 omci-flows-deleted
285 ${state12} Create List DISABLED UNKNOWN REACHABLE 12 tech-profile-config-delete-success
286 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Set Variable If
287 ... '${state}'=='1' or '${state}'=='activating-onu' ${state1}
288 ... '${state}'=='2' or '${state}'=='starting-openomci' ${state2}
289 ... '${state}'=='3' or '${state}'=='discovery-mibsync-complete' ${state3}
290 ... '${state}'=='4' or '${state}'=='initial-mib-downloaded' ${state4}
291 ... '${state}'=='5' or '${state}'=='tech-profile-config-download-success' ${state5}
292 ... '${state}'=='6' or '${state}'=='omci-flows-pushed' ${state6}
293 ... '${state}'=='7' or '${state}'=='omci-admin-lock' ${state7}
294 ... '${state}'=='8' or '${state}'=='onu-reenabled' ${state8}
295 ... '${state}'=='9' or '${state}'=='stopping-openomci' ${state9}
296 ... '${state}'=='10' or '${state}'=='rebooting' ${state10}
297 ... '${state}'=='11' or '${state}'=='omci-flows-deleted' ${state11}
298 ... '${state}'=='12' or '${state}'=='tech-profile-config-delete-success' ${state12}
299 [Return] ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}