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/openbmc_ffdc.robot
8
9Test Setup      Redfish.Login
10Test Teardown   Run Keywords  Redfish.Logout  AND  FFDC On Test Case Fail
11
12
13*** Variables ***
14
15${CMD_INTERNAL_FAILURE}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
16...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
17...  xyz.openbmc_project.Logging.Entry.Level.Error 0
18
19
20*** Test Cases ***
21
22Create Test PEL Log And Verify
23    [Documentation]  Create PEL log using busctl command and verify via peltool.
24    [Tags]  Create_Test_PEL_Log_And_Verify
25
26    Redfish Purge Event Log
27    Create Test PEL Log
28    ${pel_id}=  Get PEL Log Via BMC CLI
29    Should Not Be Empty  ${pel_id}  msg=System PEL log entry is empty.
30
31
32Verify PEL Log Details
33    [Documentation]  Verify PEL log details via peltool.
34    [Tags]  Verify_PEL_Log_Details
35
36    Redfish Purge Event Log
37
38    ${bmc_time1}=  CLI Get BMC DateTime
39    Create Test PEL Log
40    ${bmc_time2}=  CLI Get BMC DateTime
41
42    ${pel_records}=  Peltool  -l
43
44    # Example output from 'Peltool  -l':
45    # pel_records:
46    # [0x50000012]:
47    #   [CreatorID]:                  BMC
48    #   [CompID]:                     0x1000
49    #   [PLID]:                       0x50000012
50    #   [Subsystem]:                  BMC Firmware
51    #   [Message]:                    An application had an internal failure
52    #   [SRC]:                        BD8D1002
53    #   [Commit Time]:                03/02/2020  09:35:15
54    #   [Sev]:                        Unrecoverable Error
55
56    ${ids}=  Get Dictionary Keys  ${pel_records}
57    ${id}=  Get From List  ${ids}  0
58
59    @{pel_fields}=  Create List  CreatorID  Subsystem  Message  Sev
60    FOR  ${field}  IN  @{pel_fields}
61      Valid Value  pel_records['${id}']['${field}']  ['${PEL_DETAILS['${field}']}']
62    END
63
64    Valid Value  pel_records['${id}']['PLID']  ['${id}']
65
66    # Verify if "CompID" and "SRC" fields of PEL has alphanumeric value.
67    Should Match Regexp  ${pel_records['${id}']['CompID']}  [a-zA-Z0-9]
68    Should Match Regexp  ${pel_records['${id}']['SRC']}  [a-zA-Z0-9]
69
70    ${pel_date_time}=  Convert Date  ${pel_records['${id}']['Commit Time']}
71    ...  date_format=%m/%d/%Y %H:%M:%S  exclude_millis=yes
72
73    # Convert BMC and PEL time to epoch time before comparing.
74    ${bmc_time1_epoch}=  Convert Date  ${bmc_time1}  epoch
75    ${pel_time_epoch}=  Convert Date  ${pel_date_time}  epoch
76    ${bmc_time2_epoch}=  Convert Date  ${bmc_time2}  epoch
77
78    Should Be True  ${bmc_time1_epoch} <= ${pel_time_epoch} <= ${bmc_time2_epoch}
79
80
81Verify PEL Log Persistence After BMC Reboot
82    [Documentation]  Verify PEL log persistence after BMC reboot.
83    [Tags]  Verify_PEL_Log_Persistence_After_BMC_Reboot
84
85    Create Test PEL Log
86    ${pel_before_reboot}=  Get PEL Log Via BMC CLI
87
88    Redfish OBMC Reboot (off)
89    ${pel_after_reboot}=  Get PEL Log Via BMC CLI
90
91    List Should Contain Sub List  ${pel_after_reboot}  ${pel_before_reboot}
92
93
94Verify PEL ID Numbering
95    [Documentation]  Verify PEL ID numbering.
96    [Tags]  Verify_PEL_ID_Numbering
97
98    Redfish Purge Event Log
99    Create Test PEL Log
100    Create Test PEL Log
101
102    ${pel_ids}=  Get PEL Log Via BMC CLI
103
104    # Example of PEL IDs from PEL logs.
105    #  [0x50000012]:             <--- First PEL ID
106    #    [CreatorID]:                  BMC
107    #    [CompID]:                     0x1000
108    #    [PLID]:                       0x50000012
109    #    [Subsystem]:                  BMC Firmware
110    #    [Message]:                    An application had an internal failure
111    #    [SRC]:                        BD8D1002
112    #    [Commit Time]:                03/02/2020  09:35:15
113    #    [Sev]:                        Unrecoverable Error
114    #
115    #  [0x50000013]:             <--- Second PEL ID
116    #    [CreatorID]:                  BMC
117    #    [CompID]:                     0x1000
118    #    [PLID]:                       0x50000013
119    #    [Subsystem]:                  BMC Firmware
120    #    [Message]:                    An application had an internal failure
121    #    [SRC]:                        BD8D1002
122    #    [Commit Time]:                03/02/2020  09:35:15
123    #    [Sev]:                        Unrecoverable Error
124
125    Should Be True  ${pel_ids[1]} == ${pel_ids[0]}+1
126
127Verify Machine Type Model And Serial Number
128    [Documentation]  Verify machine type model and serial number from PEL.
129    [Tags]  Verify_Machine_Type_Model_And_Serial_Number
130
131    Create Test PEL Log
132
133    ${pel_ids}=  Get PEL Log Via BMC CLI
134    ${id}=  Get From List  ${pel_ids}  -1
135
136    ${pel_serial_number}=  Get PEL Field Value  ${id}  Failing MTMS  Serial Number
137    ${pel_serial_number}=  Replace String Using Regexp  ${pel_serial_number}  ^0+  ${EMPTY}
138    ${pel_machine_type_model}=  Get PEL Field Value  ${id}  Failing MTMS  Machine Type Model
139    ${pel_machine_type_model}=  Replace String Using Regexp  ${pel_machine_type_model}  ^0+  ${EMPTY}
140
141    # Example of "Machine Type Model" and "Serial Number" fields value from "Failing MTMS" section of PEL.
142    #  [Failing MTMS]:
143    #    [Created by]:                                 0x2000
144    #    [Machine Type Model]:                         1234-ABC   <---- Machine type
145    #    [Section Version]:                            1
146    #    [Serial Number]:                              ABCDEFG    <---- Serial number
147    #    [Sub-section type]:                           0
148
149    ${redfish_machine_model}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  Model
150    ${redfish_machine_model}=  Replace String Using Regexp  ${redfish_machine_model}  ^0+  ${EMPTY}
151    ${redfish_serial_number}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  SerialNumber
152    ${redfish_serial_number}=  Replace String Using Regexp  ${redfish_serial_number}  ^0+  ${EMPTY}
153
154    Valid Value  pel_machine_type_model  ['${redfish_machine_model}']
155    Valid Value  pel_serial_number  ['${redfish_serial_number}']
156
157    # Check "Machine Type Model" and "Serial Number" fields value from "Extended User Header" section of PEL.
158    ${pel_machine_type_model}=  Get PEL Field Value  ${id}  Extended User Header  Reporting Machine Type
159    ${pel_machine_type_model}=  Replace String Using Regexp  ${pel_machine_type_model}  ^0+  ${EMPTY}
160    ${pel_serial_number}=  Get PEL Field Value  ${id}  Extended User Header  Reporting Serial Number
161    ${pel_serial_number}=  Replace String Using Regexp  ${pel_serial_number}  ^0+  ${EMPTY}
162
163    Valid Value  pel_machine_type_model  ['${redfish_machine_model}']
164    Valid Value  pel_serial_number  ['${redfish_serial_number}']
165
166
167Verify Host Off State From PEL
168    [Documentation]  Verify Host off state from PEL.
169    [Tags]  Verify_Host_Off_State_From_PEL
170
171    Redfish Power Off  stack_mode=skip
172    Create Test PEL Log
173
174    ${pel_ids}=  Get PEL Log Via BMC CLI
175    ${id}=  Get From List  ${pel_ids}  -1
176    ${pel_host_state}=  Get PEL Field Value  ${id}  User Data  HostState
177
178    Valid Value  pel_host_state  ['Off']
179
180
181Verify BMC Version From PEL
182    [Documentation]  Verify BMC Version from PEL.
183    [Tags]  Verify_BMC_Version_From_PEL
184
185    Create Test PEL Log
186
187    ${pel_ids}=  Get PEL Log Via BMC CLI
188    ${id}=  Get From List  ${pel_ids}  -1
189    ${pel_bmc_version}=  Get PEL Field Value  ${id}  User Data  BMC Version ID
190
191    ${bmc_version}=  Get BMC Version
192    Valid Value  bmc_version  ['${bmc_version}']
193
194
195Verify PEL Log After Host Poweron
196    [Documentation]  Verify PEL log generation while booting host.
197    [Tags]  Verify_PEL_Log_After_Host_Poweron
198
199    Redfish Power Off  stack_mode=skip
200    Redfish Purge Event Log
201    Redfish Power On  stack_mode=skip
202
203    ${pel_informational_error}=  Get PEL Log IDs  User Header  Event Severity  Informational Event
204    ${pel_bmc_created_error}=  Get PEL Log IDs  Private Header  Creator Subsystem  BMC
205
206    # Get BMC created non-infomational error.
207    ${pel_bmc_error}=  Subtract Lists  ${pel_bmc_created_error}  ${pel_informational_error}
208
209    Should Be Empty  ${pel_bmc_error}  msg=Unexpected error log generated during Host poweron.
210
211
212Verify BMC Event Log ID
213    [Documentation]  Verify BMC Event Log ID from PEL.
214    [Tags]  Verify_BMC_Event_Log_ID
215
216    Redfish Purge Event Log
217    Create Test PEL Log
218
219    ${pel_ids}=  Get PEL Log Via BMC CLI
220    ${pel_bmc_event_log_id}=  Get PEL Field Value  ${pel_ids[0]}  Private Header  BMC Event Log Id
221
222    # Example "BMC Event Log Id" field value from "Private Header" section of PEL.
223    #  [Private Header]:
224    #    [Created at]:                 08/24/1928 12:04:06
225    #    [Created by]:                 0x584D
226    #    [Sub-section type]:           0
227    #    [Entry Id]:                   0x50000BB7
228    #    [Platform Log Id]:            0x8200061D
229    #    [CSSVER]:
230    #    [Section Version]:            1
231    #    [Creator Subsystem]:          PHYP
232    #    [BMC Event Log Id]:           341      <---- BMC event log id value
233    #    [Committed at]:               03/25/1920 12:06:22
234
235    ${redfish_event_logs}=  Redfish.Get Properties  /redfish/v1/Systems/system/LogServices/EventLog/Entries
236
237    # Example of redfish_event_logs output:
238    # redfish_event_logs:
239    #  [@odata.id]:                    /redfish/v1/Systems/system/LogServices/EventLog/Entries
240    #  [Name]:                         System Event Log Entries
241    #  [Members@odata.count]:          1
242    #  [@odata.type]:                  #LogEntryCollection.LogEntryCollection
243    #  [Description]:                  Collection of System Event Log Entries
244    #  [Members]:
245    #    [0]:
246    #      [@odata.id]:                /redfish/v1/Systems/system/LogServices/EventLog/Entries/235
247    #      [Name]:                     System Event Log Entry
248    #      [Severity]:                 Critical
249    #      [EntryType]:                Event
250    #      [Created]:                  2020-04-02T07:25:13+00:00
251    #      [@odata.type]:              #LogEntry.v1_5_1.LogEntry
252    #      [Id]:                       235          <----- Event log ID
253    #      [Message]:                  xyz.openbmc_project.Common.Error.InternalFailure
254
255    Valid Value  pel_bmc_event_log_id  ['${redfish_event_logs['Members'][0]['Id']}']
256
257
258Verify Delete All PEL
259    [Documentation]  Verify deleting all PEL logs.
260    [Tags]  Verify_Delete_All_PEL
261
262    Create Test PEL Log
263    Create Test PEL Log
264    Peltool  --delete-all  False
265
266    ${pel_ids}=  Get PEL Log Via BMC CLI
267    Should Be Empty  ${pel_ids}
268
269
270*** Keywords ***
271
272Create Test PEL Log
273    [Documentation]  Generate test PEL log.
274
275    # Test PEL log entry example:
276    # {
277    #    "0x5000002D": {
278    #            "SRC": "BD8D1002",
279    #            "Message": "An application had an internal failure",
280    #            "PLID": "0x5000002D",
281    #            "CreatorID": "BMC",
282    #            "Subsystem": "BMC Firmware",
283    #            "Commit Time": "02/25/2020  04:47:09",
284    #            "Sev": "Unrecoverable Error",
285    #            "CompID": "0x1000"
286    #    }
287    # }
288
289    BMC Execute Command  ${CMD_INTERNAL_FAILURE}
290
291
292Get PEL Log IDs
293    [Documentation]  Returns the list of PEL log IDs which contains given field's value.
294    [Arguments]  ${pel_section}  ${pel_field}  @{pel_field_value}
295
296    # Description of argument(s):
297    # pel_section      The section of PEL (e.g. Private Header, User Header).
298    # pel_field        The PEL field (e.g. Event Severity, Event Type).
299    # pel_field_value  The list of PEL's field value (e.g. Unrecoverable Error).
300
301    ${pel_ids}=  Get PEL Log Via BMC CLI
302    @{pel_id_list}=  Create List
303
304    FOR  ${id}  IN  @{pel_ids}
305      ${pel_output}=  Peltool  -i ${id}
306      # Example of PEL output from "peltool -i <id>" command.
307      #  [Private Header]:
308      #    [Created at]:                                 08/24/1928 12:04:06
309      #    [Created by]:                                 0x584D
310      #    [Sub-section type]:                           0
311      #    [Entry Id]:                                   0x50000BB7
312      #    [Platform Log Id]:                            0x8200061D
313      #    [CSSVER]:
314      #    [Section Version]:                            1
315      #    [Creator Subsystem]:                          PHYP
316      #    [BMC Event Log Id]:                           341
317      #    [Committed at]:                               03/25/1920 12:06:22
318      #  [User Header]:
319      #    [Log Committed by]:                           0x4552
320      #    [Action Flags]:
321      #      [0]:                                        Report Externally
322      #    [Subsystem]:                                  I/O Subsystem
323      #    [Event Type]:                                 Miscellaneous, Informational Only
324      #    [Sub-section type]:                           0
325      #    [Event Scope]:                                Entire Platform
326      #    [Event Severity]:                             Informational Event
327      #    [Host Transmission]:                          Not Sent
328      #    [Section Version]:                            1
329
330      ${pel_section_output}=  Get From Dictionary  ${pel_output}  ${pel_section}
331      ${pel_field_output}=  Get From Dictionary  ${pel_section_output}  ${pel_field}
332      Run Keyword If  '${pel_field_output}' in @{pel_field_value}  Append To List  ${pel_id_list}  ${id}
333    END
334    Sort List  ${pel_id_list}
335
336    [Return]  ${pel_id_list}
337
338
339Get PEL Log Via BMC CLI
340    [Documentation]  Returns the list of PEL IDs using BMC CLI.
341
342    ${pel_records}=  Peltool  -l
343    ${ids}=  Get Dictionary Keys  ${pel_records}
344    Sort List  ${ids}
345
346    [Return]  ${ids}
347
348
349Get PEL Field Value
350    [Documentation]  Returns the value of given PEL's field.
351    [Arguments]  ${pel_id}  ${pel_section}  ${pel_field}
352
353    # Description of argument(s):
354    # pel_id           The ID of PEL (e.g. 0x5000002D, 0x5000002E).
355    # pel_section      The section of PEL (e.g. Private Header, User Header)
356    # pel_field        The PEL field (e.g. Event Severity, Event Type).
357
358    ${pel_output}=  Peltool  -i ${pel_id}
359
360    # Example of PEL output from "peltool -i <id>" command.
361    #  [Private Header]:
362    #    [Created at]:                                 08/24/1928 12:04:06
363    #    [Created by]:                                 0x584D
364    #    [Sub-section type]:                           0
365    #    [Entry Id]:                                   0x50000BB7
366    #    [Platform Log Id]:                            0x8200061D
367    #    [CSSVER]:
368    #    [Section Version]:                            1
369    #    [Creator Subsystem]:                          PHYP
370    #    [BMC Event Log Id]:                           341
371    #    [Committed at]:                               03/25/1920 12:06:22
372    #  [User Header]:
373    #    [Log Committed by]:                           0x4552
374    #    [Action Flags]:
375    #      [0]:                                        Report Externally
376    #    [Subsystem]:                                  I/O Subsystem
377    #    [Event Type]:                                 Miscellaneous, Informational Only
378    #    [Sub-section type]:                           0
379    #    [Event Scope]:                                Entire Platform
380    #    [Event Severity]:                             Informational Event
381    #    [Host Transmission]:                          Not Sent
382    #    [Section Version]:                            1
383
384    ${pel_section_output}=  Get From Dictionary  ${pel_output}  ${pel_section}
385    ${pel_field_output}=  Get From Dictionary  ${pel_section_output}  ${pel_field}
386
387    [Return]  ${pel_field_output}
388