xref: /openbmc/openbmc-test-automation/lib/pel_utils.py (revision c6dd799d6e6b3465c4f8a0699b7a3a25a354ba70)
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*c6dd799dSSridevi Rameshimport pel_variables
11faa5d20aSRahul Maheshwari
12faa5d20aSRahul Maheshwari
136e0e0919SSridevi Rameshclass peltool_exception(Exception):
146e0e0919SSridevi Ramesh    r"""
156e0e0919SSridevi Ramesh    Base class for peltool related exceptions.
166e0e0919SSridevi Ramesh    """
176e0e0919SSridevi Ramesh    def __init__(self, message):
186e0e0919SSridevi Ramesh        self.message = message
196e0e0919SSridevi Ramesh        super().__init__(self.message)
206e0e0919SSridevi Ramesh
216e0e0919SSridevi Ramesh
22a20876d3SMichael Walshdef peltool(option_string, parse_json=True, **bsu_options):
23faa5d20aSRahul Maheshwari    r"""
24faa5d20aSRahul Maheshwari    Run peltool on the BMC with the caller's option string and return the result.
25faa5d20aSRahul Maheshwari
26faa5d20aSRahul Maheshwari    Example:
27faa5d20aSRahul Maheshwari
28faa5d20aSRahul Maheshwari    ${pel_results}=  Peltool  -l
29faa5d20aSRahul Maheshwari    Rprint Vars  pel_results
30faa5d20aSRahul Maheshwari
31faa5d20aSRahul Maheshwari    pel_results:
32faa5d20aSRahul Maheshwari      [0x50000031]:
33faa5d20aSRahul Maheshwari        [CompID]:                       0x1000
34faa5d20aSRahul Maheshwari        [PLID]:                         0x50000031
35faa5d20aSRahul Maheshwari        [Subsystem]:                    BMC Firmware
36faa5d20aSRahul Maheshwari        [Message]:                      An application had an internal failure
37faa5d20aSRahul Maheshwari        [SRC]:                          BD8D1002
38faa5d20aSRahul Maheshwari        [Commit Time]:                  02/25/2020  04:51:31
39faa5d20aSRahul Maheshwari        [Sev]:                          Unrecoverable Error
40faa5d20aSRahul Maheshwari        [CreatorID]:                    BMC
41faa5d20aSRahul Maheshwari
42faa5d20aSRahul Maheshwari    Description of argument(s):
43faa5d20aSRahul Maheshwari    option_string                   A string of options which are to be processed by the peltool command.
44a20876d3SMichael Walsh    parse_json                      Indicates that the raw JSON data should parsed into a list of
45a20876d3SMichael Walsh                                    dictionaries.
46faa5d20aSRahul Maheshwari    bsu_options                     Options to be passed directly to bmc_execute_command. See its prolog for
47faa5d20aSRahul Maheshwari                                    details.
48faa5d20aSRahul Maheshwari    """
49faa5d20aSRahul Maheshwari
50faa5d20aSRahul Maheshwari    bsu_options = fa.args_to_objects(bsu_options)
51faa5d20aSRahul Maheshwari    out_buf, stderr, rc = bsu.bmc_execute_command('peltool ' + option_string, **bsu_options)
52a20876d3SMichael Walsh    if parse_json:
53a20876d3SMichael Walsh        try:
54a20876d3SMichael Walsh            return json.loads(out_buf)
55*c6dd799dSSridevi Ramesh        except ValueError:
56a20876d3SMichael Walsh            return {}
57faa5d20aSRahul Maheshwari    return out_buf
586e0e0919SSridevi Ramesh
596e0e0919SSridevi Ramesh
60*c6dd799dSSridevi Rameshdef fetch_all_pel_ids_for_src(src_id, severity):
616e0e0919SSridevi Ramesh    r"""
62*c6dd799dSSridevi Ramesh    Fetch all PEL IDs for the input SRC ID based on the severity type
63*c6dd799dSSridevi Ramesh    in the list format.
646e0e0919SSridevi Ramesh
656e0e0919SSridevi Ramesh    Description of arguments:
66*c6dd799dSSridevi Ramesh    src_id      SRC ID (e.g. BC20E504).
67*c6dd799dSSridevi Ramesh    severity    PEL severity (e.g. "Predictive Error"
68*c6dd799dSSridevi Ramesh                                   "Recovered Error").
696e0e0919SSridevi Ramesh    """
706e0e0919SSridevi Ramesh
716e0e0919SSridevi Ramesh    try:
72*c6dd799dSSridevi Ramesh        src_pel_ids = []
736e0e0919SSridevi Ramesh        pel_data = peltool(" -l")
746e0e0919SSridevi Ramesh        pel_id_list = pel_data.keys()
75*c6dd799dSSridevi Ramesh        for pel_id in pel_id_list:
76*c6dd799dSSridevi Ramesh            # Check if required SRC ID with severity is present
77*c6dd799dSSridevi Ramesh            if ((pel_data[pel_id]["SRC"] == src_id) and (pel_data[pel_id]["Sev"] == severity)):
78*c6dd799dSSridevi Ramesh                src_pel_ids.append(pel_id)
79*c6dd799dSSridevi Ramesh
80*c6dd799dSSridevi Ramesh        if not src_pel_ids:
81*c6dd799dSSridevi Ramesh            raise peltool_exception(src_id + " with severity " + severity + " not present")
826e0e0919SSridevi Ramesh    except Exception as e:
836e0e0919SSridevi Ramesh        raise peltool_exception("Failed to fetch PEL ID for required SRC : " + str(e))
84*c6dd799dSSridevi Ramesh    return src_pel_ids
856e0e0919SSridevi Ramesh
866e0e0919SSridevi Ramesh
87*c6dd799dSSridevi Rameshdef verify_src_signature_and_threshold(pel_id, attn_type, signature_desc, th_limit):
886e0e0919SSridevi Ramesh    r"""
89*c6dd799dSSridevi Ramesh    Verifies SRC details for the given PEL ID based on the required
90*c6dd799dSSridevi Ramesh    attention type, signature description, threshold limits.
916e0e0919SSridevi Ramesh
926e0e0919SSridevi Ramesh    Description of arguments:
93*c6dd799dSSridevi Ramesh    pel_id          PEL ID for the required SRC details to verify.
94*c6dd799dSSridevi Ramesh    attn_type       Attention type (e.g. RE, CS, UNIT_CS).
95*c6dd799dSSridevi Ramesh    signature_desc  Signature description of the error inject.
96*c6dd799dSSridevi Ramesh    th_limit        Threshold limit (e.g. 1, 5, 32).
976e0e0919SSridevi Ramesh    """
986e0e0919SSridevi Ramesh
996e0e0919SSridevi Ramesh    try:
1006e0e0919SSridevi Ramesh        pel_cmd = " -i " + pel_id
1016e0e0919SSridevi Ramesh        src_data = peltool(pel_cmd)
1026e0e0919SSridevi Ramesh        src_dict = src_data["Primary SRC"]["SRC Details"]
103*c6dd799dSSridevi Ramesh        usr_data = src_data["User Data 1"]
104*c6dd799dSSridevi Ramesh
105*c6dd799dSSridevi Ramesh        # Example for signature in recoverable error
106*c6dd799dSSridevi Ramesh        #
107*c6dd799dSSridevi Ramesh        # "SRC Details": {
108*c6dd799dSSridevi Ramesh        # "Attention Type": "RECOVERABLE",
109*c6dd799dSSridevi Ramesh        # "Node": 0,
110*c6dd799dSSridevi Ramesh        # "Target Type": "TYPE_OMIC",
111*c6dd799dSSridevi Ramesh        # "Target Instance": 0,
112*c6dd799dSSridevi Ramesh        # "Signature": "MC_OMI_DL_FIR[1]: OMI-DL0 UE on data flit"
113*c6dd799dSSridevi Ramesh        # }
114*c6dd799dSSridevi Ramesh        if (attn_type == "RE"):
115*c6dd799dSSridevi Ramesh            if (src_dict["Attention Type"] != "RECOVERABLE"):
1166e0e0919SSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
117*c6dd799dSSridevi Ramesh
118*c6dd799dSSridevi Ramesh        # Example for signature in system checkstop error
119*c6dd799dSSridevi Ramesh        #
120*c6dd799dSSridevi Ramesh        # "SRC Details": {
121*c6dd799dSSridevi Ramesh        # "Primary Attention": "system checkstop",
122*c6dd799dSSridevi Ramesh        # "Signature Description": {
123*c6dd799dSSridevi Ramesh        #    "Chip Desc": "node 0 proc 0 (P10 2.0)",
124*c6dd799dSSridevi Ramesh        #    "Signature": "EQ_L2_FIR(0)[7] L2 directory read UE",
125*c6dd799dSSridevi Ramesh        #    "Attn Type": "checkstop"
126*c6dd799dSSridevi Ramesh        # }
127*c6dd799dSSridevi Ramesh
128*c6dd799dSSridevi Ramesh        elif (attn_type == "CS"):
129*c6dd799dSSridevi Ramesh            if (src_dict["Primary Attention"] != "system checkstop"):
130*c6dd799dSSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
131*c6dd799dSSridevi Ramesh
132*c6dd799dSSridevi Ramesh        elif (attn_type == "UNIT_CS"):
133*c6dd799dSSridevi Ramesh            if (src_dict["Attention Type"] != "UNIT_CS"):
134*c6dd799dSSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
135*c6dd799dSSridevi Ramesh        else:
136*c6dd799dSSridevi Ramesh            raise peltool_exception("Required Attention type " + attn_type + " not found")
137*c6dd799dSSridevi Ramesh
1386e0e0919SSridevi Ramesh        if signature_desc not in src_dict["Signature"]:
1396e0e0919SSridevi Ramesh            raise peltool_exception("Required Signature " + signature_desc + " not found")
1406e0e0919SSridevi Ramesh
141*c6dd799dSSridevi Ramesh        if (int(th_limit) != usr_data["Error Count"]):
142*c6dd799dSSridevi Ramesh            raise peltool_exception("Required Threshold limit " + th_limit + " not found")
1436e0e0919SSridevi Ramesh
1446e0e0919SSridevi Ramesh    except Exception as e:
1456e0e0919SSridevi Ramesh        raise peltool_exception("Failed to verify SRC details : " + str(e))
1466e0e0919SSridevi Ramesh    return True
1476e0e0919SSridevi Ramesh
1486e0e0919SSridevi Ramesh
149*c6dd799dSSridevi Rameshdef fetch_all_src():
1506e0e0919SSridevi Ramesh    r"""
151*c6dd799dSSridevi Ramesh    Fetch all SRC IDs from peltool in the list format.
1526e0e0919SSridevi Ramesh    """
1536e0e0919SSridevi Ramesh    try:
154*c6dd799dSSridevi Ramesh        src_id = []
1556e0e0919SSridevi Ramesh        pel_data = peltool(" -l")
156*c6dd799dSSridevi Ramesh        if pel_data:
1576e0e0919SSridevi Ramesh            pel_id_list = pel_data.keys()
158*c6dd799dSSridevi Ramesh            for pel_id in pel_id_list:
159*c6dd799dSSridevi Ramesh                src_id.append(pel_data[pel_id]["SRC"])
160*c6dd799dSSridevi Ramesh        else:
161*c6dd799dSSridevi Ramesh            raise peltool_exception("No PEL entry found ..")
1626e0e0919SSridevi Ramesh    except Exception as e:
1636e0e0919SSridevi Ramesh        raise peltool_exception("Failed to fetch all SRCs : " + str(e))
1646e0e0919SSridevi Ramesh    return src_id
165