blob: 4692c4235a703d46afa8d0b846ca0e5f46132356 [file] [log] [blame]
Joey Armstrong9fadcbe2024-01-17 19:00:37 -05001# Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
TorstenThiemeff9c9142021-04-08 07:21:34 +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.
14
15*** Settings ***
16Documentation Library for various pm data (metrics) test utilities
17Library String
18Library DateTime
19Library Process
20Library Collections
21Library RequestsLibrary
22Library OperatingSystem
23Library CORDRobot
24Library ImportResource resources=CORDRobot
25Library utility.py WITH NAME utility
26Resource ./voltctl.robot
27
TorstenThieme5d963062021-07-08 10:22:29 +000028Library grpc_robot.VolthaTools WITH NAME volthatools
29
TorstenThiemeff9c9142021-04-08 07:21:34 +000030*** Variables ***
31# operators for value validations, needed for a better reading only
32${gt} > # greater than
33${ge} >= # greater equal
34${lt} < # less than
35${le} <= # less equal
36${eq} == # equal
37${ne} != # not equal
38
39*** Keywords ***
40#################################################################
41# pre test keywords
42#################################################################
43Create Metric Dictionary
44 [Documentation] Create metric dict of metrics to test/validate
45 ... Created dictionary has to be set to suite variable!!!
46 ${metric_dict}= Create Dictionary
47 FOR ${I} IN RANGE 0 ${num_all_onus}
48 ${src}= Set Variable ${hosts.src[${I}]}
49 ${onu_device_id}= Get Device ID From SN ${src['onu']}
50 Continue For Loop If '${onu_device_id}' in ${metric_dict}
51 # read available metric groups
52 ${group_list} ${interval_dict}= Read Group List ${onu_device_id}
53 # read available groupmetrics
54 ${groupmetrics_dict}= Get Available Groupmetrics per Device ${group_list} ${onu_device_id}
55 ${device_dict}= Create Dictionary MetricData ${groupmetrics_dict} GroupList ${group_list}
56 Set To Dictionary ${metric_dict} ${onu_device_id} ${device_dict}
57 Prepare Interval and Validation Data ${metric_dict} ${onu_device_id} ${interval_dict}
58 END
59 log ${metric_dict}
60 [return] ${metric_dict}
61
62Get Available Groupmetrics per Device
63 [Documentation] Delivers avaiable groupmetrics incl. validation data of onu
64 [Arguments] ${group_list} ${onu_device_id}
65 ${groupmetric_dict} Create Dictionary
66 FOR ${Item} IN @{group_list}
67 ${item_dict}= Read Group Metric Dict ${onu_device_id} ${Item}
68 ${item_dict}= Set Validation Operation ${item_dict} ${Item}
69 ${item_dict}= Set User Validation Operation ${item_dict} ${Item}
70 ${item_dict}= Set User Precondition Operation for Availability ${item_dict} ${Item}
71 ${metric}= Create Dictionary GroupMetrics=${item_dict}
72 ${dict}= Create Dictionary ${Item}=${metric}
73 Set To Dictionary ${groupmetric_dict} ${Item}=${metric}
74 END
75 [return] ${groupmetric_dict}
76
77Set Validation Operation
78 [Documentation] Sets the validation operation per metric parameter
79 [Arguments] ${item_dict} ${group}
80 FOR ${item} IN @{item_dict.keys()}
81 ${type}= Get From Dictionary ${item_dict["${item}"]} type
82 ${item_dict}= Run Keyword If
83 ... '${type}'=='COUNTER' Set Validation Operation For Counter ${item_dict} ${item} ${group}
84 ... ELSE IF '${type}'=='CONTEXT' Set Validation Operation For Context ${item_dict} ${item} ${group}
85 ... ELSE IF '${type}'=='GAUGE' Set Validation Operation For Gauge ${item_dict} ${item} ${group}
86 ... ELSE Run Keyword And Continue On Failure FAIL Type (${type}) is unknown!
87 END
88 [return] ${item_dict}
89
90Set Validation Operation For Counter
91 [Documentation] Sets the validation operation for a counter
92 [Arguments] ${item_dict} ${metric} ${group}
93 # will be overwritten by user operation and value if available
94 ${first}= Create Dictionary operator=${ge} operand=0
95 # for real POD it must be >= previous counter value, in case of BBSim usage we got random values, so check >= 0
96 ${successor}= Run Keyword If ${has_dataplane} Create Dictionary operator=${ge} operand=previous
97 ... ELSE Create Dictionary operator=${ge} operand=0
98 ${ValidationOperation}= Create Dictionary first=${first} successor=${successor}
99 Set To Dictionary ${item_dict['${metric}']} ValidationOperation=${ValidationOperation}
100 [return] ${item_dict}
101
102Set Validation Operation For Context
103 [Documentation] Sets the validation operation for a context
104 [Arguments] ${item_dict} ${metric} ${group}
105 # will be overwritten by user operation and value if available
106 ${first}= Create Dictionary operator=${ge} operand=0
107 ${successor}= Create Dictionary operator=${eq} operand=previous
108 ${ValidationOperation}= Create Dictionary first=${first} successor=${successor}
109 Set To Dictionary ${item_dict['${metric}']} ValidationOperation=${ValidationOperation}
110 [return] ${item_dict}
111
112Set Validation Operation For Gauge
113 [Documentation] Sets the validation operation for a gauge
114 [Arguments] ${item_dict} ${metric} ${group}
115 # will be overwritten by user operation and value if available
116 ${first}= Create Dictionary operator=${ge} operand=0
117 ${successor}= Create Dictionary operator=${ge} operand=0
118 ${ValidationOperation}= Create Dictionary first=${first} successor=${successor}
119 Set To Dictionary ${item_dict['${metric}']} ValidationOperation=${ValidationOperation}
120 [return] ${item_dict}
121
122Set User Validation Operation
123 [Documentation] Sets the user validation operation and value per metric parameter if available
124 [Arguments] ${item_dict} ${group}
125 ${variables}= Get variables no_decoration=Yes
126 Return From Keyword If not "pm_user_validation_data" in $variables ${item_dict}
127 Return From Keyword If not '${group}' in ${pm_user_validation_data} ${item_dict}
128 FOR ${item} IN @{item_dict.keys()}
129 Continue For Loop If not '${item}' in ${pm_user_validation_data['${group}']}
130 ${operator}= Get From Dictionary ${pm_user_validation_data['${group}']['${item}']} firstoperator
131 ${operand}= Get From Dictionary ${pm_user_validation_data['${group}']['${item}']} firstvalue
132 ${first}= Create Dictionary operator=${operator} operand=${operand}
133 ${operator}= Get From Dictionary ${pm_user_validation_data['${group}']['${item}']} successoroperator
134 ${operand}= Get From Dictionary ${pm_user_validation_data['${group}']['${item}']} successorvalue
135 ${successor}= Create Dictionary operator=${operator} operand=${operand}
136 ${ValidationOperation}= Create Dictionary first=${first} successor=${successor}
137 Set To Dictionary ${item_dict['${item}']} ValidationOperation=${ValidationOperation}
138 END
139 [return] ${item_dict}
140
141Set User Precondition Operation for Availability
142 [Documentation] Sets the user precondition operation, value and element per metric parameter if available
143 [Arguments] ${item_dict} ${group}
144 ${variables}= Get variables no_decoration=Yes
145 Return From Keyword If not "pm_user_precondition_data" in $variables ${item_dict}
146 Return From Keyword If not '${group}' in ${pm_user_precondition_data} ${item_dict}
147 FOR ${item} IN @{item_dict.keys()}
148 Continue For Loop If not '${item}' in ${pm_user_precondition_data['${group}']}
149 ${operator}= Get From Dictionary ${pm_user_precondition_data['${group}']['${item}']} operator
150 ${operand}= Get From Dictionary ${pm_user_precondition_data['${group}']['${item}']} value
151 ${element}= Get From Dictionary ${pm_user_precondition_data['${group}']['${item}']} precondelement
152 ${precond}= Create Dictionary operator=${operator} operand=${operand} element=${element}
153 Set To Dictionary ${item_dict['${item}']} Precondition=${precond}
154 END
155 [return] ${item_dict}
156
157Prepare Interval and Validation Data
158 [Documentation] Prepares interval and validation data of onu
159 [Arguments] ${METRIC_DICT} ${onu_device_id} ${interval_dict}
160 ${list}= Get From Dictionary ${METRIC_DICT['${onu_device_id}']} GroupList
161 FOR ${Item} IN @{list}
162 ${metric}= Get From Dictionary ${METRIC_DICT['${onu_device_id}']['MetricData']} ${Item}
163 Set To Dictionary ${metric} NumberOfChecks=0
164 ${default_interval}= Get From Dictionary ${interval_dict} ${Item}
165 # convert interval in seconds and remove unit
166 ${default_interval}= Validate Time Unit ${default_interval} False
167 ${intervals} Create Dictionary default=${default_interval} user=-1 current=${default_interval}
168 Set To Dictionary ${metric} Intervals=${intervals}
169 Set To Dictionary ${METRIC_DICT['${onu_device_id}']['MetricData']} ${Item}=${metric}
170 END
171
172Prepare Group Interval List per Device Id
173 [Documentation] Prepares group-interval list per device id
174 [Arguments] ${dev_id} ${user}=False ${group}=${EMPTY}
175 ${list}= Get From Dictionary ${METRIC_DICT['${dev_id}']} GroupList
176 ${group_interval_list} Create List
177 FOR ${Item} IN @{list}
178 ${val}= Run Keyword If ${user}
179 ... Get From Dictionary ${METRIC_DICT['${dev_id}']['MetricData']['${Item}']['Intervals']} user
180 ... ELSE Get From Dictionary ${METRIC_DICT['${dev_id}']['MetricData']['${Item}']['Intervals']} default
181 ${dict}= Create Dictionary group=${Item} interval=${val}
182 Run Keyword If '${group}'=='${EMPTY}' or '${group}'=='${Item}' Append To List ${group_interval_list} ${dict}
183 END
184 [return] ${group_interval_list}
185
186Get Longest Interval per Onu
187 [Documentation] Delivers longest group interval per device id
188 [Arguments] ${dev_id} ${user}=False
189 ${list}= Get From Dictionary ${METRIC_DICT['${dev_id}']} GroupList
190 ${longest_interval}= Set Variable 0
191 FOR ${Item} IN @{list}
192 ${val}= Run Keyword If ${user}
193 ... Get From Dictionary ${METRIC_DICT['${dev_id}']['MetricData']['${Item}']['Intervals']} user
194 ... ELSE Get From Dictionary ${METRIC_DICT['${dev_id}']['MetricData']['${Item}']['Intervals']} default
195 ${longest_interval}= Set Variable If ${val} > ${longest_interval} ${val} ${longest_interval}
196 END
197 [return] ${longest_interval}
198
199Get Longest Interval
200 [Documentation] Delivers longest interval over all devices
201 [Arguments] ${user}=False
202 ${longest_interval}= Set Variable 0
203 ${onu_list} Create List
204 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
205 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
206 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
207 Continue For Loop If -1 != ${onu_id}
208 Continue For Loop If not '${onu_device_id}' in ${METRIC_DICT}
209 ${onu_longest_interval}= Run Keyword If '${onu_device_id}'!='${EMPTY}'
210 ... Get Longest Interval per Onu ${onu_device_id} ${user}
211 ${longest_interval}= Set Variable If ${onu_longest_interval} > ${longest_interval} ${onu_longest_interval}
212 ... ${longest_interval}
213 END
214 [return] ${longest_interval}
215
216Determine Collection Interval
217 [Documentation] Delivers collection interval over all devices
218 [Arguments] ${user}=False
219 ${longest_interval}= Get Longest Interval user=${user}
TorstenThieme5d963062021-07-08 10:22:29 +0000220 ${collect_interval}= evaluate (${longest_interval}*2)+6
TorstenThiemeff9c9142021-04-08 07:21:34 +0000221 ${collect_interval}= Validate Time Unit ${collect_interval}
222 [return] ${collect_interval}
223
224Set Group Interval per Onu
225 [Documentation] Sets group user interval in METRIC_DICT per device id
226 [Arguments] ${device_id} ${group} ${val}
227 # convert interval in seconds and remove unit
228 ${val}= Validate Time Unit ${val} False
229 Run Keyword If '${group}' in ${METRIC_DICT['${device_id}']['MetricData']}
230 ... Set To Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${group}']['Intervals']} user=${val}
231
232Set Group Interval All Onu
233 [Documentation] Sets group user interval in METRIC_DICT
234 [Arguments] ${group} ${val}
235 ${onu_list} Create List
236 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
237 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
238 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
239 Continue For Loop If -1 != ${onu_id}
240 Continue For Loop If not '${onu_device_id}' in ${METRIC_DICT}
241 Set Group Interval per Onu ${onu_device_id} ${group} ${val}
242 END
243
244Activate And Validate Interval All Onu
245 [Documentation] Activates and validates group user interval taken from METRIC_DICT
246 [Arguments] ${user}=False ${group}=${EMPTY}
247 ${onu_list} Create List
248 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
249 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
250 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
251 Continue For Loop If -1 != ${onu_id}
252 Continue For Loop If not '${onu_device_id}' in ${METRIC_DICT}
253 ${list}= Prepare Group Interval List per Device Id ${onu_device_id} ${user} ${group}
254 Activate And Validate Metrics Interval per Onu ${onu_device_id} ${list}
255 END
256
257Activate And Validate Metrics Interval per Onu
258 [Documentation] Activates and validates interval of pm data per onu
259 [Arguments] ${device_id} ${group_list}
260 FOR ${Item} IN @{group_list}
261 Continue For Loop If not '${device_id}' in ${METRIC_DICT}
262 ${group}= Get From Dictionary ${Item} group
263 ${val}= Get From Dictionary ${Item} interval
264 Continue For Loop If not '${group}' in ${METRIC_DICT['${device_id}']['MetricData']}
265 Continue For Loop If '${val}'=='-1'
266 # set the unit to sec
267 ${val_with_unit}= Validate Time Unit ${val}
268 Set and Validate Group Interval ${device_id} ${val_with_unit} ${group}
269 # update current interval in METRICS_DICT
270 Set To Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${group}']['Intervals']} current=${val}
271 END
272
273Set Validation Operation per Onu
274 [Documentation] Sets group validation data in METRIC_DICT per device id for passed metric element
275 [Arguments] ${device_id} ${group} ${metric_element} ${validation_dict}
276 Run Keyword If '${group}' in ${METRIC_DICT['${device_id}']['MetricData']}
277 ... Set To Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${group}']['GroupMetrics']['${metric_element}']}
278 ... ValidationOperation=${validation_dict}
279
280Set Validation Operation All Onu
281 [Documentation] Sets group validation data in METRIC_DICT all devices and passed metric element
282 [Arguments] ${group} ${metric_element} ${validation_dict}
283 ${onu_list} Create List
284 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
285 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
286 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
287 Continue For Loop If -1 != ${onu_id}
288 Continue For Loop If not '${onu_device_id}' in ${METRIC_DICT}
289 Set Validation Operation per Onu ${onu_device_id} ${group} ${metric_element} ${validation_dict}
290 END
291
292Set Validation Operation Passed Onu
293 [Documentation] Sets group validation data in METRIC_DICT for passed devices and passed metric element
294 ... Passed dictionary has to be format <device_id>:<Validation Dictionary>
295 ... Keyword 'Get Validation Operation All Onu' delivers such a dictionary.
296 [Arguments] ${group} ${metric_element} ${validation_dict_with_device_id}
297 FOR ${item} IN @{validation_dict_with_device_id.keys()}
298 Continue For Loop If not '${item}' in ${METRIC_DICT}
299 ${validation_dict}= Get From Dictionary ${validation_dict_with_device_id} ${item}
300 Set Validation Operation per Onu ${item} ${group} ${metric_element} ${validation_dict}
301 END
302
303Get Validation Operation per Onu
304 [Documentation] Delivers group validation data in METRIC_DICT per device id for passed metric element
305 [Arguments] ${device_id} ${group} ${metric_element}
306 ${validation_dict}= Run Keyword If '${group}' in ${METRIC_DICT['${device_id}']['MetricData']}
307 ... Get From Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${group}']['GroupMetrics']['${metric_element}']}
308 ... ValidationOperation
309 [return] ${validation_dict}
310
311Get Validation Operation All Onu
312 [Documentation] Delivers group validation data in METRIC_DICT all devices for passed metric element
313 [Arguments] ${group} ${metric_element}
314 ${validation_dict_with_device} Create Dictionary
315 ${onu_list} Create List
316 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
317 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
318 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
319 Continue For Loop If -1 != ${onu_id}
320 Continue For Loop If not '${onu_device_id}' in ${METRIC_DICT}
321 ${validation_dict}= Get Validation Operation per Onu ${onu_device_id} ${group} ${metric_element}
322 Set To Dictionary ${validation_dict_with_device} ${onu_device_id}=${validation_dict}
323 END
324 [return] ${validation_dict_with_device}
325
326#################################################################
327# test keywords
328#################################################################
329Collect and Validate PM Data
330 [Documentation] Collecta PM-data from kafka and validates metrics
331 [Arguments] ${collect_interval} ${clear}=True ${user}=False ${group}=${EMPTY}
332 ${Kafka_Records}= Get Metrics ${collect_interval} clear=${clear}
333 ${RecordsLength}= Get Length ${Kafka_Records}
334 FOR ${Index} IN RANGE 0 ${RecordsLength}
335 ${metric}= Set Variable ${Kafka_Records[${Index}]}
336 ${message}= Get From Dictionary ${metric} message
337 ${event}= volthatools.Events Decode Event ${message} return_default=true
338 Continue For Loop If not 'kpi_event2' in ${event}
339 Validate Raised Timestamp ${event}
340 ${slice}= Get Slice Data From Event ${event}
341 Validate Raised Timestamp ${event}
342 Validate Slice Data ${slice} ${Kafka_Records}
343 Set Previous Record ${Index} ${slice}
344 END
345 Validate Number of Checks ${collect_interval} user=${user} group=${group}
346
347Get Metrics
348 [Documentation] Delivers metrics from kafka
349 [Arguments] ${collect_interval} ${clear}=True
350 Run Keyword If ${clear} kafka.Records Clear
351 Sleep ${collect_interval}
352 ${Kafka_Records}= kafka.Records Get voltha.events
353 [return] ${Kafka_Records}
354
355Get Title From Metadata
356 [Documentation] Delivers the title of pm data from metadata
357 [Arguments] ${metadata}
358 ${title}= Get From Dictionary ${metadata} title
359 [return] ${title}
360
361Get Device_Id From Metadata
362 [Documentation] Delivers the device-id of pm data from metadata
363 [Arguments] ${metadata}
364 ${device_id}= Get From Dictionary ${metadata} device_id
365 [return] ${device_id}
366
367Get Timestamp From Metadata
368 [Documentation] Delivers the device-id of pm data from metadata
369 [Arguments] ${metadata}
370 ${timestamp}= Get From Dictionary ${metadata} ts
371 [return] ${timestamp}
372
373Get Slice Data From Event
374 [Documentation] Delivers the slice data of pm data from event
375 [Arguments] ${event}
376 ${kpi_event2}= Get From Dictionary ${event} kpi_event2
377 ${slice_data}= Get From Dictionary ${kpi_event2} slice_data
378 [return] ${slice_data}
379
380Validate Raised Timestamp
381 [Documentation] Validates raisedTs with kpi_event2 ts
382 ... It is assumed kpi_event2 ts and raisedTs from event header should be the same
383 [Arguments] ${event}
384 ${raisedTs}= Get From Dictionary ${event['header']['raised_ts']} seconds
385 ${reportedTs}= Get From Dictionary ${event['header']['reported_ts']} seconds
386 ${kpiEvent2Ts}= Get From Dictionary ${event['kpi_event2']} ts
387 # ${raisedTs} and ${reportedTs} looks like '2021-04-28 06:56:54.000000', convert it to seconds of epoch
388 ${raisedTsSec}= Convert Date ${raisedTs} result_format=epoch exclude_millis=yes
389 ${reportedTsSec}= Convert Date ${reportedTs} result_format=epoch exclude_millis=yes
390 Run Keyword And Continue On Failure Should Be Equal ${raisedTsSec} ${kpiEvent2Ts}
391 ${result}= utility.validate ${raisedTsSec} <= ${reportedTsSec}
392 ${msg}= Catenate raisedTs (${raisedTs}) must be earlier or equal than reportedTs (${reportedTs})!
393 Run Keyword Unless ${result} Run Keyword And Continue On Failure FAIL ${msg}
394
395Validate Slice Data
396 [Documentation] Validates passed slice data
397 [Arguments] ${slice} ${metric_records}
398 ${result}= Set Variable True
399 ${checked}= Set Variable False
400 ${device_id}= Set Variable ${EMPTY}
401 ${title}= Set Variable ${EMPTY}
402 ${SliceLength}= Get Length ${slice}
403 Validate Slice Metrics Integrity ${slice}
404 FOR ${Index} IN RANGE 0 ${SliceLength}
405 ${metadata}= Get From Dictionary ${slice[${Index}]} metadata
406 ${metrics}= Get From Dictionary ${slice[${Index}]} metrics
407 ${title}= Get Title From Metadata ${metadata}
408 ${device_id}= Get Device_Id From Metadata ${metadata}
409 Continue For Loop If not '${device_id}' in ${METRIC_DICT}
410 ${timestamp}= Get Timestamp From Metadata ${metadata}
411 ${prevSliceIndex}= Run Keyword If 'PreviousRecord' in ${METRIC_DICT['${device_id}']['MetricData']['${title}']}
412 ... Get Previous Slice Index ${device_id} ${title} ${metric_records} ${metrics}
413 ... ELSE Set Variable 0
414 Continue For Loop If ${prevSliceIndex}==-1
415 Run Keyword If 'PreviousRecord' in ${METRIC_DICT['${device_id}']['MetricData']['${title}']}
416 ... Validate Timestamp ${device_id} ${title} ${timestamp} ${metric_records} ${prevSliceIndex}
417 ${hasprev}= Set Variable If 'PreviousRecord' in ${METRIC_DICT['${device_id}']['MetricData']['${title}']}
418 ... True False
419 Validate Metrics Data ${device_id} ${title} ${metrics} ${hasprev} ${metric_records} ${prevSliceIndex}
420 Validate Completeness of Metrics Data ${device_id} ${title} ${metrics}
421 ${checked}= Set Variable True
422 END
423 # increase number of checks, only once per slice
424 Run Keyword If ${checked} Increase Number of Checks ${device_id} ${title}
425
426Validate Slice Metrics Integrity
427 [Documentation] Valitdates the inegrity of the passed slice.
428 ... The pair 'entity_id' and 'class_id' has tor appear only once per slice!
429 ... In case of metric group UNI_Status parameter 'uni_port_no' appends to check!
430 [Arguments] ${slice}
431 ${prev_values} Create List
432 ${SliceLength}= Get Length ${slice}
433 FOR ${Index} IN RANGE 0 ${SliceLength}
434 ${metadata}= Get From Dictionary ${slice[${Index}]} metadata
435 ${metrics}= Get From Dictionary ${slice[${Index}]} metrics
436 ${title}= Get Title From Metadata ${metadata}
437 # get entity-id and class_id if available
438 # class_id identifier differs in case of metric group UNI_Status, 'me_class_id' instead simple 'class_id'
439 ${class_id_name}= Run Keyword If '${title}'=='UNI_Status' Set Variable me_class_id
440 ... ELSE Set Variable class_id
441 Continue For Loop If not 'entity_id' in ${metrics}
442 Continue For Loop If not '${class_id_name}' in ${metrics}
443 ${entity_id}= Get From Dictionary ${metrics} entity_id
444 ${class_id}= Get From Dictionary ${metrics} ${class_id_name}
445 # additional handling for metric group UNI_Status, uni_port_no has to be matched too
446 ${uni_port_no}= Run Keyword If '${title}'=='UNI_Status' Get From Dictionary ${metrics} uni_port_no
447 ... ELSE Set Variable ${Index}
448 ${current_values}= Create Dictionary entity_id=${entity_id} class_id=${class_id} uni_port_no=${uni_port_no}
449 Run Keyword And Continue On Failure Should Not Contain ${prev_values} ${current_values}
450 Append To List ${prev_values} ${current_values}
451 END
452
453Get Previous Slice Index
454 [Documentation] Delivers the slice index of previous metrics.
455 ... Previous slice index will be identified by matching entity_ids.
456 ... In case of UNI_Status the me_class_id has to be matched too!
457 [Arguments] ${device_id} ${title} ${metric_records} ${metrics}
458 ${prevSliceIndex}= Set Variable 0
459 # get entity-id and class_id if available
460 # class_id identifier differs in case of metric group UNI_Status, 'me_class_id' instead simple 'class_id'
461 ${class_id_name}= Run Keyword If '${title}'=='UNI_Status' Set Variable me_class_id
462 ... ELSE Set Variable class_id
463 Return From Keyword If not 'entity_id' in ${metrics} ${prevSliceIndex}
464 Return From Keyword If not '${class_id_name}' in ${metrics} ${prevSliceIndex}
465 ${entity_id}= Get From Dictionary ${metrics} entity_id
466 ${class_id}= Get From Dictionary ${metrics} ${class_id_name}
467 # get previous entity-id
468 ${prev_index}= Set Variable ${METRIC_DICT['${device_id}']['MetricData']['${title}']['PreviousRecord']}
469 ${pre_record}= Set Variable ${metric_records[${prev_index}]}
470 ${message}= Get From Dictionary ${pre_record} message
471 ${event}= volthatools.Events Decode Event ${message} return_default=true
472 ${prev_slice}= Get Slice Data From Event ${event}
473 ${prevSliceLength}= Get Length ${prev_slice}
474 ${matched}= Set Variable False
475 FOR ${Index} IN RANGE 0 ${prevSliceLength}
476 ${prevmetrics}= Get From Dictionary ${prev_slice[${Index}]} metrics
477 ${prev_entity_id}= Get From Dictionary ${prevmetrics} entity_id
478 ${prev_class_id}= Get From Dictionary ${prevmetrics} ${class_id_name}
479 ${matched}= Set Variable If (${entity_id}==${prev_entity_id})and(${${class_id}}==${prev_class_id}) True False
480 ${prevSliceIndex}= Set Variable If ${matched} ${Index} -1
481 Exit For Loop If ${matched}
482 END
483 Run Keyword And Continue On Failure Run Keyword Unless ${matched} FAIL
484 ... Could not find previous metrics for ${title} entity_id ${entity_id} of device ${device_id}!
485 [return] ${prevSliceIndex}
486
487Validate Timestamp
488 [Documentation] Validates passed timestamp with timestamp of previous metrics
489 [Arguments] ${device_id} ${title} ${timestamp} ${metric_records} ${prevSliceIndex}
490 # get previous timestamp
491 ${prev_timestamp}= Get Previous Timestamp ${METRIC_DICT['${device_id}']['MetricData']['${title}']['PreviousRecord']}
492 ... ${metric_records} ${prevSliceIndex}
493 ${interval}= Get From Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${title}']['Intervals']}
494 ... current
495 ${interval}= Convert To Integer ${interval}
496 ${check_value}= Evaluate abs(${prev_timestamp}+${interval}-${timestamp})
497 Run Keyword And Continue On Failure Run Keyword Unless ${0} <= ${check_value} <= ${4} FAIL
498 ... Wrong interval for ${title} of device ${device_id}!
499
500Get Validation Operation
501 [Documentation] Delivers the stored validation operation of passed metrics
502 [Arguments] ${dev_id} ${title} ${item} ${has_previous}
503 ${w_wo_prev}= Set Variable If ${has_previous} successor first
504 ${validation_operator}= Get From Dictionary
505 ... ${METRIC_DICT['${dev_id}']['MetricData']['${title}']['GroupMetrics']['${item}']['ValidationOperation']['${w_wo_prev}']}
506 ... operator
507 ${validation_operand}= Get From Dictionary
508 ... ${METRIC_DICT['${dev_id}']['MetricData']['${title}']['GroupMetrics']['${item}']['ValidationOperation']['${w_wo_prev}']}
509 ... operand
510 [return] ${validation_operator} ${validation_operand}
511
512Get Previous Value
513 [Documentation] Delivers the previous value
514 [Arguments] ${device_id} ${title} ${item} ${metric_records} ${prevSliceIndex}
515 ${prev_index}= Set Variable ${METRIC_DICT['${device_id}']['MetricData']['${title}']['PreviousRecord']}
516 ${pre_record}= Set Variable ${metric_records[${prev_index}]}
517 ${message}= Get From Dictionary ${pre_record} message
518 ${event}= volthatools.Events Decode Event ${message} return_default=true
519 ${slice}= Get Slice Data From Event ${event}
520 ${metrics}= Get From Dictionary ${slice[${prevSliceIndex}]} metrics
521 ${prev_value}= Get From Dictionary ${metrics} ${item}
522 [return] ${prev_value}
523
524Validate Metrics Data
525 [Documentation] Validates passed metrics
526 [Arguments] ${device_id} ${title} ${metrics} ${has_previous} ${metric_records} ${prevSliceIndex}
527 FOR ${item} IN @{metrics.keys()}
528 ${operation} ${validation_value}= Get Validation Operation ${device_id} ${title} ${item} ${has_previous}
529 # get previous value in case of ${has_previous}==True and ${validation_value}==previous
530 ${validation_value}= Run Keyword If ${has_previous} and '${validation_value}'=='previous' Get Previous Value
531 ... ${device_id} ${title} ${item} ${metric_records} ${prevSliceIndex}
532 ... ELSE Set Variable ${validation_value}
533 ${current_value}= Get From Dictionary ${metrics} ${item}
534 ${result}= utility.validate ${current_value} ${operation} ${validation_value}
535 ${msg}= Catenate Received value (${current_value}) from device (${device_id}) of group (${title}) for '${item}'
536 ... does not match!
537 ... Expected: <value> ${operation} ${validation_value}
538 Run Keyword Unless ${result} Run Keyword And Continue On Failure FAIL ${msg}
539 END
540
541Validate Precondition for Availability
542 [Documentation] Validates passed metrics for stored precondition
543 [Arguments] ${device_id} ${title} ${metrics} ${item}
544 ${precond}= Get From Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${title}']['GroupMetrics']['${item}']}
545 ... Precondition
546 ${operation}= Get From Dictionary ${precond} operator
547 ${validation_value}= Get From Dictionary ${precond} operand
548 ${element}= Get From Dictionary ${precond} element
549 ${current_value}= Get From Dictionary ${metrics} ${element}
550 ${result}= utility.validate ${current_value} ${operation} ${validation_value}
551 [return] ${result}
552
553Validate Completeness of Metrics Data
554 [Documentation] Validates passed metrics of completness
555 [Arguments] ${device_id} ${title} ${metrics}
556 # get validation data
557 ${validation_data}= Set Variable ${METRIC_DICT['${device_id}']['MetricData']['${title}']['GroupMetrics']}
558 FOR ${item} IN @{validation_data.keys()}
559 ${precondfullfilled}= Run Keyword If
560 ... 'Precondition' in ${METRIC_DICT['${device_id}']['MetricData']['${title}']['GroupMetrics']['${item}']}
561 ... Validate Precondition for Availability ${device_id} ${title} ${metrics} ${item}
562 ... ELSE Set Variable True
563 Run Keyword If (not '${item}' in ${metrics}) and ${precondfullfilled} Run Keyword And Continue On Failure FAIL
564 ... Missing metric (${item}) from device (${device_id}) of group (${title})
565 END
566
567Get Previous Timestamp
568 [Documentation] Deliveres the timestamp of the passed metrics record
569 [Arguments] ${prev_index} ${metric_records} ${prevSliceIndex}
570 ${metric}= Set Variable ${metric_records[${prev_index}]}
571 ${message}= Get From Dictionary ${metric} message
572 ${event}= volthatools.Events Decode Event ${message} return_default=true
573 ${slice}= Get Slice Data From Event ${event}
574 ${metadata}= Get From Dictionary ${slice[${prevSliceIndex}]} metadata
575 ${timestamp}= Get Timestamp From Metadata ${metadata}
576 [return] ${timestamp}
577
578Set Previous Record
579 [Documentation] Sets the previous record in METRIC_DICT for next validation
580 [Arguments] ${Index} ${slice}
581 # use first slice for further handling
582 ${metadata}= Get From Dictionary ${slice[${0}]} metadata
583 ${title}= Get Title From Metadata ${metadata}
584 ${device_id}= Get Device_Id From Metadata ${metadata}
585 Return From Keyword If not '${device_id}' in ${METRIC_DICT}
586 ${metric}= Get From Dictionary ${METRIC_DICT['${device_id}']['MetricData']} ${title}
587 Set To Dictionary ${metric} PreviousRecord=${Index}
588 Set To Dictionary ${METRIC_DICT['${device_id}']['MetricData']} ${title}=${metric}
589
590Increase Number of Checks
591 [Documentation] Increases the NumberOfChecks value in METRIC_DICT for passed device id and title
592 [Arguments] ${device_id} ${title}
593 ${checks}= Get From Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${title}']} NumberOfChecks
594 ${checks}= evaluate ${checks} + 1
595 Set To Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${title}']} NumberOfChecks=${checks}
596
597Validate Number of Checks
598 [Documentation] Validates the NumberOfChecks value in METRIC_DICT, must be at least >=2
599 [Arguments] ${collect_interval} ${user}=False ${group}=${EMPTY}
600 ${onu_list} Create List
601 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
602 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
603 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
604 Continue For Loop If -1 != ${onu_id}
605 ${list}= Prepare Group Interval List per Device Id ${onu_device_id} ${user} ${group}
606 Validate Number of Checks per Onu ${onu_device_id} ${list} ${collect_interval}
607 END
608
609Validate Number of Checks per Onu
610 [Documentation] Validates the NumberOfChecks value per ONU, must be at least >=2
611 ... Collecting of metrics will be calculated that at least each group has to be checked twice!
612 ... Correct value per group and its interval will be calculated!
613 [Arguments] ${device_id} ${list} ${collect_interval}
614 FOR ${Item} IN @{list}
615 ${group}= Get From Dictionary ${Item} group
616 ${val}= Get From Dictionary ${Item} interval
617 # use interval value to skip groups, which should not be checked!
618 Continue For Loop If '${val}'=='-1'
619 ${checks}= Get From Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${group}']} NumberOfChecks
620 # remove time unit if available
621 ${collect_interval}= Validate Time Unit ${collect_interval} False
622 ${expected_checks}= evaluate ${collect_interval}/${val}
TorstenThieme5d963062021-07-08 10:22:29 +0000623 # remove float format and round down always (e.g. 3.9 -> 3)
624 ${expected_checks}= evaluate int(${expected_checks})
TorstenThiemeff9c9142021-04-08 07:21:34 +0000625 Run Keyword And Continue On Failure Run Keyword Unless ${expected_checks} <= ${checks} FAIL
626 ... Wrong number of pm-data (${checks}) for ${group} of device ${device_id}!
627 END
628
629#################################################################
630# Post test keywords
631#################################################################
632
633Remove Previous Record
634 [Documentation] Removes the previous record in METRIC_DICT
635 [Arguments] ${device_id} ${title}
636 Remove From Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${title}']} PreviousRecord
637
638Reset Number Of Checks
639 [Documentation] Removes the previous record in METRIC_DICT
640 [Arguments] ${device_id} ${title}
641 Set To Dictionary ${METRIC_DICT['${device_id}']['MetricData']['${title}']} NumberOfChecks=0
642
643Clean Metric Dictionary per Onu
644 [Documentation] Cleans METRIC_DICT per onu device id
645 [Arguments] ${device_id}
646 FOR ${Item} IN @{METRIC_DICT['${device_id}']['GroupList']}
647 Remove Previous Record ${device_id} ${Item}
648 Reset Number Of Checks ${device_id} ${Item}
649 END
650
651Clean Metric Dictionary
652 [Documentation] Cleans METRIC_DICT
653 ${onu_list} Create List
654 FOR ${INDEX} IN RANGE 0 ${num_all_onus}
655 ${onu_device_id}= Get Device ID From SN ${hosts.src[${INDEX}].onu}
656 ${onu_id}= Get Index From List ${onu_list} ${onu_device_id}
657 Continue For Loop If -1 != ${onu_id}
658 Clean Metric Dictionary per Onu ${onu_device_id}
659 END
660 log ${METRIC_DICT}
661
662
663#################################################################
664# Helper keywords
665#################################################################
666
667Validate Time Unit
668 [Documentation] Converts the passed value in seconds and return it w/o unit
669 ... Conversion to string is needed to remove float format!
670 [Arguments] ${val} ${unit}=True
671 ${seconds}= Convert Time ${val}
672 ${seconds}= Convert To String ${seconds}
673 ${seconds}= Get Substring ${seconds} 0 -2
674 ${seconds}= Set Variable If ${unit} ${seconds}s ${seconds}
675 [return] ${seconds}