Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | Provide useful error log utility keywords. |
| 5 | """ |
| 6 | |
| 7 | import gen_print as gp |
| 8 | import sys |
| 9 | import os |
| 10 | import imp |
| 11 | base_path = os.path.dirname(os.path.dirname( |
| 12 | imp.find_module("gen_robot_print")[1])) + os.sep |
| 13 | sys.path.append(base_path + "data/") |
| 14 | import variables as var |
| 15 | |
| 16 | |
| 17 | def print_error_logs(error_logs, key_list=None): |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 18 | 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 Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 27 | 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 Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 35 | |
| 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 Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 46 | [Message]: |
| 47 | xyz.openbmc_project.Inventory.Error.Nonfunctional |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 48 | [/xyz/openbmc_project/logging/entry/2]: |
| 49 | [Timestamp]: 1521738334637 |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 50 | [Message]: |
| 51 | xyz.openbmc_project.Inventory.Error.Nonfunctional |
Michael Walsh | 90e14e0 | 2018-03-22 16:38:04 -0500 | [diff] [blame] | 52 | [/xyz/openbmc_project/logging/entry/1]: |
| 53 | [Timestamp]: 1521738300696 |
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/4]: |
| 57 | [Timestamp]: 1521738337915 |
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 | |
| 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) |