blob: 0cdbea997ef3a345b00f5ea0adf2cf3699ebf987 [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
Patrick Williams57318182022-12-08 06:18:26 -06007import gen_print as gp
Patrick Williams57318182022-12-08 06:18:26 -06008import variables as var
George Keishinge635ddc2022-12-08 07:38:02 -06009import gen_robot_utils as gru
10import sys
11import os
12import imp
13
Sridevi Ramesh47375aa2022-12-08 05:05:31 -060014from robot.libraries.BuiltIn import BuiltIn
15
George Keishinge635ddc2022-12-08 07:38:02 -060016base_path = os.path.dirname(os.path.dirname(
17 imp.find_module("gen_robot_print")[1])) + os.sep
Michael Walsh90e14e02018-03-22 16:38:04 -050018sys.path.append(base_path + "data/")
Michael Walsh193f33a2018-10-04 15:15:09 -050019gru.my_import_resource("logging_utils.robot")
Michael Walsh90e14e02018-03-22 16:38:04 -050020
21
George Keishinge635ddc2022-12-08 07:38:02 -060022redfish_support_trans_state = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \
23 int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0))
George Keishing438fd3b2021-10-08 02:15:18 -050024
25
Michael Walsh90e14e02018-03-22 16:38:04 -050026def print_error_logs(error_logs, key_list=None):
Michael Walsh90e14e02018-03-22 16:38:04 -050027 r"""
28 Print the error logs to the console screen.
29
30 This function provides the following benefits:
31 - It will specify print_var parms for the caller (e.g. hex=1).
32 - It is much easier to call this function than to generate the desired code
33 directly from a robot script.
34
35 Description of argument(s):
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050036 error_logs An error log dictionary such as the one
37 returned by the 'Get Error Logs' keyword.
38 key_list The list of keys to be printed. This may
39 be specified as either a python list
40 or a space-delimited string. In the
41 latter case, this function will convert
42 it to a python list. See the sprint_varx
43 function prolog for additionatl details.
Michael Walsh90e14e02018-03-22 16:38:04 -050044
45 Example use from a python script:
46
47 ${error_logs}= Get Error Logs
48 Print Error Logs ${error_logs} Message Timestamp
49
50 Sample output:
51
52 error_logs:
53 [/xyz/openbmc_project/logging/entry/3]:
54 [Timestamp]: 1521738335735
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050055 [Message]:
56 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050057 [/xyz/openbmc_project/logging/entry/2]:
58 [Timestamp]: 1521738334637
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050059 [Message]:
60 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050061 [/xyz/openbmc_project/logging/entry/1]:
62 [Timestamp]: 1521738300696
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/4]:
66 [Timestamp]: 1521738337915
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050067 [Message]:
68 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050069
70 Another example call using a robot list:
71 ${error_logs}= Get Error Logs
72 ${key_list}= Create List Message Timestamp Severity
73 Print Error Logs ${error_logs} ${key_list}
74 """
75
76 if key_list is not None:
George Keishing36efbc02018-12-12 10:18:23 -060077 try:
Michael Walsh90e14e02018-03-22 16:38:04 -050078 key_list = key_list.split(" ")
George Keishing36efbc02018-12-12 10:18:23 -060079 except AttributeError:
80 pass
George Keishing438fd3b2021-10-08 02:15:18 -050081 if redfish_support_trans_state:
82 key_list.insert(0, var.REDFISH_BMC_LOGGING_ENTRY + ".*")
83 else:
84 key_list.insert(0, var.BMC_LOGGING_ENTRY + ".*")
Michael Walsh90e14e02018-03-22 16:38:04 -050085
Michael Walsh39c00512019-07-17 10:54:06 -050086 gp.print_var(error_logs, key_list=key_list)
Michael Walsh193f33a2018-10-04 15:15:09 -050087
88
89def get_esels(error_logs=None):
90 r"""
91 Get all available extended Service Event Logs (eSELs) and return as a list.
92
93 Example robot code:
94 ${esels}= Get Esels
95 Rprint Vars esels
96
97 Example output (excerpt):
98 esels:
99 esels[0]: ESEL=00 00 df 00 00...
100 esels[1]: ESEL=00 00 df 00 00...
101
102 Description of argument(s):
103 error_logs The error_log data, which can be obtained
104 from 'Get Error Logs'. If this value is
105 None, then this function will call 'Get
106 Error Logs' on the caller's behalf.
107 """
108
109 if error_logs is None:
George Keishinge635ddc2022-12-08 07:38:02 -0600110 error_logs = BuiltIn().run_keyword('Get Error Logs')
Michael Walsh193f33a2018-10-04 15:15:09 -0500111
112 # Look for any error log entries containing the 'AdditionalData' field
113 # which in turn has an entry starting with "ESEL=". Here is an excerpt of
114 # the error_logs that contains such an entry.
115 # error_logs:
116 # [/xyz/openbmc_project/logging/entry/1]:
117 # [AdditionalData]:
118 # [AdditionalData][0]: CALLOUT_INVENTORY_PATH=/xyz/openbmc_project/inventory/system/chassis/mot...
119 # [AdditionalData][1]: ESEL=00 00 df 00 00 00 00 20 00 04...
120 esels = []
121 for error_log in error_logs.values():
George Keishinge635ddc2022-12-08 07:38:02 -0600122 if 'AdditionalData' in error_log:
123 for additional_data in error_log['AdditionalData']:
124 if additional_data.startswith('ESEL='):
Michael Walsh193f33a2018-10-04 15:15:09 -0500125 esels.append(additional_data)
126
127 return esels