George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
| 4 | Provide useful error log utility keywords. |
| 5 | """ |
| 6 | |
George Keishing | 0967989 | 2022-12-08 08:21:52 -0600 | [diff] [blame] | 7 | from robot.libraries.BuiltIn import BuiltIn |
| 8 | |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 9 | import gen_print as gp |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 10 | import sys |
| 11 | import os |
| 12 | import imp |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 13 | base_path = os.path.dirname(os.path.dirname( |
| 14 | imp.find_module("gen_robot_print")[1])) + os.sep |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 15 | sys.path.append(base_path + "data/") |
George Keishing | 0967989 | 2022-12-08 08:21:52 -0600 | [diff] [blame] | 16 | import variables as var # NOQA |
| 17 | import gen_robot_utils as gru # NOQA |
Michael Walsh | 193f33a | 2018-10-04 15:15:09 -0500 | [diff] [blame] | 18 | gru.my_import_resource("logging_utils.robot") |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 19 | |
| 20 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 21 | redfish_support_trans_state = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \ |
| 22 | int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0)) |
George Keishing | 438fd3b | 2021-10-08 02:15:18 -0500 | [diff] [blame] | 23 | |
| 24 | |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 25 | def print_error_logs(error_logs, key_list=None): |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 26 | r""" |
| 27 | Print the error logs to the console screen. |
| 28 | |
| 29 | This function provides the following benefits: |
| 30 | - It will specify print_var parms for the caller (e.g. hex=1). |
| 31 | - It is much easier to call this function than to generate the desired code |
| 32 | directly from a robot script. |
| 33 | |
| 34 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 35 | error_logs An error log dictionary such as the one |
| 36 | returned by the 'Get Error Logs' keyword. |
| 37 | key_list The list of keys to be printed. This may |
| 38 | be specified as either a python list |
| 39 | or a space-delimited string. In the |
| 40 | latter case, this function will convert |
| 41 | it to a python list. See the sprint_varx |
| 42 | function prolog for additionatl details. |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 43 | |
| 44 | Example use from a python script: |
| 45 | |
| 46 | ${error_logs}= Get Error Logs |
| 47 | Print Error Logs ${error_logs} Message Timestamp |
| 48 | |
| 49 | Sample output: |
| 50 | |
| 51 | error_logs: |
| 52 | [/xyz/openbmc_project/logging/entry/3]: |
| 53 | [Timestamp]: 1521738335735 |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 54 | [Message]: |
| 55 | xyz.openbmc_project.Inventory.Error.Nonfunctional |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 56 | [/xyz/openbmc_project/logging/entry/2]: |
| 57 | [Timestamp]: 1521738334637 |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 58 | [Message]: |
| 59 | xyz.openbmc_project.Inventory.Error.Nonfunctional |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 60 | [/xyz/openbmc_project/logging/entry/1]: |
| 61 | [Timestamp]: 1521738300696 |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 62 | [Message]: |
| 63 | xyz.openbmc_project.Inventory.Error.Nonfunctional |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 64 | [/xyz/openbmc_project/logging/entry/4]: |
| 65 | [Timestamp]: 1521738337915 |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 66 | [Message]: |
| 67 | xyz.openbmc_project.Inventory.Error.Nonfunctional |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 68 | |
| 69 | Another example call using a robot list: |
| 70 | ${error_logs}= Get Error Logs |
| 71 | ${key_list}= Create List Message Timestamp Severity |
| 72 | Print Error Logs ${error_logs} ${key_list} |
| 73 | """ |
| 74 | |
| 75 | if key_list is not None: |
George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 76 | try: |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 77 | key_list = key_list.split(" ") |
George Keishing | 36efbc0 | 2018-12-12 10:18:23 -0600 | [diff] [blame] | 78 | except AttributeError: |
| 79 | pass |
George Keishing | 438fd3b | 2021-10-08 02:15:18 -0500 | [diff] [blame] | 80 | if redfish_support_trans_state: |
| 81 | key_list.insert(0, var.REDFISH_BMC_LOGGING_ENTRY + ".*") |
| 82 | else: |
| 83 | key_list.insert(0, var.BMC_LOGGING_ENTRY + ".*") |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 84 | |
Michael Walsh | 39c0051 | 2019-07-17 10:54:06 -0500 | [diff] [blame] | 85 | gp.print_var(error_logs, key_list=key_list) |
Michael Walsh | 193f33a | 2018-10-04 15:15:09 -0500 | [diff] [blame] | 86 | |
| 87 | |
| 88 | def get_esels(error_logs=None): |
| 89 | r""" |
| 90 | Get all available extended Service Event Logs (eSELs) and return as a list. |
| 91 | |
| 92 | Example robot code: |
| 93 | ${esels}= Get Esels |
| 94 | Rprint Vars esels |
| 95 | |
| 96 | Example output (excerpt): |
| 97 | esels: |
| 98 | esels[0]: ESEL=00 00 df 00 00... |
| 99 | esels[1]: ESEL=00 00 df 00 00... |
| 100 | |
| 101 | Description of argument(s): |
| 102 | error_logs The error_log data, which can be obtained |
| 103 | from 'Get Error Logs'. If this value is |
| 104 | None, then this function will call 'Get |
| 105 | Error Logs' on the caller's behalf. |
| 106 | """ |
| 107 | |
| 108 | if error_logs is None: |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 109 | error_logs = BuiltIn().run_keyword('Get Error Logs') |
Michael Walsh | 193f33a | 2018-10-04 15:15:09 -0500 | [diff] [blame] | 110 | |
| 111 | # Look for any error log entries containing the 'AdditionalData' field |
| 112 | # which in turn has an entry starting with "ESEL=". Here is an excerpt of |
| 113 | # the error_logs that contains such an entry. |
| 114 | # error_logs: |
| 115 | # [/xyz/openbmc_project/logging/entry/1]: |
| 116 | # [AdditionalData]: |
| 117 | # [AdditionalData][0]: CALLOUT_INVENTORY_PATH=/xyz/openbmc_project/inventory/system/chassis/mot... |
| 118 | # [AdditionalData][1]: ESEL=00 00 df 00 00 00 00 20 00 04... |
| 119 | esels = [] |
| 120 | for error_log in error_logs.values(): |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 121 | if 'AdditionalData' in error_log: |
| 122 | for additional_data in error_log['AdditionalData']: |
| 123 | if additional_data.startswith('ESEL='): |
Michael Walsh | 193f33a | 2018-10-04 15:15:09 -0500 | [diff] [blame] | 124 | esels.append(additional_data) |
| 125 | |
| 126 | return esels |