blob: 92160cd6f6bb124a5a7b2318adc2a2274b857d39 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh90e14e02018-03-22 16:38:04 -05002
3r"""
4Provide useful error log utility keywords.
5"""
6
Brian Ma139f1da2024-10-18 13:34:14 +08007import importlib.util
Patrick Williams20f38712022-12-08 06:18:26 -06008import os
9import sys
George Keishing09679892022-12-08 08:21:52 -060010
Patrick Williams57318182022-12-08 06:18:26 -060011import gen_print as gp
Patrick Williams20f38712022-12-08 06:18:26 -060012from robot.libraries.BuiltIn import BuiltIn
13
14base_path = (
Brian Ma139f1da2024-10-18 13:34:14 +080015 os.path.dirname(
16 os.path.dirname(importlib.util.find_spec("gen_robot_print").origin)
17 )
Patrick Williams20f38712022-12-08 06:18:26 -060018 + os.sep
19)
Michael Walsh90e14e02018-03-22 16:38:04 -050020sys.path.append(base_path + "data/")
Patrick Williams20f38712022-12-08 06:18:26 -060021import gen_robot_utils as gru # NOQA
22import variables as var # NOQA
23
Michael Walsh193f33a2018-10-04 15:15:09 -050024gru.my_import_resource("logging_utils.robot")
Michael Walsh90e14e02018-03-22 16:38:04 -050025
26
Patrick Williams20f38712022-12-08 06:18:26 -060027redfish_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 Keishing438fd3b2021-10-08 02:15:18 -050032
33
Michael Walsh90e14e02018-03-22 16:38:04 -050034def print_error_logs(error_logs, key_list=None):
Michael Walsh90e14e02018-03-22 16:38:04 -050035 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 Onyerikwu004ad3c2018-06-11 16:29:56 -050044 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 Walsh90e14e02018-03-22 16:38:04 -050052
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 Onyerikwu004ad3c2018-06-11 16:29:56 -050063 [Message]:
64 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050065 [/xyz/openbmc_project/logging/entry/2]:
66 [Timestamp]: 1521738334637
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050067 [Message]:
68 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050069 [/xyz/openbmc_project/logging/entry/1]:
70 [Timestamp]: 1521738300696
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050071 [Message]:
72 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050073 [/xyz/openbmc_project/logging/entry/4]:
74 [Timestamp]: 1521738337915
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050075 [Message]:
76 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050077
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 Keishing36efbc02018-12-12 10:18:23 -060085 try:
Michael Walsh90e14e02018-03-22 16:38:04 -050086 key_list = key_list.split(" ")
George Keishing36efbc02018-12-12 10:18:23 -060087 except AttributeError:
88 pass
George Keishing438fd3b2021-10-08 02:15:18 -050089 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 Walsh90e14e02018-03-22 16:38:04 -050093
Michael Walsh39c00512019-07-17 10:54:06 -050094 gp.print_var(error_logs, key_list=key_list)
Michael Walsh193f33a2018-10-04 15:15:09 -050095
96
97def 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 Williams20f38712022-12-08 06:18:26 -0600118 error_logs = BuiltIn().run_keyword("Get Error Logs")
Michael Walsh193f33a2018-10-04 15:15:09 -0500119
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 Williams20f38712022-12-08 06:18:26 -0600130 if "AdditionalData" in error_log:
131 for additional_data in error_log["AdditionalData"]:
132 if additional_data.startswith("ESEL="):
Michael Walsh193f33a2018-10-04 15:15:09 -0500133 esels.append(additional_data)
134
135 return esels