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