xref: /openbmc/openbmc-test-automation/lib/pel_utils.py (revision d1cb3252aa5e360342e65c0338e486265a84cfe1)
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
1048ffa2c2SGeorge Keishingimport os
1148ffa2c2SGeorge Keishingimport sys
1248ffa2c2SGeorge Keishingfrom robot.libraries.BuiltIn import BuiltIn
1348ffa2c2SGeorge Keishing
1448ffa2c2SGeorge Keishingbase_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1548ffa2c2SGeorge Keishingsys.path.append(base_path + "/data/")
1648ffa2c2SGeorge 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    """
2448ffa2c2SGeorge 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
68*d1cb3252SSridevi Rameshdef get_pel_data_from_bmc(include_hidden_pels=False,
69*d1cb3252SSridevi Ramesh                          include_informational_pels=False):
702930050aSSridevi Ramesh    r"""
712930050aSSridevi Ramesh    Returns PEL data from BMC else throws exception.
72*d1cb3252SSridevi Ramesh
73*d1cb3252SSridevi Ramesh    Description of arguments:
74*d1cb3252SSridevi Ramesh    include_hidden_pels           True/False (default: False).
75*d1cb3252SSridevi Ramesh                                  Set True to get hidden PELs else False.
76*d1cb3252SSridevi Ramesh    include_informational_pels    True/False (default: False).
77*d1cb3252SSridevi Ramesh                                  Set True to get informational PELs else False.
782930050aSSridevi Ramesh    """
792930050aSSridevi Ramesh    try:
80*d1cb3252SSridevi Ramesh        pel_cmd = " -l"
81*d1cb3252SSridevi Ramesh        if include_hidden_pels:
82*d1cb3252SSridevi Ramesh            pel_cmd = pel_cmd + " -h"
83*d1cb3252SSridevi Ramesh        if include_informational_pels:
84*d1cb3252SSridevi Ramesh            pel_cmd = pel_cmd + " -f"
85*d1cb3252SSridevi Ramesh        pel_data = peltool(pel_cmd)
862930050aSSridevi Ramesh        if not pel_data:
872930050aSSridevi Ramesh            print("No PEL data present in BMC ...")
882930050aSSridevi Ramesh    except Exception as e:
892930050aSSridevi Ramesh        raise peltool_exception("Failed to get PEL data from BMC : " + str(e))
902930050aSSridevi Ramesh    return pel_data
912930050aSSridevi Ramesh
922930050aSSridevi Ramesh
93*d1cb3252SSridevi Rameshdef fetch_all_pel_ids_for_src(src_id, severity, include_hidden_pels=False):
946e0e0919SSridevi Ramesh    r"""
95c6dd799dSSridevi Ramesh    Fetch all PEL IDs for the input SRC ID based on the severity type
96c6dd799dSSridevi Ramesh    in the list format.
976e0e0919SSridevi Ramesh
986e0e0919SSridevi Ramesh    Description of arguments:
99*d1cb3252SSridevi Ramesh    src_id                SRC ID (e.g. BCXXYYYY).
100c6dd799dSSridevi Ramesh    severity              PEL severity (e.g. "Predictive Error"
101c6dd799dSSridevi Ramesh                                             "Recovered Error").
102*d1cb3252SSridevi Ramesh    include_hidden_pels   True/False (default: False).
103*d1cb3252SSridevi Ramesh                          Set True to get hidden PELs else False.
1046e0e0919SSridevi Ramesh    """
1056e0e0919SSridevi Ramesh
1066e0e0919SSridevi Ramesh    try:
107c6dd799dSSridevi Ramesh        src_pel_ids = []
108*d1cb3252SSridevi Ramesh        pel_data = get_pel_data_from_bmc(include_hidden_pels)
1096e0e0919SSridevi Ramesh        pel_id_list = pel_data.keys()
110c6dd799dSSridevi Ramesh        for pel_id in pel_id_list:
111c6dd799dSSridevi Ramesh            # Check if required SRC ID with severity is present
112c6dd799dSSridevi Ramesh            if ((pel_data[pel_id]["SRC"] == src_id) and (pel_data[pel_id]["Sev"] == severity)):
113c6dd799dSSridevi Ramesh                src_pel_ids.append(pel_id)
114c6dd799dSSridevi Ramesh
115c6dd799dSSridevi Ramesh        if not src_pel_ids:
116c6dd799dSSridevi Ramesh            raise peltool_exception(src_id + " with severity " + severity + " not present")
1176e0e0919SSridevi Ramesh    except Exception as e:
1186e0e0919SSridevi Ramesh        raise peltool_exception("Failed to fetch PEL ID for required SRC : " + str(e))
119c6dd799dSSridevi Ramesh    return src_pel_ids
1206e0e0919SSridevi Ramesh
1216e0e0919SSridevi Ramesh
122c6dd799dSSridevi Rameshdef verify_src_signature_and_threshold(pel_id, attn_type, signature_desc, th_limit):
1236e0e0919SSridevi Ramesh    r"""
124c6dd799dSSridevi Ramesh    Verifies SRC details for the given PEL ID based on the required
125c6dd799dSSridevi Ramesh    attention type, signature description, threshold limits.
1266e0e0919SSridevi Ramesh
1276e0e0919SSridevi Ramesh    Description of arguments:
128c6dd799dSSridevi Ramesh    pel_id          PEL ID for the required SRC details to verify.
129c6dd799dSSridevi Ramesh    attn_type       Attention type (e.g. RE, CS, UNIT_CS).
130c6dd799dSSridevi Ramesh    signature_desc  Signature description of the error inject.
131c6dd799dSSridevi Ramesh    th_limit        Threshold limit (e.g. 1, 5, 32).
1326e0e0919SSridevi Ramesh    """
1336e0e0919SSridevi Ramesh
1346e0e0919SSridevi Ramesh    try:
1356e0e0919SSridevi Ramesh        pel_cmd = " -i " + pel_id
1366e0e0919SSridevi Ramesh        src_data = peltool(pel_cmd)
1376e0e0919SSridevi Ramesh        src_dict = src_data["Primary SRC"]["SRC Details"]
138c6dd799dSSridevi Ramesh        usr_data = src_data["User Data 1"]
139c6dd799dSSridevi Ramesh
140c6dd799dSSridevi Ramesh        # Example for signature in recoverable error
141c6dd799dSSridevi Ramesh        #
142c6dd799dSSridevi Ramesh        # "SRC Details": {
143c6dd799dSSridevi Ramesh        # "Attention Type": "RECOVERABLE",
144c6dd799dSSridevi Ramesh        # "Node": 0,
145c6dd799dSSridevi Ramesh        # "Target Type": "TYPE_OMIC",
146c6dd799dSSridevi Ramesh        # "Target Instance": 0,
147c6dd799dSSridevi Ramesh        # "Signature": "MC_OMI_DL_FIR[1]: OMI-DL0 UE on data flit"
148c6dd799dSSridevi Ramesh        # }
149c6dd799dSSridevi Ramesh        if (attn_type == "RE"):
150c6dd799dSSridevi Ramesh            if (src_dict["Attention Type"] != "RECOVERABLE"):
1516e0e0919SSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
152c6dd799dSSridevi Ramesh
153c6dd799dSSridevi Ramesh        # Example for signature in system checkstop error
154c6dd799dSSridevi Ramesh        #
155c6dd799dSSridevi Ramesh        # "SRC Details": {
156c6dd799dSSridevi Ramesh        # "Primary Attention": "system checkstop",
157c6dd799dSSridevi Ramesh        # "Signature Description": {
158c6dd799dSSridevi Ramesh        #    "Chip Desc": "node 0 proc 0 (P10 2.0)",
159c6dd799dSSridevi Ramesh        #    "Signature": "EQ_L2_FIR(0)[7] L2 directory read UE",
160c6dd799dSSridevi Ramesh        #    "Attn Type": "checkstop"
161c6dd799dSSridevi Ramesh        # }
162c6dd799dSSridevi Ramesh
163c6dd799dSSridevi Ramesh        elif (attn_type == "CS"):
164c6dd799dSSridevi Ramesh            if (src_dict["Primary Attention"] != "system checkstop"):
165c6dd799dSSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
166c6dd799dSSridevi Ramesh
167c6dd799dSSridevi Ramesh        elif (attn_type == "UNIT_CS"):
168c6dd799dSSridevi Ramesh            if (src_dict["Attention Type"] != "UNIT_CS"):
169c6dd799dSSridevi Ramesh                raise peltool_exception("Required Attention type " + attn_type + " not found")
170c6dd799dSSridevi Ramesh        else:
171c6dd799dSSridevi Ramesh            raise peltool_exception("Required Attention type " + attn_type + " not found")
172c6dd799dSSridevi Ramesh
1736e0e0919SSridevi Ramesh        if signature_desc not in src_dict["Signature"]:
1746e0e0919SSridevi Ramesh            raise peltool_exception("Required Signature " + signature_desc + " not found")
1756e0e0919SSridevi Ramesh
176c6dd799dSSridevi Ramesh        if (int(th_limit) != usr_data["Error Count"]):
177c6dd799dSSridevi Ramesh            raise peltool_exception("Required Threshold limit " + th_limit + " not found")
1786e0e0919SSridevi Ramesh
1796e0e0919SSridevi Ramesh    except Exception as e:
1806e0e0919SSridevi Ramesh        raise peltool_exception("Failed to verify SRC details : " + str(e))
1816e0e0919SSridevi Ramesh    return True
1826e0e0919SSridevi Ramesh
1836e0e0919SSridevi Ramesh
184*d1cb3252SSridevi Rameshdef fetch_all_src(include_hidden_pels=False):
1856e0e0919SSridevi Ramesh    r"""
186c6dd799dSSridevi Ramesh    Fetch all SRC IDs from peltool in the list format.
187*d1cb3252SSridevi Ramesh
188*d1cb3252SSridevi Ramesh    include_hidden_pels       True/False (default: False).
189*d1cb3252SSridevi Ramesh                              Set True to get hidden PELs else False.
1906e0e0919SSridevi Ramesh    """
1916e0e0919SSridevi Ramesh    try:
192c6dd799dSSridevi Ramesh        src_id = []
193*d1cb3252SSridevi Ramesh        pel_data = get_pel_data_from_bmc(include_hidden_pels)
194c6dd799dSSridevi Ramesh        if pel_data:
1956e0e0919SSridevi Ramesh            pel_id_list = pel_data.keys()
196c6dd799dSSridevi Ramesh            for pel_id in pel_id_list:
197c6dd799dSSridevi Ramesh                src_id.append(pel_data[pel_id]["SRC"])
1986bf23630SSridevi Ramesh        print("SRC IDs: " + str(src_id))
1996e0e0919SSridevi Ramesh    except Exception as e:
2006e0e0919SSridevi Ramesh        raise peltool_exception("Failed to fetch all SRCs : " + str(e))
2016e0e0919SSridevi Ramesh    return src_id
2026bf23630SSridevi Ramesh
2036bf23630SSridevi Ramesh
204*d1cb3252SSridevi Rameshdef check_for_unexpected_src(unexpected_src_list=[], include_hidden_pels=False):
2056bf23630SSridevi Ramesh    r"""
2066bf23630SSridevi Ramesh    From the given unexpected SRC list, check if any unexpected SRC created
2076bf23630SSridevi Ramesh    on the BMC. Returns 0 if no SRC found else throws exception.
2086bf23630SSridevi Ramesh
2096bf23630SSridevi Ramesh    Description of arguments:
2106bf23630SSridevi Ramesh    unexpected_src_list       Give unexpected SRCs in the list format.
2116bf23630SSridevi Ramesh                              e.g.: ["BBXXYYYY", "AAXXYYYY"].
212*d1cb3252SSridevi Ramesh
213*d1cb3252SSridevi Ramesh    include_hidden_pels       True/False (default: False).
214*d1cb3252SSridevi Ramesh                              Set True to get hidden PELs else False.
2156bf23630SSridevi Ramesh    """
2166bf23630SSridevi Ramesh    try:
2176bf23630SSridevi Ramesh        unexpected_src_count = 0
2186bf23630SSridevi Ramesh        if not unexpected_src_list:
2196bf23630SSridevi Ramesh            print("Unexpected SRC list is empty.")
220*d1cb3252SSridevi Ramesh        src_data = fetch_all_src(include_hidden_pels)
2216bf23630SSridevi Ramesh        for src in unexpected_src_list:
2226bf23630SSridevi Ramesh            if src in src_data:
2236bf23630SSridevi Ramesh                print("Found an unexpected SRC : " + src)
2246bf23630SSridevi Ramesh                unexpected_src_count = unexpected_src_count + 1
2256bf23630SSridevi Ramesh        if (unexpected_src_count >= 1):
2266bf23630SSridevi Ramesh            raise peltool_exception("Unexpected SRC found.")
2276bf23630SSridevi Ramesh
2286bf23630SSridevi Ramesh    except Exception as e:
2296bf23630SSridevi Ramesh        raise peltool_exception("Failed to verify unexpected SRC list : " + str(e))
2306bf23630SSridevi Ramesh    return unexpected_src_count
231e8801a3fSAnusha Dathatri
232e8801a3fSAnusha Dathatri
233e8801a3fSAnusha Dathatridef filter_unexpected_srcs(expected_srcs=None):
234e8801a3fSAnusha Dathatri    r"""
235e8801a3fSAnusha Dathatri    Return list of SRCs found in BMC after filtering expected SRCs.
236e8801a3fSAnusha Dathatri    If expected_srcs is None then all SRCs found in system are returned.
237e8801a3fSAnusha Dathatri
238e8801a3fSAnusha Dathatri    Description of arguments:
239e8801a3fSAnusha Dathatri    expected_srcs       List of expected SRCs. E.g. ["BBXXYYYY", "AAXXYYYY"].
240e8801a3fSAnusha Dathatri    """
241e8801a3fSAnusha Dathatri
242e8801a3fSAnusha Dathatri    srcs_found = fetch_all_src()
243e8801a3fSAnusha Dathatri    if not expected_srcs:
244e8801a3fSAnusha Dathatri        expected_srcs = []
245e8801a3fSAnusha Dathatri    print(expected_srcs)
246e8801a3fSAnusha Dathatri    return list(set(srcs_found) - set(expected_srcs))
2475636ad12SAnusha Dathatri
2485636ad12SAnusha Dathatri
2495636ad12SAnusha Dathatridef get_bmc_event_log_id_for_pel(pel_id):
2505636ad12SAnusha Dathatri    r"""
2515636ad12SAnusha Dathatri    Return BMC event log ID for the given PEL ID.
2525636ad12SAnusha Dathatri
2535636ad12SAnusha Dathatri    Description of arguments:
2545636ad12SAnusha Dathatri    pel_id       PEL ID. E.g. 0x50000021.
2555636ad12SAnusha Dathatri    """
2565636ad12SAnusha Dathatri
2575636ad12SAnusha Dathatri    pel_data = peltool("-i " + pel_id)
2585636ad12SAnusha Dathatri    print(pel_data)
2595636ad12SAnusha Dathatri    bmc_id_for_pel = pel_data["Private Header"]["BMC Event Log Id"]
2605636ad12SAnusha Dathatri    return bmc_id_for_pel
261