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 682930050aSSridevi Rameshdef get_pel_data_from_bmc(): 692930050aSSridevi Ramesh r""" 702930050aSSridevi Ramesh Returns PEL data from BMC else throws exception. 712930050aSSridevi Ramesh """ 722930050aSSridevi Ramesh try: 732930050aSSridevi Ramesh pel_data = peltool(" -l") 742930050aSSridevi Ramesh if not pel_data: 752930050aSSridevi Ramesh print("No PEL data present in BMC ...") 762930050aSSridevi Ramesh except Exception as e: 772930050aSSridevi Ramesh raise peltool_exception("Failed to get PEL data from BMC : " + str(e)) 782930050aSSridevi Ramesh return pel_data 792930050aSSridevi Ramesh 802930050aSSridevi 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 = [] 94c80a3094SSridevi Ramesh pel_data = get_pel_data_from_bmc() 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 = [] 176c80a3094SSridevi Ramesh pel_data = get_pel_data_from_bmc() 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"]) 1816bf23630SSridevi Ramesh print("SRC IDs: " + str(src_id)) 1826e0e0919SSridevi Ramesh except Exception as e: 1836e0e0919SSridevi Ramesh raise peltool_exception("Failed to fetch all SRCs : " + str(e)) 1846e0e0919SSridevi Ramesh return src_id 1856bf23630SSridevi Ramesh 1866bf23630SSridevi Ramesh 1876bf23630SSridevi Rameshdef check_for_unexpected_src(unexpected_src_list=[]): 1886bf23630SSridevi Ramesh r""" 1896bf23630SSridevi Ramesh From the given unexpected SRC list, check if any unexpected SRC created 1906bf23630SSridevi Ramesh on the BMC. Returns 0 if no SRC found else throws exception. 1916bf23630SSridevi Ramesh 1926bf23630SSridevi Ramesh Description of arguments: 1936bf23630SSridevi Ramesh unexpected_src_list Give unexpected SRCs in the list format. 1946bf23630SSridevi Ramesh e.g.: ["BBXXYYYY", "AAXXYYYY"]. 1956bf23630SSridevi Ramesh """ 1966bf23630SSridevi Ramesh try: 1976bf23630SSridevi Ramesh unexpected_src_count = 0 1986bf23630SSridevi Ramesh if not unexpected_src_list: 1996bf23630SSridevi Ramesh print("Unexpected SRC list is empty.") 2006bf23630SSridevi Ramesh src_data = fetch_all_src() 2016bf23630SSridevi Ramesh for src in unexpected_src_list: 2026bf23630SSridevi Ramesh if src in src_data: 2036bf23630SSridevi Ramesh print("Found an unexpected SRC : " + src) 2046bf23630SSridevi Ramesh unexpected_src_count = unexpected_src_count + 1 2056bf23630SSridevi Ramesh if (unexpected_src_count >= 1): 2066bf23630SSridevi Ramesh raise peltool_exception("Unexpected SRC found.") 2076bf23630SSridevi Ramesh 2086bf23630SSridevi Ramesh except Exception as e: 2096bf23630SSridevi Ramesh raise peltool_exception("Failed to verify unexpected SRC list : " + str(e)) 2106bf23630SSridevi Ramesh return unexpected_src_count 211e8801a3fSAnusha Dathatri 212e8801a3fSAnusha Dathatri 213e8801a3fSAnusha Dathatridef filter_unexpected_srcs(expected_srcs=None): 214e8801a3fSAnusha Dathatri r""" 215e8801a3fSAnusha Dathatri Return list of SRCs found in BMC after filtering expected SRCs. 216e8801a3fSAnusha Dathatri If expected_srcs is None then all SRCs found in system are returned. 217e8801a3fSAnusha Dathatri 218e8801a3fSAnusha Dathatri Description of arguments: 219e8801a3fSAnusha Dathatri expected_srcs List of expected SRCs. E.g. ["BBXXYYYY", "AAXXYYYY"]. 220e8801a3fSAnusha Dathatri """ 221e8801a3fSAnusha Dathatri 222e8801a3fSAnusha Dathatri srcs_found = fetch_all_src() 223e8801a3fSAnusha Dathatri if not expected_srcs: 224e8801a3fSAnusha Dathatri expected_srcs = [] 225e8801a3fSAnusha Dathatri print(expected_srcs) 226e8801a3fSAnusha Dathatri return list(set(srcs_found) - set(expected_srcs)) 227*5636ad12SAnusha Dathatri 228*5636ad12SAnusha Dathatri 229*5636ad12SAnusha Dathatridef get_bmc_event_log_id_for_pel(pel_id): 230*5636ad12SAnusha Dathatri r""" 231*5636ad12SAnusha Dathatri Return BMC event log ID for the given PEL ID. 232*5636ad12SAnusha Dathatri 233*5636ad12SAnusha Dathatri Description of arguments: 234*5636ad12SAnusha Dathatri pel_id PEL ID. E.g. 0x50000021. 235*5636ad12SAnusha Dathatri """ 236*5636ad12SAnusha Dathatri 237*5636ad12SAnusha Dathatri pel_data = peltool("-i " + pel_id) 238*5636ad12SAnusha Dathatri print(pel_data) 239*5636ad12SAnusha Dathatri bmc_id_for_pel = pel_data["Private Header"]["BMC Event Log Id"] 240*5636ad12SAnusha Dathatri return bmc_id_for_pel 241