1*** Settings ***
2Documentation    Error logging utility keywords.
3
4Resource        rest_client.robot
5Resource        bmc_redfish_utils.robot
6Variables       ../data/variables.py
7Variables       ../data/pel_variables.py
8
9*** Variables ***
10
11
12# Define variables for use by callers of 'Get Error Logs'.
13${low_severity_errlog_regex}  \\.(Informational|Notice|Debug|OK)$
14&{low_severity_errlog_filter}  Severity=${low_severity_errlog_regex}
15&{low_severity_errlog_filter_args}  filter_dict=${low_severity_errlog_filter}  regex=${True}  invert=${True}
16# The following is equivalent to &{low_severity_errlog_filter_args} but the name may be more intuitive for
17# users. Example usage:
18# ${err_logs}=  Get Error Logs  &{filter_low_severity_errlogs}
19&{filter_low_severity_errlogs}  &{low_severity_errlog_filter_args}
20
21*** Keywords ***
22
23Filter Expected Logging Events
24    [Documentation]  Get redfish logging entry, remove the user input expected
25    ...              log event and return the object list.
26    [Arguments]  ${expected_event}=None
27
28    # Description of argument(s):
29    # expected_eventd   Event log list.
30
31    ${all_event_list}=  Get Redfish Event Logs
32    Remove Values From List  ${all_event_list}  ${expected_event}
33
34    [Return]  ${all_event_list}
35
36
37Get Logging Entry List
38    [Documentation]  Get logging entry and return the object list.
39
40    ${entry_list}=  Create List
41    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
42    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
43
44    FOR  ${entry}  IN  @{resp.json()["data"]}
45        Continue For Loop If  '${entry.rsplit('/', 1)[1]}' == 'callout'
46        Append To List  ${entry_list}  ${entry}
47    END
48
49    # Logging entries list.
50    # ['/xyz/openbmc_project/logging/entry/14',
51    #  '/xyz/openbmc_project/logging/entry/15']
52    [Return]  ${entry_list}
53
54
55Logging Entry Should Exist
56    [Documentation]  Find the matching message id and return the entry id.
57    [Arguments]  ${message_id}
58
59    # Description of argument(s):
60    # message_id    Logging message string.
61    #               Example: "xyz.openbmc_project.Common.Error.InternalFailure"
62
63    @{elog_entries}=  Get Logging Entry List
64
65    FOR  ${entry}  IN  @{elog_entries}
66         ${resp}=  Read Properties  ${entry}
67         ${status}=  Run Keyword And Return Status
68         ...  Should Be Equal As Strings  ${message_id}  ${resp["Message"]}
69         Return From Keyword If  ${status} == ${TRUE}  ${entry}
70    END
71
72    Fail  No ${message_id} logging entry found.
73
74
75Get Error Logs
76    [Documentation]  Return the BMC error logs as a dictionary.
77    [Arguments]   ${quiet}=1  &{filter_struct_args}
78
79    # Example of call using pre-defined filter args (defined above).
80
81    # ${err_logs}=  Get Error Logs  &{filter_low_severity_errlogs}
82
83    # In this example, all error logs with "Severity" fields that are neither Informational, Debug nor
84    # Notice will be returned.
85
86    # Description of argument(s):
87    # quiet                         Indicates whether this keyword should run without any output to the
88    #                               console, 0 = verbose, 1 = quiet.
89    # filter_struct_args            filter_struct args (e.g. filter_dict, regex, etc.) to be passed directly
90    #                               to the Filter Struct keyword.  See its prolog for details.
91
92    #  The length of the returned dictionary indicates how many logs there are.
93
94    # Use 'Print Error Logs' to print.  Example:
95
96    # Print Error Logs  ${error_logs}  Message.
97
98    ${status}  ${error_logs}=  Run Keyword And Ignore Error  Read Properties
99    ...  /xyz/openbmc_project/logging/entry/enumerate  timeout=30  quiet=${quiet}
100    Return From Keyword If  '${status}' == 'FAIL'  &{EMPTY}
101    ${num_filter_struct_args}=  Get Length  ${filter_struct_args}
102    Return From Keyword If  '${num_filter_struct_args}' == '${0}'  ${error_logs}
103    ${filtered_error_logs}=  Filter Struct  ${error_logs}  &{filter_struct_args}
104    [Return]  ${filtered_error_logs}
105
106
107Get IPMI SEL Setting
108    [Documentation]  Returns status for given IPMI SEL setting.
109    [Arguments]  ${setting}
110    # Description of argument(s):
111    # setting  SEL setting which needs to be read(e.g. "Last Add Time").
112
113    ${resp}=  Run IPMI Standard Command  sel info
114
115    ${setting_line}=  Get Lines Containing String  ${resp}  ${setting}
116    ...  case-insensitive
117    ${setting_status}=  Fetch From Right  ${setting_line}  :${SPACE}
118
119    [Return]  ${setting_status}
120
121
122Verify Watchdog Errorlog Content
123    [Documentation]  Verify watchdog errorlog content.
124    # Example:
125    # "/xyz/openbmc_project/logging/entry/1":
126    #  {
127    #      "AdditionalData": [],
128    #      "Id": 1,
129    #      "Message": "org.open_power.Host.Boot.Error.WatchdogTimedOut",
130    #      "Resolved": 0,
131    #      "Severity": "xyz.openbmc_project.Logging.Entry.Level.Error",
132    #      "Timestamp": 1492715244828,
133    #      "Associations": []
134    # },
135
136    ${elog_entry}=  Get URL List  ${BMC_LOGGING_ENTRY}
137    ${elog}=  Read Properties  ${elog_entry[0]}
138    Should Be Equal As Strings
139    ...  ${elog["Message"]}  org.open_power.Host.Boot.Error.WatchdogTimedOut
140    ...  msg=Watchdog timeout error log was not found.
141    Should Be Equal As Strings
142    ...  ${elog["Severity"]}  xyz.openbmc_project.Logging.Entry.Level.Error
143    ...  msg=Watchdog timeout severity unexpected value.
144
145
146Logging Test Binary Exist
147    [Documentation]  Verify existence of prerequisite logging-test.
148    ${stdout}  ${stderr}  ${rc}=
149    ...  BMC Execute Command  test -f /tmp/tarball/bin/logging-test  print_out=1
150    Should Be Empty  ${stderr}  msg=Logging Test stderr is non-empty.
151
152
153Clear Existing Error Logs
154    [Documentation]  If error log isn't empty, reboot the BMC to clear the log.
155    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
156    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
157    Initiate BMC Reboot
158    Wait Until Keyword Succeeds  10 min  10 sec
159    ...  Is BMC Ready
160    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
161    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
162    ...  msg=Could not clear BMC error logs.
163
164
165Create Test PEL Log
166    [Documentation]  Generate test PEL log.
167    [Arguments]  ${pel_type}=Unrecoverable Error
168
169    # Description of argument(s):
170    # pel_type      The PEL type (e.g. Internal Failure, FRU Callout, Procedural Callout).
171
172    # Test PEL log entry example:
173    # {
174    #    "0x5000002D": {
175    #            "SRC": "BD8D1002",
176    #            "Message": "An application had an internal failure",
177    #            "PLID": "0x5000002D",
178    #            "CreatorID": "BMC",
179    #            "Subsystem": "BMC Firmware",
180    #            "Commit Time": "02/25/2020  04:47:09",
181    #            "Sev": "Unrecoverable Error",
182    #            "CompID": "0x1000"
183    #    }
184    # }
185
186    Run Keyword If  '${pel_type}' == 'Internal Failure'
187    ...   BMC Execute Command  ${CMD_INTERNAL_FAILURE}
188    ...  ELSE IF  '${pel_type}' == 'FRU Callout'
189    ...   BMC Execute Command  ${CMD_FRU_CALLOUT}
190    ...  ELSE IF  '${pel_type}' == 'Procedure And Symbolic FRU Callout'
191    ...   BMC Execute Command  ${CMD_PROCEDURAL_SYMBOLIC_FRU_CALLOUT}
192    ...  ELSE IF  '${pel_type}' == 'Unrecoverable Error'
193    ...   BMC Execute Command  ${CMD_UNRECOVERABLE_ERROR}
194
195
196Create Test Error Log
197    [Documentation]  Generate test error log.
198    # Test error log entry example:
199    # "/xyz/openbmc_project/logging/entry/1":  {
200    #     "AdditionalData": [
201    #         "STRING=FOO"
202    #     ],
203    #     "Id": 1,
204    #     "Message": "example.xyz.openbmc_project.Example.Elog.AutoTestSimple",
205    #     "Severity": "xyz.openbmc_project.Logging.Entry.Level.Error",
206    #     "Timestamp": 1487743963328,
207    #     "Associations": []
208    # }
209    BMC Execute Command  /tmp/tarball/bin/logging-test -c AutoTestSimple
210
211Count Error Entries
212    [Documentation]  Count Error entries.
213    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}
214    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
215    ...  msg=Failed to get error logs.
216    ${count}=  Get Length  ${resp.json()["data"]}
217    [Return]  ${count}
218
219Verify Test Error Log
220    [Documentation]  Verify test error log entries.
221    ${elog_entry}=  Get URL List  ${BMC_LOGGING_ENTRY}
222    ${entry_id}=  Read Attribute  ${elog_entry[0]}  Message
223    Should Be Equal  ${entry_id}
224    ...  example.xyz.openbmc_project.Example.Elog.AutoTestSimple
225    ...  msg=Error log not from AutoTestSimple.
226    ${entry_id}=  Read Attribute  ${elog_entry[0]}  Severity
227    Should Be Equal  ${entry_id}
228    ...  xyz.openbmc_project.Logging.Entry.Level.Error
229    ...  msg=Error log severity mismatch.
230
231Delete Error Logs And Verify
232    [Documentation]  Delete all error logs and verify.
233    Delete All Error Logs
234    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
235    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
236    ...  msg=Error logs not deleted as expected.
237
238
239Install Tarball
240    [Documentation]  Install tarball on BMC.
241    Should Not Be Empty  ${DEBUG_TARBALL_PATH}
242    ...  msg=Debug tarball path value is required.
243    BMC Execute Command  rm -rf /tmp/tarball
244    Install Debug Tarball On BMC  ${DEBUG_TARBALL_PATH}
245
246
247Get Event Logs
248    [Documentation]  Get all available EventLog entries.
249
250    #{
251    #  "@odata.context": "/redfish/v1/$metadata#LogEntryCollection.LogEntryCollection",
252    #  "@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/Entries",
253    #  "@odata.type": "#LogEntryCollection.LogEntryCollection",
254    #  "Description": "Collection of System Event Log Entries",
255    #  "Members": [
256    #  {
257    #    "@odata.context": "/redfish/v1/$metadata#LogEntry.LogEntry",
258    #    "@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/Entries/1",
259    #    "@odata.type": "#LogEntry.v1_4_0.LogEntry",
260    #    "Created": "2019-05-29T13:19:27+00:00",
261    #    "EntryType": "Event",
262    #    "Id": "1",
263    #    "Message": "org.open_power.Host.Error.Event",
264    #    "Name": "System DBus Event Log Entry",
265    #    "Severity": "Critical"
266    #  }
267    #  ],
268    #  "Members@odata.count": 1,
269    #  "Name": "System Event Log Entries"
270    #}
271
272    ${members}=  Redfish.Get Attribute  ${EVENT_LOG_URI}Entries  Members
273    [Return]  ${members}
274
275
276Get Redfish Event Logs
277    [Documentation]  Pack the list of all available EventLog entries in dictionary.
278    [Arguments]   ${quiet}=1  &{filter_struct_args}
279
280    # Description of argument(s):
281    # quiet                  Indicates whether this keyword should run without any output to the
282    #                        console, 0 = verbose, 1 = quiet.
283    # filter_struct_args     filter_struct args (e.g. filter_dict, regex, etc.) to be passed
284    #                        directly to the Filter Struct keyword.  See its prolog for details.
285
286    ${packed_dict}=  Create Dictionary
287    ${error_logs}=  Get Event Logs
288
289    FOR  ${idx}   IN  @{error_logs}
290       Set To Dictionary  ${packed_dict}    ${idx['@odata.id']}=${idx}
291    END
292
293    ${num_filter_struct_args}=  Get Length  ${filter_struct_args}
294    Return From Keyword If  '${num_filter_struct_args}' == '${0}'  &{packed_dict}
295    ${filtered_error_logs}=  Filter Struct  ${packed_dict}  &{filter_struct_args}
296
297    [Return]  ${filtered_error_logs}
298
299
300Get Event Logs Not Ok
301    [Documentation]  Get all event logs where the 'Severity' is not 'OK'.
302
303    ${members}=  Get Event Logs
304    ${severe_logs}=  Evaluate  [elog for elog in $members if elog['Severity'] != 'OK']
305    [Return]  ${severe_logs}
306
307
308Get Number Of Event Logs
309    [Documentation]  Return the number of EventLog members.
310
311    ${members}=  Get Event Logs
312    ${num_members}=  Get Length  ${members}
313    [Return]  ${num_members}
314
315
316Redfish Purge Event Log
317    [Documentation]  Do Redfish EventLog purge.
318
319    ${target_action}=  redfish_utils.Get Target Actions
320    ...  /redfish/v1/Systems/system/LogServices/EventLog/  LogService.ClearLog
321    Redfish.Post  ${target_action}  body={'target': '${target_action}'}
322    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
323
324
325Event Log Should Not Exist
326    [Documentation]  Event log entries should not exist.
327
328    ${elogs}=  Get Event Logs
329    Should Be Empty  ${elogs}  msg=System event log entry is not empty.
330
331
332Redfish Clear PostCodes
333    [Documentation]  Do Redfish PostCodes purge from system.
334
335    ${target_action}=  redfish_utils.Get Target Actions
336    ...  /redfish/v1/Systems/system/LogServices/PostCodes/  LogService.ClearLog
337    Redfish.Post  ${target_action}  body={'target': '${target_action}'}
338    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
339
340
341Redfish Get PostCodes
342    [Documentation]  Perform Redfish GET request and return the PostCodes entries as a list of dictionaries.
343
344    # Formatted example output from Rprint vars  members
345    # members:
346    #  [0]:
347    #    [@odata.id]:               /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-1
348    #    [@odata.type]:             #LogEntry.v1_8_0.LogEntry
349    #    [AdditionalDataURI]:       /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-1/attachment
350    #    [Created]:                 2022-08-06T04:38:10+00:00
351    #    [EntryType]:               Event
352    #    [Id]:                      B1-1
353    #    [Message]:                 Message": "Boot Count: 4: TS Offset: 0.0033; POST Code: 0x43
354    #    [MessageArgs]:
355    #      [0]:                    4
356    #      [1]:                    0.0033
357    #      [2]:                    0x43
358    #    [MessageId]:              OpenBMC.0.2.BIOSPOSTCodeASCII
359    #    [Name]:                   POST Code Log Entry
360    #    [Severity]:               OK
361
362    ${members}=  Redfish.Get Attribute  /redfish/v1/Systems/system/LogServices/PostCodes/Entries  Members
363    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
364
365    [Return]  ${members}
366