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 10faa5d20aSRahul Maheshwari 11faa5d20aSRahul Maheshwari 12*6e0e0919SSridevi Rameshclass peltool_exception(Exception): 13*6e0e0919SSridevi Ramesh r""" 14*6e0e0919SSridevi Ramesh Base class for peltool related exceptions. 15*6e0e0919SSridevi Ramesh """ 16*6e0e0919SSridevi Ramesh def __init__(self, message): 17*6e0e0919SSridevi Ramesh self.message = message 18*6e0e0919SSridevi Ramesh super().__init__(self.message) 19*6e0e0919SSridevi Ramesh 20*6e0e0919SSridevi Ramesh 21a20876d3SMichael Walshdef peltool(option_string, parse_json=True, **bsu_options): 22faa5d20aSRahul Maheshwari r""" 23faa5d20aSRahul Maheshwari Run peltool on the BMC with the caller's option string and return the result. 24faa5d20aSRahul Maheshwari 25faa5d20aSRahul Maheshwari Example: 26faa5d20aSRahul Maheshwari 27faa5d20aSRahul Maheshwari ${pel_results}= Peltool -l 28faa5d20aSRahul Maheshwari Rprint Vars pel_results 29faa5d20aSRahul Maheshwari 30faa5d20aSRahul Maheshwari pel_results: 31faa5d20aSRahul Maheshwari [0x50000031]: 32faa5d20aSRahul Maheshwari [CompID]: 0x1000 33faa5d20aSRahul Maheshwari [PLID]: 0x50000031 34faa5d20aSRahul Maheshwari [Subsystem]: BMC Firmware 35faa5d20aSRahul Maheshwari [Message]: An application had an internal failure 36faa5d20aSRahul Maheshwari [SRC]: BD8D1002 37faa5d20aSRahul Maheshwari [Commit Time]: 02/25/2020 04:51:31 38faa5d20aSRahul Maheshwari [Sev]: Unrecoverable Error 39faa5d20aSRahul Maheshwari [CreatorID]: BMC 40faa5d20aSRahul Maheshwari 41faa5d20aSRahul Maheshwari Description of argument(s): 42faa5d20aSRahul Maheshwari option_string A string of options which are to be processed by the peltool command. 43a20876d3SMichael Walsh parse_json Indicates that the raw JSON data should parsed into a list of 44a20876d3SMichael Walsh dictionaries. 45faa5d20aSRahul Maheshwari bsu_options Options to be passed directly to bmc_execute_command. See its prolog for 46faa5d20aSRahul Maheshwari details. 47faa5d20aSRahul Maheshwari """ 48faa5d20aSRahul Maheshwari 49faa5d20aSRahul Maheshwari bsu_options = fa.args_to_objects(bsu_options) 50faa5d20aSRahul Maheshwari out_buf, stderr, rc = bsu.bmc_execute_command('peltool ' + option_string, **bsu_options) 51a20876d3SMichael Walsh if parse_json: 52a20876d3SMichael Walsh try: 53a20876d3SMichael Walsh return json.loads(out_buf) 54a20876d3SMichael Walsh except json.JSONDecodeError: 55a20876d3SMichael Walsh return {} 56faa5d20aSRahul Maheshwari return out_buf 57*6e0e0919SSridevi Ramesh 58*6e0e0919SSridevi Ramesh 59*6e0e0919SSridevi Rameshdef fetch_pelId_For_SRC(src_id): 60*6e0e0919SSridevi Ramesh r""" 61*6e0e0919SSridevi Ramesh Fetch PEL ID for the input SRC ID 62*6e0e0919SSridevi Ramesh 63*6e0e0919SSridevi Ramesh Description of arguments: 64*6e0e0919SSridevi Ramesh src_id SRC ID (e.g. BC20E504) 65*6e0e0919SSridevi Ramesh """ 66*6e0e0919SSridevi Ramesh 67*6e0e0919SSridevi Ramesh src_pel_id = [] 68*6e0e0919SSridevi Ramesh try: 69*6e0e0919SSridevi Ramesh pel_data = peltool(" -l") 70*6e0e0919SSridevi Ramesh pel_id_list = pel_data.keys() 71*6e0e0919SSridevi Ramesh for i in pel_id_list: 72*6e0e0919SSridevi Ramesh if pel_data[i]["SRC"] == src_id: 73*6e0e0919SSridevi Ramesh src_pel_id.append(i) 74*6e0e0919SSridevi Ramesh except Exception as e: 75*6e0e0919SSridevi Ramesh raise peltool_exception("Failed to fetch PEL ID for required SRC : " + str(e)) 76*6e0e0919SSridevi Ramesh return src_pel_id 77*6e0e0919SSridevi Ramesh 78*6e0e0919SSridevi Ramesh 79*6e0e0919SSridevi Rameshdef verify_SRC_details(pel_id, attn_type, target_type, signature_desc, 80*6e0e0919SSridevi Ramesh threshold_limit): 81*6e0e0919SSridevi Ramesh r""" 82*6e0e0919SSridevi Ramesh Verify SRC details for the given PEL ID based on the required 83*6e0e0919SSridevi Ramesh target type, attention type, signature description, threshold limit. 84*6e0e0919SSridevi Ramesh 85*6e0e0919SSridevi Ramesh Description of arguments: 86*6e0e0919SSridevi Ramesh pel_id PEL ID for the required SRC details to verify 87*6e0e0919SSridevi Ramesh target_type Target type (e.g. TYPE_OMIC) 88*6e0e0919SSridevi Ramesh attn_type Attention type (e.g. RECCOVERABLE) 89*6e0e0919SSridevi Ramesh signature_desc Signature description of the error inject 90*6e0e0919SSridevi Ramesh threshold_limit Threshold limit (e.g. 1, 5, 32) 91*6e0e0919SSridevi Ramesh """ 92*6e0e0919SSridevi Ramesh 93*6e0e0919SSridevi Ramesh try: 94*6e0e0919SSridevi Ramesh pel_cmd = " -i " + pel_id 95*6e0e0919SSridevi Ramesh src_data = peltool(pel_cmd) 96*6e0e0919SSridevi Ramesh src_dict = src_data["Primary SRC"]["SRC Details"] 97*6e0e0919SSridevi Ramesh usr_data = src_data["User Data 4"] 98*6e0e0919SSridevi Ramesh if (src_dict["Attention Type"] != attn_type): 99*6e0e0919SSridevi Ramesh raise peltool_exception("Required Attention type " + attn_type + " not found") 100*6e0e0919SSridevi Ramesh if target_type not in src_dict["Target Type"]: 101*6e0e0919SSridevi Ramesh raise peltool_exception("Required Target type " + target_type + " not found") 102*6e0e0919SSridevi Ramesh if signature_desc not in src_dict["Signature"]: 103*6e0e0919SSridevi Ramesh raise peltool_exception("Required Signature " + signature_desc + " not found") 104*6e0e0919SSridevi Ramesh 105*6e0e0919SSridevi Ramesh if (int(threshold_limit) != usr_data["Error Threshold"]): 106*6e0e0919SSridevi Ramesh raise peltool_exception("Required Threshold limit " + threshold_limit + " not found") 107*6e0e0919SSridevi Ramesh 108*6e0e0919SSridevi Ramesh except Exception as e: 109*6e0e0919SSridevi Ramesh raise peltool_exception("Failed to verify SRC details : " + str(e)) 110*6e0e0919SSridevi Ramesh 111*6e0e0919SSridevi Ramesh return True 112*6e0e0919SSridevi Ramesh 113*6e0e0919SSridevi Ramesh 114*6e0e0919SSridevi Rameshdef fetch_All_SRC(): 115*6e0e0919SSridevi Ramesh r""" 116*6e0e0919SSridevi Ramesh Fetch all list of SRC IDs from peltool 117*6e0e0919SSridevi Ramesh """ 118*6e0e0919SSridevi Ramesh 119*6e0e0919SSridevi Ramesh src_id = [] 120*6e0e0919SSridevi Ramesh try: 121*6e0e0919SSridevi Ramesh pel_data = peltool(" -l") 122*6e0e0919SSridevi Ramesh pel_id_list = pel_data.keys() 123*6e0e0919SSridevi Ramesh for i in pel_id_list: 124*6e0e0919SSridevi Ramesh src_id.append(pel_data[i]["SRC"]) 125*6e0e0919SSridevi Ramesh except Exception as e: 126*6e0e0919SSridevi Ramesh raise peltool_exception("Failed to fetch all SRCs : " + str(e)) 127*6e0e0919SSridevi Ramesh return src_id 128