blob: edb7a368ded05e64d7bf4cb954d2f1ac4ee7d582 [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}
162 ${tp_path}= Get From Dictionary ${value['uni_config'][0]} tp_path
163 ${pononuuniid}= Read Pon Onu Uni String ${tp_path}
164 ${cookieslice}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]} cookie_slice
165 #@{cookieslicelist}= Split String ${cookieslice} ,
166 ${foundcookieslices}= Get Length ${cookieslice}
167 Should Be Equal As Integers ${foundcookieslices} ${nbofcookieslice}
168 ${matchvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
169 ... match_vid
170 Should Be Equal As Integers ${matchvid} ${reqmatchvid}
171 ${setvid}= Get From Dictionary ${value['uni_config'][0]['flow_params'][0]['vlan_rule_params']}
172 ... set_vid
173 ${evalresult}= Evaluate 2 <= ${setvid} <= 4095
174 Should Be True ${evalresult} msg=set_vid out of range (${setvid})!
175 Set To Dictionary ${vlan_rules} ${pononuuniid} ${setvid}
176 ${oldsetvidvalid} Set Variable If ${prevvlanrules} is ${NONE} False True
177 ${prevsetvid}= Set Variable If ${oldsetvidvalid} ${prevvlanrules['${pononuuniid}']}
178 Run Keyword If ${oldsetvidvalid} and ${setvidequal}
179 ... Should Be Equal As Integers ${prevsetvid} ${setvid}
180 ... ELSE IF ${oldsetvidvalid} and not ${setvidequal}
181 ... Should Not Be Equal As Integers ${prevsetvid} ${setvid}
182 END
183 log Many ${vlan_rules}
184 [Return] ${vlan_rules}
185
186Get ONU Go Adapter ETCD Data
187 [Documentation] This keyword delivers openonu-go-adapter Data stored in etcd
188 ${namespace}= Set Variable default
189 ${podname}= Set Variable etcd
190 ${commandget} Catenate
191 ... /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix --prefix service/voltha/openonu'
Holger Hildebrandt23147742020-11-16 10:13:21 +0000192 ${result}= Exec Pod In Kube ${namespace} ${podname} ${commandget}
TorstenThieme52ef8392020-11-10 13:42:26 +0000193 log ${result}
194 [Return] ${result}
195
196Prepare ONU Go Adapter ETCD Data For Json
197 [Documentation] This keyword prepares openonu-go-adapter Data stored in etcd for converting
198 ... to json
199 [Arguments] ${etcddata}
200 #prepare result for json convert
201 ${prepresult}= Replace String ${etcddata} \n ,
202 ${prepresult}= Strip String ${prepresult} mode=right characters=,
203 ${prepresult}= Set Variable [${prepresult}]
204 log ${prepresult}
205 [Return] ${prepresult}
206
207Remove Lines Containing String
208 [Documentation] This keyword deletes all lines from given string containing passed remove string
209 [Arguments] ${string} ${toremove} ${appendtoremoveline}
210 ${lines}= Get Lines Containing String ${string} ${toremove}
211 ${length}= Get Line Count ${lines}
212 ${firstline}= Set Variable False
213 FOR ${INDEX} IN RANGE 0 ${length}
214 ${String2remove} Get Line ${lines} ${INDEX}
215 ${String2remove} Set Variable ${String2remove}${appendtoremoveline}
216 ${string}= Remove String ${string} ${String2remove}
217 END
218 log ${string}
219 [Return] ${string}
220
221Read Pon Onu Uni String
222 [Documentation] This keyword builds a thre digit string using Pon, Onu and Uni value of given tp-path taken
223 ... taken from etcd data of onu go adapter
224 [Arguments] ${tp_path}
TorstenThieme52ef8392020-11-10 13:42:26 +0000225 ${tppathlines}= Replace String ${tp_path} / \n
226 ${pon}= Get Value Of Tp Path Element ${tppathlines} pon
227 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
228 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
229 ${valuesid}= Set Variable ${pon}/${onu}/${uni}
230 log ${valuesid}
231 [Return] ${valuesid}
232
233Get Value Of Tp Path Element
TorstenThieme17756ea2020-11-11 14:09:47 +0000234 [Documentation] This keyword delivers numeric value of given tp path element.
TorstenThieme52ef8392020-11-10 13:42:26 +0000235 [Arguments] ${tp_path_lines} ${element}
236 ${value}= Get Lines Containing String ${tp_path_lines} ${element}-\{
237 ${value}= Remove String ${value} ${element}-\{
238 ${value}= Remove String ${value} \}
239 log ${value}
240 [Return] ${value}
241
TorstenThieme17756ea2020-11-11 14:09:47 +0000242Validate Onu Id
243 [Documentation] This keyword validates ONU Id of passed etcd data.
244 [Arguments] ${value}
245 ${tp_path}= Get From Dictionary ${value['uni_config'][0]} tp_path
246 ${tppathlines}= Replace String ${tp_path} / \n
247 ${onu}= Get Value Of Tp Path Element ${tppathlines} onu
248 ${onu_id}= Get From Dictionary ${value} onu_id
249 Should Be Equal As Integers ${onu} ${onu_id}
250 ... msg=Onu-Id (${onu_id}) does not match onu (${onu}) from tp_path in etcd data!
251 Should Be True ${onu_id}>=1
252
253Validate Uni Id
254 [Documentation] This keyword validates UNI Id of passed etcd data.
255 [Arguments] ${value}
256 ${tp_path}= Get From Dictionary ${value['uni_config'][0]} tp_path
257 ${tppathlines}= Replace String ${tp_path} / \n
258 ${uni}= Get Value Of Tp Path Element ${tppathlines} uni
259 ${uni_id}= Get From Dictionary ${value['uni_config'][0]} uni_id
260 Should Be Equal As Integers ${uni} ${uni_id}
261 ... msg=Uni-Id (${uni_id}) does not match onu (${uni}) from tp_path in etcd data!
TorstenThieme52ef8392020-11-10 13:42:26 +0000262
TorstenThiemefd7e7ba2020-11-06 13:57:57 +0000263Map State
264 [Documentation] This keyword converts the passed numeric value or name of a onu state to its state values.
265 [Arguments] ${state}
266 # create state lists with corresponding return values
267 # ADMIN-STATE OPER-STATUS CONNECT-STATUS ONU-STATE (number/name)
268 ${state1} Create List ENABLED ACTIVATING REACHABLE 1 activating-onu
269 ${state2} Create List ENABLED ACTIVATING REACHABLE 2 starting-openomci
270 ${state3} Create List ENABLED ACTIVATING REACHABLE 3 discovery-mibsync-complete
271 ${state4} Create List ENABLED ACTIVE REACHABLE 4 initial-mib-downloaded
272 ${state5} Create List ENABLED ACTIVE REACHABLE 5 tech-profile-config-download-success
273 ${state6} Create List ENABLED ACTIVE REACHABLE 6 omci-flows-pushed
274 ${state7} Create List DISABLED UNKNOWN REACHABLE 7 omci-admin-lock
275 ${state8} Create List ENABLED ACTIVE REACHABLE 8 onu-reenabled
276 ${state9} Create List ENABLED DISCOVERED UNREACHABLE 9 stopping-openomci
277 ${state10} Create List ENABLED DISCOVERED REACHABLE 10 rebooting
278 ${state11} Create List ENABLED DISCOVERED REACHABLE 11 omci-flows-deleted
279 ${state12} Create List DISABLED UNKNOWN REACHABLE 12 tech-profile-config-delete-success
280 ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}= Set Variable If
281 ... '${state}'=='1' or '${state}'=='activating-onu' ${state1}
282 ... '${state}'=='2' or '${state}'=='starting-openomci' ${state2}
283 ... '${state}'=='3' or '${state}'=='discovery-mibsync-complete' ${state3}
284 ... '${state}'=='4' or '${state}'=='initial-mib-downloaded' ${state4}
285 ... '${state}'=='5' or '${state}'=='tech-profile-config-download-success' ${state5}
286 ... '${state}'=='6' or '${state}'=='omci-flows-pushed' ${state6}
287 ... '${state}'=='7' or '${state}'=='omci-admin-lock' ${state7}
288 ... '${state}'=='8' or '${state}'=='onu-reenabled' ${state8}
289 ... '${state}'=='9' or '${state}'=='stopping-openomci' ${state9}
290 ... '${state}'=='10' or '${state}'=='rebooting' ${state10}
291 ... '${state}'=='11' or '${state}'=='omci-flows-deleted' ${state11}
292 ... '${state}'=='12' or '${state}'=='tech-profile-config-delete-success' ${state12}
293 [Return] ${admin_state} ${oper_status} ${connect_status} ${onu_state_nb} ${onu_state}