xref: /openbmc/openbmc-test-automation/lib/pel_utils.py (revision 48ffa2c223d581075886b1411e6cbd56fd94ece5)
1e7e9171eSGeorge Keishing#!/usr/bin/env python3
2faa5d20aSRahul Maheshwari
3faa5d20aSRahul Maheshwarir"""
4faa5d20aSRahul MaheshwariPEL functions.
5faa5d20aSRahul Maheshwari"""
6faa5d20aSRahul Maheshwari
7faa5d20aSRahul Maheshwariimport func_args as fa
8faa5d20aSRahul Maheshwariimport bmc_ssh_utils as bsu
9faa5d20aSRahul Maheshwariimport json
10*48ffa2c2SGeorge Keishingimport os
11*48ffa2c2SGeorge Keishingimport sys
12*48ffa2c2SGeorge Keishingfrom robot.libraries.BuiltIn import BuiltIn
13*48ffa2c2SGeorge Keishing
14*48ffa2c2SGeorge Keishingbase_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15*48ffa2c2SGeorge Keishingsys.path.append(base_path + "/data/")
16*48ffa2c2SGeorge Keishing
17c6dd799dSSridevi Rameshimport pel_variables
18faa5d20aSRahul Maheshwari
19faa5d20aSRahul Maheshwari
206e0e0919SSridevi Rameshclass peltool_exception(Exception):
216e0e0919SSridevi Ramesh    r"""
226e0e0919SSridevi Ramesh    Base class for peltool related exceptions.
236e0e0919SSridevi Ramesh    """
24*48ffa2c2SGeorge Keishing
256e0e0919SSridevi Ramesh    def __init__(self, message):
266e0e0919SSridevi Ramesh        self.message = message
276e0e0919SSridevi Ramesh        super().__init__(self.message)
286e0e0919SSridevi Ramesh
296e0e0919SSridevi Ramesh
30a20876d3SMichael Walshdef peltool(option_string, parse_json=True, **bsu_options):
31faa5d20aSRahul Maheshwari    r"""
32faa5d20aSRahul Maheshwari    Run peltool on the BMC with the caller's option string and return the result.
33faa5d20aSRahul Maheshwari
34faa5d20aSRahul Maheshwari    Example:
35faa5d20aSRahul Maheshwari
36faa5d20aSRahul Maheshwari    ${pel_results}=  Peltool  -l
37faa5d20aSRahul Maheshwari    Rprint Vars  pel_results
38faa5d20aSRahul Maheshwari
39faa5d20aSRahul Maheshwari    pel_results:
40faa5d20aSRahul Maheshwari      [0x50000031]:
41faa5d20aSRahul Maheshwari        [CompID]:                       0x1000
42faa5d20aSRahul Maheshwari        [PLID]:                         0x50000031
43faa5d20aSRahul Maheshwari        [Subsystem]:                    BMC Firmware
44faa5d20aSRahul Maheshwari        [Message]:                      An application had an internal failure
45faa5d20aSRahul Maheshwari        [SRC]:                          BD8D1002
46faa5d20aSRahul Maheshwari        [Commit Time]:                  02/25/2020  04:51:31
47faa5d20aSRahul Maheshwari        [Sev]:                          Unrecoverable Error
48faa5d20aSRahul Maheshwari        [CreatorID]:                    BMC
49faa5d20aSRahul Maheshwari
50faa5d20aSRahul Maheshwari    Description of argument(s):
51faa5d20aSRahul Maheshwari    option_string                   A string of options which are to be processed by the peltool command.
52a20876d3SMichael Walsh    parse_json                      Indicates that the raw JSON data should parsed into a list of
53a20876d3SMichael Walsh                                    dictionaries.
54faa5d20aSRahul Maheshwari    bsu_options                     Options to be passed directly to bmc_execute_command. See its prolog for
55faa5d20aSRahul Maheshwari                                    details.
56faa5d20aSRahul Maheshwari    """
57faa5d20aSRahul Maheshwari
58faa5d20aSRahul Maheshwari    bsu_options = fa.args_to_objects(bsu_options)
59faa5d20aSRahul Maheshwari    out_buf, stderr, rc = bsu.bmc_execute_command('peltool ' + option_string, **bsu_options)
60a20876d3SMichael Walsh    if parse_json:
61a20876d3SMichael Walsh        try:
62a20876d3SMichael Walsh            return json.loads(out_buf)
63c6dd799dSSridevi Ramesh        except ValueError:
64a20876d3SMichael Walsh            return {}
65faa5d20aSRahul Maheshwari    return out_buf
666e0e0919SSridevi Ramesh
676e0e0919SSridevi Ramesh
68c6dd799dSSridevi Rameshdef fetch_all_pel_ids_for_src(src_id, severity):
696e0e0919SSridevi Ramesh    r"""
70c6dd799dSSridevi Ramesh    Fetch all PEL IDs for the input SRC ID based on the severity type
71c6dd799dSSridevi Ramesh    in the list format.
726e0e0919SSridevi Ramesh
736e0e0919SSridevi Ramesh    Description of arguments:
74c6dd799dSSridevi Ramesh    src_id      SRC ID (e.g. BC20E504).
75c6dd799dSSridevi Ramesh    severity    PEL severity (e.g. "Predictive Error"
76c6dd799dSSridevi Ramesh                                   "Recovered Error").
776e0e0919SSridevi Ramesh    """
786e0e0919SSridevi Ramesh
796e0e0919SSridevi Ramesh    try:
80c6dd799dSSridevi Ramesh        src_pel_ids = []
816e0e0919SSridevi Ramesh        pel_data = peltool(" -l")
826e0e0919SSridevi Ramesh        pel_id_list = pel_data.keys()
83c6dd799dSSridevi Ramesh        for pel_id in pel_id_list:
84c6dd799dSSridevi Ramesh            # Check if required SRC ID with severity is present
85c6dd799dSSridevi Ramesh            if ((pel_data[pel_id]["SRC"] == src_id) and (pel_data[pel_id]["Sev"] == severity)):
86c6dd799dSSridevi Ramesh                src_pel_ids.append(pel_id)
87c6dd799dSSridevi Ramesh
88c6dd799dSSridevi Ramesh        if not src_pel_ids:
89c6dd799dSSridevi Ramesh            raise peltool_exception(src_id + " with severity " + severity + " not present")
906e0e0919SSridevi Ramesh    except Exception as e:
916e0e0919SSridevi Ramesh        raise peltool_exception("Failed to fetch PEL ID for required SRC : " + str(e))
92c6dd799dSSridevi Ramesh    return src_pel_ids
936e0e0919SSridevi Ramesh
946e0e0919SSridevi Ramesh
95c6dd799dSSridevi Rameshdef verify_src_signature_and_threshold(pel_id, attn_type, signature_desc, th_limit):
966e0e0919SSridevi Ramesh    r"""
97c6dd799dSSridevi Ramesh    Verifies SRC details for the given PEL ID based on the required
98c6dd799dSSridevi Ramesh    attention type, signature description, threshold limits.
996e0e0919SSridevi Ramesh
1006e0e0919SSridevi Ramesh    Description of arguments:
101c6dd799dSSridevi Ramesh    pel_id          PEL ID for the required SRC details to verify.
102c6dd799dSSridevi Ramesh    attn_type       Attention type (e.g. RE, CS, UNIT_CS).
103c6dd799dSSridevi Ramesh    signature_desc  Signature description of the error inject.
104c6dd799dSSridevi Ramesh    th_limit        Threshold limit (e.g. 1, 5, 32).
1056e0e0919SSridevi Ramesh    """
1066e0e0919SSridevi Ramesh
1076e0e0919SSridevi Ramesh    try:
1086e0e0919SSridevi Ramesh        pel_cmd = " -i " + pel_id
1096e0e0919SSridevi Ramesh        src_data = peltool(pel_cmd)
1106e0e0919SSridevi Ramesh        src_dict = src_data["Primary SRC"]["SRC Details"]
111c6dd799dSSridevi Ramesh        usr_data = src_data["User Data 1"]
112c6dd799dSSridevi Ramesh
113c6dd799dSSridevi Ramesh        # Example for signature in recoverable error
114c6dd799dSSridevi Ramesh        #
115c6dd799dSSridevi Ramesh        # "SRC Details": {
116c6dd799dSSridevi Ramesh        # "Attention Type": "RECOVERABLE",
117c6dd799dSSridevi Ramesh        # "Node": 0,
118c6dd799dSSridevi Ramesh        # "Target Type": "TYPE_OMIC",
119c6dd799dSSridevi Ramesh        # "Target Instance": 0,
120c6dd799dSSridevi Ramesh        # "Signature": "MC_OMI_DL_FIR[1]: OMI-DL0 UE on data flit"
121c6dd799dSSridevi Ramesh        # }
122c6dd799dSSridevi Ramesh        if (attn_type == "RE"):
123c6dd799dSSridevi Ramesh            if (src_dict["Attention Type"] != "RECOVERABLE"):
1246e0e0919SSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
125c6dd799dSSridevi Ramesh
126c6dd799dSSridevi Ramesh        # Example for signature in system checkstop error
127c6dd799dSSridevi Ramesh        #
128c6dd799dSSridevi Ramesh        # "SRC Details": {
129c6dd799dSSridevi Ramesh        # "Primary Attention": "system checkstop",
130c6dd799dSSridevi Ramesh        # "Signature Description": {
131c6dd799dSSridevi Ramesh        #    "Chip Desc": "node 0 proc 0 (P10 2.0)",
132c6dd799dSSridevi Ramesh        #    "Signature": "EQ_L2_FIR(0)[7] L2 directory read UE",
133c6dd799dSSridevi Ramesh        #    "Attn Type": "checkstop"
134c6dd799dSSridevi Ramesh        # }
135c6dd799dSSridevi Ramesh
136c6dd799dSSridevi Ramesh        elif (attn_type == "CS"):
137c6dd799dSSridevi Ramesh            if (src_dict["Primary Attention"] != "system checkstop"):
138c6dd799dSSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
139c6dd799dSSridevi Ramesh
140c6dd799dSSridevi Ramesh        elif (attn_type == "UNIT_CS"):
141c6dd799dSSridevi Ramesh            if (src_dict["Attention Type"] != "UNIT_CS"):
142c6dd799dSSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
143c6dd799dSSridevi Ramesh        else:
144c6dd799dSSridevi Ramesh            raise peltool_exception("Required Attention type " + attn_type + " not found")
145c6dd799dSSridevi Ramesh
1466e0e0919SSridevi Ramesh        if signature_desc not in src_dict["Signature"]:
1476e0e0919SSridevi Ramesh            raise peltool_exception("Required Signature " + signature_desc + " not found")
1486e0e0919SSridevi Ramesh
149c6dd799dSSridevi Ramesh        if (int(th_limit) != usr_data["Error Count"]):
150c6dd799dSSridevi Ramesh            raise peltool_exception("Required Threshold limit " + th_limit + " not found")
1516e0e0919SSridevi Ramesh
1526e0e0919SSridevi Ramesh    except Exception as e:
1536e0e0919SSridevi Ramesh        raise peltool_exception("Failed to verify SRC details : " + str(e))
1546e0e0919SSridevi Ramesh    return True
1556e0e0919SSridevi Ramesh
1566e0e0919SSridevi Ramesh
157c6dd799dSSridevi Rameshdef fetch_all_src():
1586e0e0919SSridevi Ramesh    r"""
159c6dd799dSSridevi Ramesh    Fetch all SRC IDs from peltool in the list format.
1606e0e0919SSridevi Ramesh    """
1616e0e0919SSridevi Ramesh    try:
162c6dd799dSSridevi Ramesh        src_id = []
1636e0e0919SSridevi Ramesh        pel_data = peltool(" -l")
164c6dd799dSSridevi Ramesh        if pel_data:
1656e0e0919SSridevi Ramesh            pel_id_list = pel_data.keys()
166c6dd799dSSridevi Ramesh            for pel_id in pel_id_list:
167c6dd799dSSridevi Ramesh                src_id.append(pel_data[pel_id]["SRC"])
168c6dd799dSSridevi Ramesh        else:
169c6dd799dSSridevi Ramesh            raise peltool_exception("No PEL entry found ..")
1706e0e0919SSridevi Ramesh    except Exception as e:
1716e0e0919SSridevi Ramesh        raise peltool_exception("Failed to fetch all SRCs : " + str(e))
1726e0e0919SSridevi Ramesh    return src_id
173