xref: /openbmc/openbmc-test-automation/lib/logging_utils.py (revision e17cf5fd0e4bff1169dab667fe0ce361ca76d857)
1#!/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):
18
19    r"""
20    Print the error logs to the console screen.
21
22    This function provides the following benefits:
23    - It will specify print_var parms for the caller (e.g. hex=1).
24    - It is much easier to call this function than to generate the desired code
25      directly from a robot script.
26
27    Description of argument(s):
28    error_logs  An error log dictionary such as the one returned by the
29                'Get Error Logs' keyword.
30    key_list    The list of keys to be printed.  This may be specified as
31                either a python list or a space-delimited string.  In the
32                latter case, this function will convert it to a python list.
33                See the sprint_varx function prolog for additionatl details.
34
35    Example use from a python script:
36
37    ${error_logs}=  Get Error Logs
38    Print Error Logs  ${error_logs}  Message Timestamp
39
40    Sample output:
41
42    error_logs:
43      [/xyz/openbmc_project/logging/entry/3]:
44        [Timestamp]:                                  1521738335735
45        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
46      [/xyz/openbmc_project/logging/entry/2]:
47        [Timestamp]:                                  1521738334637
48        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
49      [/xyz/openbmc_project/logging/entry/1]:
50        [Timestamp]:                                  1521738300696
51        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
52      [/xyz/openbmc_project/logging/entry/4]:
53        [Timestamp]:                                  1521738337915
54        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
55
56    Another example call using a robot list:
57    ${error_logs}=  Get Error Logs
58    ${key_list}=  Create List  Message  Timestamp  Severity
59    Print Error Logs  ${error_logs}  ${key_list}
60    """
61
62    if key_list is not None:
63        if type(key_list) in (str, unicode):
64            key_list = key_list.split(" ")
65        key_list.insert(0, var.BMC_LOGGING_ENTRY + ".*")
66
67    gp.print_var(error_logs, hex=1, key_list=key_list)
68