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