blob: b39aa3f72bc95c10df899a1a0087731258108e37 [file] [log] [blame]
Michael Walsh90e14e02018-03-22 16:38:04 -05001#!/usr/bin/env python
2
3r"""
4Provide useful error log utility keywords.
5"""
6
7import gen_print as gp
8import sys
9import os
10import imp
11base_path = os.path.dirname(os.path.dirname(
12 imp.find_module("gen_robot_print")[1])) + os.sep
13sys.path.append(base_path + "data/")
14import variables as var
15
16
17def print_error_logs(error_logs, key_list=None):
Michael Walsh90e14e02018-03-22 16:38:04 -050018 r"""
19 Print the error logs to the console screen.
20
21 This function provides the following benefits:
22 - It will specify print_var parms for the caller (e.g. hex=1).
23 - It is much easier to call this function than to generate the desired code
24 directly from a robot script.
25
26 Description of argument(s):
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050027 error_logs An error log dictionary such as the one
28 returned by the 'Get Error Logs' keyword.
29 key_list The list of keys to be printed. This may
30 be specified as either a python list
31 or a space-delimited string. In the
32 latter case, this function will convert
33 it to a python list. See the sprint_varx
34 function prolog for additionatl details.
Michael Walsh90e14e02018-03-22 16:38:04 -050035
36 Example use from a python script:
37
38 ${error_logs}= Get Error Logs
39 Print Error Logs ${error_logs} Message Timestamp
40
41 Sample output:
42
43 error_logs:
44 [/xyz/openbmc_project/logging/entry/3]:
45 [Timestamp]: 1521738335735
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050046 [Message]:
47 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050048 [/xyz/openbmc_project/logging/entry/2]:
49 [Timestamp]: 1521738334637
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050050 [Message]:
51 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050052 [/xyz/openbmc_project/logging/entry/1]:
53 [Timestamp]: 1521738300696
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050054 [Message]:
55 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050056 [/xyz/openbmc_project/logging/entry/4]:
57 [Timestamp]: 1521738337915
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050058 [Message]:
59 xyz.openbmc_project.Inventory.Error.Nonfunctional
Michael Walsh90e14e02018-03-22 16:38:04 -050060
61 Another example call using a robot list:
62 ${error_logs}= Get Error Logs
63 ${key_list}= Create List Message Timestamp Severity
64 Print Error Logs ${error_logs} ${key_list}
65 """
66
67 if key_list is not None:
68 if type(key_list) in (str, unicode):
69 key_list = key_list.split(" ")
70 key_list.insert(0, var.BMC_LOGGING_ENTRY + ".*")
71
72 gp.print_var(error_logs, hex=1, key_list=key_list)