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