1*** Settings ***
2Documentation   This suite tests Platform Event Log (PEL) functionality of OpenBMC.
3
4Library         ../../lib/pel_utils.py
5Variables       ../../data/pel_variables.py
6Resource        ../../lib/list_utils.robot
7Resource        ../../lib/logging_utils.robot
8Resource        ../../lib/openbmc_ffdc.robot
9
10Test Setup      Redfish.Login
11Test Teardown   Run Keywords  Redfish.Logout  AND  FFDC On Test Case Fail
12
13
14*** Variables ***
15
16${CMD_INTERNAL_FAILURE}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
17...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
18...  xyz.openbmc_project.Logging.Entry.Level.Error 0
19
20${CMD_FRU_CALLOUT}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
21...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.Timeout
22...  xyz.openbmc_project.Logging.Entry.Level.Error 2 "TIMEOUT_IN_MSEC" "5"
23...  "CALLOUT_INVENTORY_PATH" "/xyz/openbmc_project/inventory/system/chassis/motherboard"
24
25${CMD_PROCEDURAL_SYMBOLIC_FRU_CALLOUT}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
26...  xyz.openbmc_project.Logging.Create Create ssa{ss} org.open_power.Logging.Error.TestError1
27...  xyz.openbmc_project.Logging.Entry.Level.Error 0
28
29${CMD_INFORMATIONAL_ERROR}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
30...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.TestError2
31...  xyz.openbmc_project.Logging.Entry.Level.Informational 0
32
33${CMD_INVENTORY_PREFIX}  busctl get-property xyz.openbmc_project.Inventory.Manager
34...  /xyz/openbmc_project/inventory/system/chassis/motherboard
35
36${CMD_UNRECOVERABLE_ERROR}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
37...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
38...  xyz.openbmc_project.Logging.Entry.Level.Error 0
39
40${CMD_PREDICTIVE_ERROR}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
41...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
42...   xyz.openbmc_project.Logging.Entry.Level.Warning 0
43
44@{mandatory_pel_fileds}   Private Header  User Header  Primary SRC  Extended User Header  Failing MTMS
45
46${info_log_max_usage_percentage}  15
47
48
49*** Test Cases ***
50
51Create Test PEL Log And Verify
52    [Documentation]  Create PEL log using busctl command and verify via peltool.
53    [Tags]  Create_Test_PEL_Log_And_Verify
54
55    Redfish Purge Event Log
56    Create Test PEL Log
57    ${pel_id}=  Get PEL Log Via BMC CLI
58    Should Not Be Empty  ${pel_id}  msg=System PEL log entry is empty.
59
60
61Verify PEL Log Details
62    [Documentation]  Verify PEL log details via peltool.
63    [Tags]  Verify_PEL_Log_Details
64
65    Redfish Purge Event Log
66
67    ${bmc_time1}=  CLI Get BMC DateTime
68    Create Test PEL Log
69    ${bmc_time2}=  CLI Get BMC DateTime
70
71    ${pel_records}=  Peltool  -l
72
73    # Example output from 'Peltool  -l':
74    # pel_records:
75    # [0x50000012]:
76    #   [CreatorID]:                  BMC
77    #   [CompID]:                     0x1000
78    #   [PLID]:                       0x50000012
79    #   [Subsystem]:                  BMC Firmware
80    #   [Message]:                    An application had an internal failure
81    #   [SRC]:                        BD8D1002
82    #   [Commit Time]:                03/02/2020  09:35:15
83    #   [Sev]:                        Unrecoverable Error
84
85    ${ids}=  Get Dictionary Keys  ${pel_records}
86    ${id}=  Get From List  ${ids}  0
87
88    @{pel_fields}=  Create List  CreatorID  Subsystem  Message  Sev
89    FOR  ${field}  IN  @{pel_fields}
90      Valid Value  pel_records['${id}']['${field}']  ['${PEL_DETAILS['${field}']}']
91    END
92
93    Valid Value  pel_records['${id}']['PLID']  ['${id}']
94
95    # Verify if "CompID" and "SRC" fields of PEL has alphanumeric value.
96    Should Match Regexp  ${pel_records['${id}']['CompID']}  [a-zA-Z0-9]
97    Should Match Regexp  ${pel_records['${id}']['SRC']}  [a-zA-Z0-9]
98
99    ${pel_date_time}=  Convert Date  ${pel_records['${id}']['Commit Time']}
100    ...  date_format=%m/%d/%Y %H:%M:%S  exclude_millis=yes
101
102    # Convert BMC and PEL time to epoch time before comparing.
103    ${bmc_time1_epoch}=  Convert Date  ${bmc_time1}  epoch
104    ${pel_time_epoch}=  Convert Date  ${pel_date_time}  epoch
105    ${bmc_time2_epoch}=  Convert Date  ${bmc_time2}  epoch
106
107    Should Be True  ${bmc_time1_epoch} <= ${pel_time_epoch} <= ${bmc_time2_epoch}
108
109
110Verify Mandatory Sections Of Error Log PEL
111    [Documentation]  Verify mandatory sections of error log PEL.
112    [Tags]  Verify_Mandatory_Sections_Of_Error_Log_PEL
113
114    Create Test PEL Log
115
116    ${pel_ids}=  Get PEL Log Via BMC CLI
117    ${pel_id}=  Get From List  ${pel_ids}  -1
118    ${pel_output}=  Peltool  -i ${pel_id}
119    ${pel_sections}=  Get Dictionary Keys  ${pel_output}
120
121    List Should Contain Sub List  ${pel_sections}  ${mandatory_pel_fileds}
122
123
124Verify PEL Log Persistence After BMC Reboot
125    [Documentation]  Verify PEL log persistence after BMC reboot.
126    [Tags]  Verify_PEL_Log_Persistence_After_BMC_Reboot
127
128    Create Test PEL Log
129    ${pel_before_reboot}=  Get PEL Log Via BMC CLI
130
131    Redfish OBMC Reboot (off)
132    ${pel_after_reboot}=  Get PEL Log Via BMC CLI
133
134    List Should Contain Sub List  ${pel_after_reboot}  ${pel_before_reboot}
135
136
137Verify PEL ID Numbering
138    [Documentation]  Verify PEL ID numbering.
139    [Tags]  Verify_PEL_ID_Numbering
140
141    Redfish Purge Event Log
142    Create Test PEL Log
143    Create Test PEL Log
144
145    ${pel_ids}=  Get PEL Log Via BMC CLI
146
147    # Example of PEL IDs from PEL logs.
148    #  [0x50000012]:             <--- First PEL ID
149    #    [CreatorID]:                  BMC
150    #    [CompID]:                     0x1000
151    #    [PLID]:                       0x50000012
152    #    [Subsystem]:                  BMC Firmware
153    #    [Message]:                    An application had an internal failure
154    #    [SRC]:                        BD8D1002
155    #    [Commit Time]:                03/02/2020  09:35:15
156    #    [Sev]:                        Unrecoverable Error
157    #
158    #  [0x50000013]:             <--- Second PEL ID
159    #    [CreatorID]:                  BMC
160    #    [CompID]:                     0x1000
161    #    [PLID]:                       0x50000013
162    #    [Subsystem]:                  BMC Firmware
163    #    [Message]:                    An application had an internal failure
164    #    [SRC]:                        BD8D1002
165    #    [Commit Time]:                03/02/2020  09:35:15
166    #    [Sev]:                        Unrecoverable Error
167
168    Should Be True  ${pel_ids[1]} == ${pel_ids[0]}+1
169
170Verify Machine Type Model And Serial Number
171    [Documentation]  Verify machine type model and serial number from PEL.
172    [Tags]  Verify_Machine_Type_Model_And_Serial_Number
173
174    Create Test PEL Log
175
176    ${pel_ids}=  Get PEL Log Via BMC CLI
177    ${id}=  Get From List  ${pel_ids}  -1
178
179    ${pel_serial_number}=  Get PEL Field Value  ${id}  Failing MTMS  Serial Number
180    ${pel_serial_number}=  Replace String Using Regexp  ${pel_serial_number}  ^0+  ${EMPTY}
181    ${pel_machine_type_model}=  Get PEL Field Value  ${id}  Failing MTMS  Machine Type Model
182    ${pel_machine_type_model}=  Replace String Using Regexp  ${pel_machine_type_model}  ^0+  ${EMPTY}
183
184    # Example of "Machine Type Model" and "Serial Number" fields value from "Failing MTMS" section of PEL.
185    #  [Failing MTMS]:
186    #    [Created by]:                                 0x2000
187    #    [Machine Type Model]:                         1234-ABC   <---- Machine type
188    #    [Section Version]:                            1
189    #    [Serial Number]:                              ABCDEFG    <---- Serial number
190    #    [Sub-section type]:                           0
191
192    ${redfish_machine_model}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  Model
193    ${redfish_machine_model}=  Replace String Using Regexp  ${redfish_machine_model}  ^0+  ${EMPTY}
194    ${redfish_serial_number}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  SerialNumber
195    ${redfish_serial_number}=  Replace String Using Regexp  ${redfish_serial_number}  ^0+  ${EMPTY}
196
197    Valid Value  pel_machine_type_model  ['${redfish_machine_model}']
198    Valid Value  pel_serial_number  ['${redfish_serial_number}']
199
200    # Check "Machine Type Model" and "Serial Number" fields value from "Extended User Header" section of PEL.
201    ${pel_machine_type_model}=  Get PEL Field Value  ${id}  Extended User Header  Reporting Machine Type
202    ${pel_machine_type_model}=  Replace String Using Regexp  ${pel_machine_type_model}  ^0+  ${EMPTY}
203    ${pel_serial_number}=  Get PEL Field Value  ${id}  Extended User Header  Reporting Serial Number
204    ${pel_serial_number}=  Replace String Using Regexp  ${pel_serial_number}  ^0+  ${EMPTY}
205
206    Valid Value  pel_machine_type_model  ['${redfish_machine_model}']
207    Valid Value  pel_serial_number  ['${redfish_serial_number}']
208
209
210Verify Host Off State From PEL
211    [Documentation]  Verify Host off state from PEL.
212    [Tags]  Verify_Host_Off_State_From_PEL
213
214    Redfish Power Off  stack_mode=skip
215    Create Test PEL Log
216
217    ${pel_ids}=  Get PEL Log Via BMC CLI
218    ${id}=  Get From List  ${pel_ids}  -1
219    ${pel_host_state}=  Get PEL Field Value  ${id}  User Data  HostState
220
221    Valid Value  pel_host_state  ['Off']
222
223
224Verify BMC Version From PEL
225    [Documentation]  Verify BMC Version from PEL.
226    [Tags]  Verify_BMC_Version_From_PEL
227
228    Create Test PEL Log
229
230    ${pel_ids}=  Get PEL Log Via BMC CLI
231    ${id}=  Get From List  ${pel_ids}  -1
232    ${pel_bmc_version}=  Get PEL Field Value  ${id}  User Data  BMC Version ID
233
234    ${bmc_version}=  Get BMC Version
235    Valid Value  bmc_version  ['${bmc_version}']
236
237
238Verify PEL Log After Host Poweron
239    [Documentation]  Verify PEL log generation while booting host.
240    [Tags]  Verify_PEL_Log_After_Host_Poweron
241
242    Redfish Power Off  stack_mode=skip
243    Redfish Purge Event Log
244    Redfish Power On  stack_mode=skip
245
246    ${pel_informational_error}=  Get PEL Log IDs  User Header  Event Severity  Informational Event
247    ${pel_bmc_created_error}=  Get PEL Log IDs  Private Header  Creator Subsystem  BMC
248
249    # Get BMC created non-infomational error.
250    ${pel_bmc_error}=  Subtract Lists  ${pel_bmc_created_error}  ${pel_informational_error}
251
252    Should Be Empty  ${pel_bmc_error}  msg=Unexpected error log generated during Host poweron.
253
254
255Verify BMC Event Log ID
256    [Documentation]  Verify BMC Event Log ID from PEL.
257    [Tags]  Verify_BMC_Event_Log_ID
258
259    Redfish Purge Event Log
260    Create Test PEL Log
261
262    ${pel_ids}=  Get PEL Log Via BMC CLI
263    ${pel_bmc_event_log_id}=  Get PEL Field Value  ${pel_ids[0]}  Private Header  BMC Event Log Id
264
265    # Example "BMC Event Log Id" field value from "Private Header" section of PEL.
266    #  [Private Header]:
267    #    [Created at]:                 08/24/1928 12:04:06
268    #    [Created by]:                 0x584D
269    #    [Sub-section type]:           0
270    #    [Entry Id]:                   0x50000BB7
271    #    [Platform Log Id]:            0x8200061D
272    #    [CSSVER]:
273    #    [Section Version]:            1
274    #    [Creator Subsystem]:          PHYP
275    #    [BMC Event Log Id]:           341      <---- BMC event log id value
276    #    [Committed at]:               03/25/1920 12:06:22
277
278    ${redfish_event_logs}=  Redfish.Get Properties  /redfish/v1/Systems/system/LogServices/EventLog/Entries
279
280    # Example of redfish_event_logs output:
281    # redfish_event_logs:
282    #  [@odata.id]:                    /redfish/v1/Systems/system/LogServices/EventLog/Entries
283    #  [Name]:                         System Event Log Entries
284    #  [Members@odata.count]:          1
285    #  [@odata.type]:                  #LogEntryCollection.LogEntryCollection
286    #  [Description]:                  Collection of System Event Log Entries
287    #  [Members]:
288    #    [0]:
289    #      [@odata.id]:                /redfish/v1/Systems/system/LogServices/EventLog/Entries/235
290    #      [Name]:                     System Event Log Entry
291    #      [Severity]:                 Critical
292    #      [EntryType]:                Event
293    #      [Created]:                  2020-04-02T07:25:13+00:00
294    #      [@odata.type]:              #LogEntry.v1_5_1.LogEntry
295    #      [Id]:                       235          <----- Event log ID
296    #      [Message]:                  xyz.openbmc_project.Common.Error.InternalFailure
297
298    Valid Value  pel_bmc_event_log_id  ['${redfish_event_logs['Members'][0]['Id']}']
299
300
301Verify FRU Callout
302    [Documentation]  Verify FRU callout entries from PEL log.
303    [Tags]  Verify_FRU_Callout
304
305    Create Test PEL Log  FRU Callout
306
307    ${pel_ids}=  Get PEL Log Via BMC CLI
308    ${id}=  Get From List  ${pel_ids}  -1
309    ${pel_callout_section}=  Get PEL Field Value  ${id}  Primary SRC  Callout Section
310
311    # Example of PEL Callout Section from "peltool -i <id>" command.
312    #  [Callouts]:
313    #    [0]:
314    #      [FRU Type]:                 Normal Hardware FRU
315    #      [Priority]:                 Mandatory, replace all with this type as a unit
316    #      [Location Code]:            U78DA.ND1.1234567-P0
317    #      [Part Number]:              F191014
318    #      [CCIN]:                     2E2D
319    #      [Serial Number]:            YL2E2D010000
320    #  [Callout Count]:                1
321
322    Valid Value  pel_callout_section['Callout Count']  ['1']
323    Valid Value  pel_callout_section['Callouts'][0]['FRU Type']  ['Normal Hardware FRU']
324    Should Contain  ${pel_callout_section['Callouts'][0]['Priority']}  Mandatory
325
326    # Verify Location Code field of PEL callout with motherboard's Location Code.
327    ${busctl_output}=  BMC Execute Command  ${CMD_INVENTORY_PREFIX} com.ibm.ipzvpd.Location LocationCode
328    Should Be Equal  ${pel_callout_section['Callouts'][0]['Location Code']}
329    ...  ${busctl_output[0].split('"')[1].strip('"')}
330
331    # TODO: Compare CCIN and part number fields of PEL callout with Redfish or busctl output.
332    Should Match Regexp  ${pel_callout_section['Callouts'][0]['CCIN']}  [a-zA-Z0-9]
333    Should Match Regexp  ${pel_callout_section['Callouts'][0]['Part Number']}  [a-zA-Z0-9]
334
335    # Verify Serial Number field of PEL callout with motherboard's Serial Number.
336    ${busctl_output}=  BMC Execute Command
337    ...  ${CMD_INVENTORY_PREFIX} xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
338    Should Be Equal  ${pel_callout_section['Callouts'][0]['Serial Number']}
339    ...  ${busctl_output[0].split('"')[1].strip('"')}
340
341
342Verify Procedure And Symbolic FRU Callout
343    [Documentation]  Verify procedure and symbolic FRU callout from PEL log.
344    [Tags]  Verify_Procedure_And_Symbolic_FRU_Callout
345
346    Create Test PEL Log   Procedure And Symbolic FRU Callout
347
348    ${pel_ids}=  Get PEL Log Via BMC CLI
349    ${id}=  Get From List  ${pel_ids}  -1
350    ${pel_callout_section}=  Get PEL Field Value  ${id}  Primary SRC  Callout Section
351
352    # Example of PEL Callout Section from "peltool -i <id>" command.
353    #  [Callouts]:
354    #    [0]:
355    #      [Priority]:                                 Mandatory, replace all with this type as a unit
356    #      [Procedure Number]:                         BMCSP02
357    #      [FRU Type]:                                 Maintenance Procedure Required
358    #    [1]:
359    #      [Priority]:                                 Medium Priority
360    #      [Part Number]:                              SVCDOCS
361    #      [FRU Type]:                                 Symbolic FRU
362    #  [Callout Count]:                                2
363
364    Valid Value  pel_callout_section['Callout Count']  ['2']
365
366    # Verify procedural callout info.
367
368    Valid Value  pel_callout_section['Callouts'][0]['FRU Type']  ['Maintenance Procedure Required']
369    Should Contain  ${pel_callout_section['Callouts'][0]['Priority']}  Mandatory
370    # Verify if "Procedure Number" field of PEL has an alphanumeric value.
371    Should Match Regexp  ${pel_callout_section['Callouts'][0]['Procedure']}  [a-zA-Z0-9]
372
373    # Verify procedural callout info.
374
375    Valid Value  pel_callout_section['Callouts'][1]['FRU Type']  ['Symbolic FRU']
376    Should Contain  ${pel_callout_section['Callouts'][1]['Priority']}  Medium Priority
377    # Verify if "Part Number" field of Symbolic FRU has an alphanumeric value.
378    Should Match Regexp  ${pel_callout_section['Callouts'][1]['Part Number']}  [a-zA-Z0-9]
379
380
381Verify PEL Log Entry For Event Log
382    [Documentation]  Create an event log and verify PEL log entry in BMC for the same.
383    [Tags]  Verify_PEL_Log_Entry_For_Event_Log
384
385    Redfish Purge Event Log
386    # Create an internal failure error log.
387    BMC Execute Command  ${CMD_INTERNAL_FAILURE}
388
389    ${elog_entry}=  Get Event Logs
390    # Example of Redfish event logs:
391    # elog_entry:
392    #  [0]:
393    #    [Message]:                                    xyz.openbmc_project.Common.Error.InternalFailure
394    #    [Created]:                                    2020-04-20T01:55:22+00:00
395    #    [Id]:                                         1
396    #    [@odata.id]:                                  /redfish/v1/Systems/system/LogServices/EventLog/Entries/1
397    #    [@odata.type]:                                #LogEntry.v1_4_0.LogEntry
398    #    [EntryType]:                                  Event
399    #    [Severity]:                                   Critical
400    #    [Name]:                                       System Event Log Entry
401
402    ${redfish_log_time}=  Convert Date  ${elog_entry[0]["Created"]}  epoch
403
404    ${pel_records}=  Peltool  -l
405    # Example output from 'Peltool  -l':
406    # pel_records:
407    # [0x50000023]:
408    #   [SRC]:                                        BD8D1002
409    #   [CreatorID]:                                  BMC
410    #   [Message]:                                    An application had an internal failure
411    #   [CompID]:                                     0x1000
412    #   [PLID]:                                       0x50000023
413    #   [Commit Time]:                                04/20/2020 01:55:22
414    #   [Subsystem]:                                  BMC Firmware
415    #   [Sev]:                                        Unrecoverable Error
416
417    ${ids}=  Get Dictionary Keys  ${pel_records}
418    ${id}=  Get From List  ${ids}  0
419    ${pel_log_time}=  Convert Date  ${pel_records['${id}']['Commit Time']}  epoch
420    ...  date_format=%m/%d/%Y %H:%M:%S
421
422    # Verify that both Redfish event and PEL has log entry for internal error with same time stamp.
423    Should Contain Any  ${pel_records['${id}']['Message']}  internal failure  ignore_case=True
424    Should Contain Any  ${elog_entry[0]['Message']}  InternalFailure  ignore_case=True
425
426    Should Be Equal  ${redfish_log_time}  ${pel_log_time}
427
428
429Verify Delete All PEL
430    [Documentation]  Verify deleting all PEL logs.
431    [Tags]  Verify_Delete_All_PEL
432
433    Create Test PEL Log
434    Create Test PEL Log
435    Peltool  --delete-all  False
436
437    ${pel_ids}=  Get PEL Log Via BMC CLI
438    Should Be Empty  ${pel_ids}
439
440
441Verify Informational Error Log
442    [Documentation]  Create an informational error log and verify.
443    [Tags]  Verify_Informational_Error_Log
444
445    Redfish Purge Event Log
446    # Create an informational error log.
447    BMC Execute Command  ${CMD_INFORMATIONAL_ERROR}
448    ${pel_records}=  Peltool  -lfh
449
450    # An example of information error log data:
451    # {
452    #    "0x500006A0": {
453    #            "SRC": "BD8D1002",
454    #            "Message": "An application had an internal failure",
455    #            "PLID": "0x500006A0",
456    #            "CreatorID": "BMC",
457    #            "Subsystem": "BMC Firmware",
458    #            "Commit Time": "10/14/2020 11:41:38",
459    #            "Sev": "Informational Event",
460    #            "CompID": "0x1000"
461    #    }
462    # }
463
464    ${ids}=  Get Dictionary Keys  ${pel_records}
465    ${id}=  Get From List  ${ids}  0
466    Should Contain  ${pel_records['${id}']['Sev']}  Informational
467
468
469Verify Predictable Error Log
470    [Documentation]  Create a predictive error and verify.
471    [Tags]  Verify_Predictable_Error_Log
472
473    # Create a predictable error log.
474    BMC Execute Command  ${CMD_PREDICTIVE_ERROR}
475    ${pel_records}=  Peltool  -l
476
477    # An example of predictive error log data:
478    # {
479    #    "0x5000069E": {
480    #            "SRC": "BD8D1002",
481    #            "Message": "An application had an internal failure",
482    #            "PLID": "0x5000069E",
483    #            "CreatorID": "BMC",
484    #            "Subsystem": "BMC Firmware",
485    #            "Commit Time": "10/14/2020 11:40:07",
486    #            "Sev": "Predictive Error",
487    #            "CompID": "0x1000"
488    #    }
489    # }
490
491    ${pel_ids}=  Get PEL Log Via BMC CLI
492    ${id}=  Get From List  ${pel_ids}  -1
493    Should Contain  ${pel_records['${id}']['Sev']}  Predictive
494
495
496Verify Unrecoverable Error Log
497    [Documentation]  Create an unrecoverable error and verify.
498    [Tags]  Verify_Unrecoverable_Error_Log
499
500    # Create an internal failure error log.
501    BMC Execute Command  ${CMD_UNRECOVERABLE_ERROR}
502    ${pel_records}=  Peltool  -l
503
504    # An example of unrecoverable error log data:
505    # {
506    #    "0x50000CC5": {
507    #            "SRC": "BD8D1002",
508    #            "Message": "An application had an internal failure",
509    #            "PLID": "0x50000CC5",
510    #            "CreatorID": "BMC",
511    #            "Subsystem": "BMC Firmware",
512    #            "Commit Time": "04/01/2020 16:44:55",
513    #            "Sev": "Unrecoverable Error",
514    #            "CompID": "0x1000"
515    #    }
516    # }
517
518    ${pel_ids}=  Get PEL Log Via BMC CLI
519    ${id}=  Get From List  ${pel_ids}  -1
520    Should Contain  ${pel_records['${id}']['Sev']}  Unrecoverable
521
522
523Verify Informational Error Log Size When Error Log Exceeds Limit
524    [Documentation]  Verify informational error log size when informational log size exceeds limit.
525    [Tags]  Verify_Informational_Error_Log_Error_Log_When_Size_Exceeds_Limit
526
527    # Initially remove all logs.
528    Redfish Purge Event Log
529
530    # Create 3001 information logs.
531    FOR  ${LOG_COUNT}  IN RANGE  0  3001
532      BMC Execute Command  ${CMD_INFORMATIONAL_ERROR}
533    END
534
535    # Delay for BMC to perform log compression when log size exceeds.
536    Sleep  10s
537
538    # Check logsize and verify that disk usage is around 15%.
539    ${usage_percent}=  Get Disk Usage For Error Logs
540    ${percent_diff}=  Evaluate  ${usage_percent} - ${info_log_max_usage_percentage}
541    ${percent_diff}=   Evaluate  abs(${percent_diff})
542    Should Be True  ${percent_diff} <= 0.5
543
544
545Verify Reverse Order Of PEL Logs
546    [Documentation]  Verify PEL command to output PEL logs in reverse order.
547    [Tags]  Verify_Reverse_PEL_Logs
548
549    Redfish Purge Event Log
550    BMC Execute Command  ${CMD_UNRECOVERABLE_ERROR}
551    BMC Execute Command  ${CMD_PREDICTIVE_ERROR}
552
553    ${pel_records}=  Peltool  -rl
554    ${pel_ids}=  Get Dictionary Keys   ${pel_records}   False
555
556    Should Be True  ${pel_ids}[0] > ${pel_ids}[1]
557
558
559Verify Total PEL Count
560    [Documentation]  Verify total PEL count returned by peltool command.
561    [Tags]  Verify_Total_PEL_Count
562
563    # Initially remove all logs.
564    Redfish Purge Event Log
565
566    # Generate a random number between 1-20.
567    ${random}=  Evaluate  random.randint(1, 20)  modules=random
568
569    # Generate predictive error log multiple times.
570    FOR  ${count}  IN RANGE  0  ${random}
571      BMC Execute Command  ${CMD_PREDICTIVE_ERROR}
572    END
573
574    # Check PEL log count via peltool command and compare it with actual generated log count.
575    ${pel_records}=  peltool  -n
576
577    Should Be Equal  ${pel_records['Number of PELs found']}   ${random}
578
579
580Verify Listing Information Error
581    [Documentation]  Verify that information error logs can only be listed using -lfh option of peltool.
582    [Tags]  Verify_Listing_Information_Error
583
584    # Initially remove all logs.
585    Redfish Purge Event Log
586    BMC Execute Command  ${CMD_INFORMATIONAL_ERROR}
587
588    # Generate informational logs and verify that it would not get listed by peltool's list command.
589    ${pel_records}=  peltool  -l
590    ${pel_ids}=  Get PEL Log Via BMC CLI
591    ${id}=  Get From List  ${pel_ids}  -1
592    Should Not Contain  ${pel_records['${id}']['Sev']}  Informational
593
594    # Verify that information logs get listed using peltool's list command with -lfh option.
595    ${pel_records}=  peltool  -lfh
596    ${pel_ids}=  Get PEL Log Via BMC CLI
597    ${id}=  Get From List  ${pel_ids}  -1
598    Should Contain  ${pel_records['${id}']['Sev']}  Informational
599
600
601*** Keywords ***
602
603Get Disk Usage For Error Logs
604    [Documentation]  Get disk usage percentage for error logs.
605
606    ${usage_output}  ${stderr}  ${rc}=  BMC Execute Command  du /var/lib/phosphor-logging/errors
607
608    ${usage_output}=  Fetch From Left  ${usage_output}  \/
609
610    # Covert disk usage unit from KB to MB.
611    ${usage_output}=  Evaluate  ${usage_output} / 1024
612
613    # Logging disk capacity limit is set to 20MB. So calculating the log usage percentage.
614    ${usage_percent}=  Evaluate  ${usage_output} / 20 * 100
615
616    [return]  ${usage_percent}
617
618
619Create Test PEL Log
620    [Documentation]  Generate test PEL log.
621    [Arguments]  ${pel_type}=Internal Failure
622
623    # Description of argument(s):
624    # pel_type      The PEL type (e.g. Internal Failure, FRU Callout, Procedural Callout).
625
626    # Test PEL log entry example:
627    # {
628    #    "0x5000002D": {
629    #            "SRC": "BD8D1002",
630    #            "Message": "An application had an internal failure",
631    #            "PLID": "0x5000002D",
632    #            "CreatorID": "BMC",
633    #            "Subsystem": "BMC Firmware",
634    #            "Commit Time": "02/25/2020  04:47:09",
635    #            "Sev": "Unrecoverable Error",
636    #            "CompID": "0x1000"
637    #    }
638    # }
639
640    Run Keyword If  '${pel_type}' == 'Internal Failure'
641    ...   BMC Execute Command  ${CMD_INTERNAL_FAILURE}
642    ...  ELSE IF  '${pel_type}' == 'FRU Callout'
643    ...   BMC Execute Command  ${CMD_FRU_CALLOUT}
644    ...  ELSE IF  '${pel_type}' == 'Procedure And Symbolic FRU Callout'
645    ...   BMC Execute Command  ${CMD_PROCEDURAL_SYMBOLIC_FRU_CALLOUT}
646
647
648Get PEL Log IDs
649    [Documentation]  Returns the list of PEL log IDs which contains given field's value.
650    [Arguments]  ${pel_section}  ${pel_field}  @{pel_field_value}
651
652    # Description of argument(s):
653    # pel_section      The section of PEL (e.g. Private Header, User Header).
654    # pel_field        The PEL field (e.g. Event Severity, Event Type).
655    # pel_field_value  The list of PEL's field value (e.g. Unrecoverable Error).
656
657    ${pel_ids}=  Get PEL Log Via BMC CLI
658    @{pel_id_list}=  Create List
659
660    FOR  ${id}  IN  @{pel_ids}
661      ${pel_output}=  Peltool  -i ${id}
662      # Example of PEL output from "peltool -i <id>" command.
663      #  [Private Header]:
664      #    [Created at]:                                 08/24/1928 12:04:06
665      #    [Created by]:                                 0x584D
666      #    [Sub-section type]:                           0
667      #    [Entry Id]:                                   0x50000BB7
668      #    [Platform Log Id]:                            0x8200061D
669      #    [CSSVER]:
670      #    [Section Version]:                            1
671      #    [Creator Subsystem]:                          PHYP
672      #    [BMC Event Log Id]:                           341
673      #    [Committed at]:                               03/25/1920 12:06:22
674      #  [User Header]:
675      #    [Log Committed by]:                           0x4552
676      #    [Action Flags]:
677      #      [0]:                                        Report Externally
678      #    [Subsystem]:                                  I/O Subsystem
679      #    [Event Type]:                                 Miscellaneous, Informational Only
680      #    [Sub-section type]:                           0
681      #    [Event Scope]:                                Entire Platform
682      #    [Event Severity]:                             Informational Event
683      #    [Host Transmission]:                          Not Sent
684      #    [Section Version]:                            1
685
686      ${pel_section_output}=  Get From Dictionary  ${pel_output}  ${pel_section}
687      ${pel_field_output}=  Get From Dictionary  ${pel_section_output}  ${pel_field}
688      Run Keyword If  '${pel_field_output}' in @{pel_field_value}  Append To List  ${pel_id_list}  ${id}
689    END
690    Sort List  ${pel_id_list}
691
692    [Return]  ${pel_id_list}
693
694
695Get PEL Log Via BMC CLI
696    [Documentation]  Returns the list of PEL IDs using BMC CLI.
697
698    ${pel_records}=  Peltool  -l
699    ${ids}=  Get Dictionary Keys  ${pel_records}
700    Sort List  ${ids}
701
702    [Return]  ${ids}
703
704
705Get PEL Field Value
706    [Documentation]  Returns the value of given PEL's field.
707    [Arguments]  ${pel_id}  ${pel_section}  ${pel_field}
708
709    # Description of argument(s):
710    # pel_id           The ID of PEL (e.g. 0x5000002D, 0x5000002E).
711    # pel_section      The section of PEL (e.g. Private Header, User Header)
712    # pel_field        The PEL field (e.g. Event Severity, Event Type).
713
714    ${pel_output}=  Peltool  -i ${pel_id}
715
716    # Example of PEL output from "peltool -i <id>" command.
717    #  [Private Header]:
718    #    [Created at]:                                 08/24/1928 12:04:06
719    #    [Created by]:                                 0x584D
720    #    [Sub-section type]:                           0
721    #    [Entry Id]:                                   0x50000BB7
722    #    [Platform Log Id]:                            0x8200061D
723    #    [CSSVER]:
724    #    [Section Version]:                            1
725    #    [Creator Subsystem]:                          PHYP
726    #    [BMC Event Log Id]:                           341
727    #    [Committed at]:                               03/25/1920 12:06:22
728    #  [User Header]:
729    #    [Log Committed by]:                           0x4552
730    #    [Action Flags]:
731    #      [0]:                                        Report Externally
732    #    [Subsystem]:                                  I/O Subsystem
733    #    [Event Type]:                                 Miscellaneous, Informational Only
734    #    [Sub-section type]:                           0
735    #    [Event Scope]:                                Entire Platform
736    #    [Event Severity]:                             Informational Event
737    #    [Host Transmission]:                          Not Sent
738    #    [Section Version]:                            1
739
740    ${pel_section_output}=  Get From Dictionary  ${pel_output}  ${pel_section}
741    ${pel_field_output}=  Get From Dictionary  ${pel_section_output}  ${pel_field}
742
743    [Return]  ${pel_field_output}
744