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*2930050aSSridevi Rameshdef get_pel_data_from_bmc(): 69*2930050aSSridevi Ramesh r""" 70*2930050aSSridevi Ramesh Returns PEL data from BMC else throws exception. 71*2930050aSSridevi Ramesh """ 72*2930050aSSridevi Ramesh try: 73*2930050aSSridevi Ramesh pel_data = peltool(" -l") 74*2930050aSSridevi Ramesh if not pel_data: 75*2930050aSSridevi Ramesh print("No PEL data present in BMC ...") 76*2930050aSSridevi Ramesh except Exception as e: 77*2930050aSSridevi Ramesh raise peltool_exception("Failed to get PEL data from BMC : " + str(e)) 78*2930050aSSridevi Ramesh return pel_data 79*2930050aSSridevi Ramesh 80*2930050aSSridevi Ramesh 81c6dd799dSSridevi Rameshdef fetch_all_pel_ids_for_src(src_id, severity): 826e0e0919SSridevi Ramesh r""" 83c6dd799dSSridevi Ramesh Fetch all PEL IDs for the input SRC ID based on the severity type 84c6dd799dSSridevi Ramesh in the list format. 856e0e0919SSridevi Ramesh 866e0e0919SSridevi Ramesh Description of arguments: 87c6dd799dSSridevi Ramesh src_id SRC ID (e.g. BC20E504). 88c6dd799dSSridevi Ramesh severity PEL severity (e.g. "Predictive Error" 89c6dd799dSSridevi Ramesh "Recovered Error"). 906e0e0919SSridevi Ramesh """ 916e0e0919SSridevi Ramesh 926e0e0919SSridevi Ramesh try: 93c6dd799dSSridevi Ramesh src_pel_ids = [] 946e0e0919SSridevi Ramesh pel_data = peltool(" -l") 956e0e0919SSridevi Ramesh pel_id_list = pel_data.keys() 96c6dd799dSSridevi Ramesh for pel_id in pel_id_list: 97c6dd799dSSridevi Ramesh # Check if required SRC ID with severity is present 98c6dd799dSSridevi Ramesh if ((pel_data[pel_id]["SRC"] == src_id) and (pel_data[pel_id]["Sev"] == severity)): 99c6dd799dSSridevi Ramesh src_pel_ids.append(pel_id) 100c6dd799dSSridevi Ramesh 101c6dd799dSSridevi Ramesh if not src_pel_ids: 102c6dd799dSSridevi Ramesh raise peltool_exception(src_id + " with severity " + severity + " not present") 1036e0e0919SSridevi Ramesh except Exception as e: 1046e0e0919SSridevi Ramesh raise peltool_exception("Failed to fetch PEL ID for required SRC : " + str(e)) 105c6dd799dSSridevi Ramesh return src_pel_ids 1066e0e0919SSridevi Ramesh 1076e0e0919SSridevi Ramesh 108c6dd799dSSridevi Rameshdef verify_src_signature_and_threshold(pel_id, attn_type, signature_desc, th_limit): 1096e0e0919SSridevi Ramesh r""" 110c6dd799dSSridevi Ramesh Verifies SRC details for the given PEL ID based on the required 111c6dd799dSSridevi Ramesh attention type, signature description, threshold limits. 1126e0e0919SSridevi Ramesh 1136e0e0919SSridevi Ramesh Description of arguments: 114c6dd799dSSridevi Ramesh pel_id PEL ID for the required SRC details to verify. 115c6dd799dSSridevi Ramesh attn_type Attention type (e.g. RE, CS, UNIT_CS). 116c6dd799dSSridevi Ramesh signature_desc Signature description of the error inject. 117c6dd799dSSridevi Ramesh th_limit Threshold limit (e.g. 1, 5, 32). 1186e0e0919SSridevi Ramesh """ 1196e0e0919SSridevi Ramesh 1206e0e0919SSridevi Ramesh try: 1216e0e0919SSridevi Ramesh pel_cmd = " -i " + pel_id 1226e0e0919SSridevi Ramesh src_data = peltool(pel_cmd) 1236e0e0919SSridevi Ramesh src_dict = src_data["Primary SRC"]["SRC Details"] 124c6dd799dSSridevi Ramesh usr_data = src_data["User Data 1"] 125c6dd799dSSridevi Ramesh 126c6dd799dSSridevi Ramesh # Example for signature in recoverable error 127c6dd799dSSridevi Ramesh # 128c6dd799dSSridevi Ramesh # "SRC Details": { 129c6dd799dSSridevi Ramesh # "Attention Type": "RECOVERABLE", 130c6dd799dSSridevi Ramesh # "Node": 0, 131c6dd799dSSridevi Ramesh # "Target Type": "TYPE_OMIC", 132c6dd799dSSridevi Ramesh # "Target Instance": 0, 133c6dd799dSSridevi Ramesh # "Signature": "MC_OMI_DL_FIR[1]: OMI-DL0 UE on data flit" 134c6dd799dSSridevi Ramesh # } 135c6dd799dSSridevi Ramesh if (attn_type == "RE"): 136c6dd799dSSridevi Ramesh if (src_dict["Attention Type"] != "RECOVERABLE"): 1376e0e0919SSridevi Ramesh raise peltool_exception("Required Attention type " + attn_type + " not found") 138c6dd799dSSridevi Ramesh 139c6dd799dSSridevi Ramesh # Example for signature in system checkstop error 140c6dd799dSSridevi Ramesh # 141c6dd799dSSridevi Ramesh # "SRC Details": { 142c6dd799dSSridevi Ramesh # "Primary Attention": "system checkstop", 143c6dd799dSSridevi Ramesh # "Signature Description": { 144c6dd799dSSridevi Ramesh # "Chip Desc": "node 0 proc 0 (P10 2.0)", 145c6dd799dSSridevi Ramesh # "Signature": "EQ_L2_FIR(0)[7] L2 directory read UE", 146c6dd799dSSridevi Ramesh # "Attn Type": "checkstop" 147c6dd799dSSridevi Ramesh # } 148c6dd799dSSridevi Ramesh 149c6dd799dSSridevi Ramesh elif (attn_type == "CS"): 150c6dd799dSSridevi Ramesh if (src_dict["Primary Attention"] != "system checkstop"): 151c6dd799dSSridevi Ramesh raise peltool_exception("Required Attention type " + attn_type + " not found") 152c6dd799dSSridevi Ramesh 153c6dd799dSSridevi Ramesh elif (attn_type == "UNIT_CS"): 154c6dd799dSSridevi Ramesh if (src_dict["Attention Type"] != "UNIT_CS"): 155c6dd799dSSridevi Ramesh raise peltool_exception("Required Attention type " + attn_type + " not found") 156c6dd799dSSridevi Ramesh else: 157c6dd799dSSridevi Ramesh raise peltool_exception("Required Attention type " + attn_type + " not found") 158c6dd799dSSridevi Ramesh 1596e0e0919SSridevi Ramesh if signature_desc not in src_dict["Signature"]: 1606e0e0919SSridevi Ramesh raise peltool_exception("Required Signature " + signature_desc + " not found") 1616e0e0919SSridevi Ramesh 162c6dd799dSSridevi Ramesh if (int(th_limit) != usr_data["Error Count"]): 163c6dd799dSSridevi Ramesh raise peltool_exception("Required Threshold limit " + th_limit + " not found") 1646e0e0919SSridevi Ramesh 1656e0e0919SSridevi Ramesh except Exception as e: 1666e0e0919SSridevi Ramesh raise peltool_exception("Failed to verify SRC details : " + str(e)) 1676e0e0919SSridevi Ramesh return True 1686e0e0919SSridevi Ramesh 1696e0e0919SSridevi Ramesh 170c6dd799dSSridevi Rameshdef fetch_all_src(): 1716e0e0919SSridevi Ramesh r""" 172c6dd799dSSridevi Ramesh Fetch all SRC IDs from peltool in the list format. 1736e0e0919SSridevi Ramesh """ 1746e0e0919SSridevi Ramesh try: 175c6dd799dSSridevi Ramesh src_id = [] 1766e0e0919SSridevi Ramesh pel_data = peltool(" -l") 177c6dd799dSSridevi Ramesh if pel_data: 1786e0e0919SSridevi Ramesh pel_id_list = pel_data.keys() 179c6dd799dSSridevi Ramesh for pel_id in pel_id_list: 180c6dd799dSSridevi Ramesh src_id.append(pel_data[pel_id]["SRC"]) 181c6dd799dSSridevi Ramesh else: 182c6dd799dSSridevi Ramesh raise peltool_exception("No PEL entry found ..") 1836e0e0919SSridevi Ramesh except Exception as e: 1846e0e0919SSridevi Ramesh raise peltool_exception("Failed to fetch all SRCs : " + str(e)) 1856e0e0919SSridevi Ramesh return src_id 186