Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | PLDM functions. |
| 5 | """ |
| 6 | |
| 7 | import re |
| 8 | import var_funcs as vf |
| 9 | import func_args as fa |
| 10 | import bmc_ssh_utils as bsu |
| 11 | |
| 12 | |
| 13 | def pldmtool(option_string, parse_results=1, **bsu_options): |
| 14 | r""" |
| 15 | Run pldmtool on the BMC with the caller's option string and return the result. |
| 16 | |
| 17 | Example: |
| 18 | |
| 19 | ${pldm_results}= Pldmtool base GetPLDMTypes |
| 20 | Rprint Vars pldm_results |
| 21 | |
| 22 | pldm_results: |
| 23 | [request_message]: 08 01 80 00 04 |
| 24 | [success_in_creating_the_socket]: RC = 3 |
| 25 | [success_in_connecting_to_socket]: RC = 0 |
| 26 | [success_in_sending_message_type_as_pldm_to_mctp]:RC = 0 |
| 27 | [write_to_socket_successful]: RC = 5 |
| 28 | [total_length]: 14 |
| 29 | [loopback_response_message]: 08 01 80 00 04 |
| 30 | [on_first_recv(),response_==_request]: RC = 0 |
| 31 | [shutdown_socket_successful]: RC = 0 |
| 32 | [response_message]: 08 01 00 00 04 00 0d 00 00 00 00 00 00 00 |
| 33 | [supported_types]: |
| 34 | [raw]: |
| 35 | [0]: 0 |
| 36 | [1]: 2 |
| 37 | [2]: 3 |
| 38 | [text]: |
| 39 | [0]: base |
| 40 | [1]: platform |
| 41 | [2]: bios |
| 42 | |
| 43 | Description of argument(s): |
| 44 | option_string A string of options which are to be processed by the pldmtool command. |
| 45 | parse_results Parse the pldmtool results and return a dictionary rather than the raw |
| 46 | pldmtool output. |
| 47 | bsu_options Options to be passed directly to bmc_execute_command. See its prolog for |
| 48 | details. |
| 49 | """ |
| 50 | |
| 51 | # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}). |
| 52 | bsu_options = fa.args_to_objects(bsu_options) |
| 53 | |
| 54 | stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options) |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 55 | if parse_results: |
| 56 | # Remove linefeeds following colons. |
| 57 | stdout = re.sub(":\n", ":", stdout) |
| 58 | # Remove first line (e.g. "Encode request successfully"). |
| 59 | stdout = re.sub("^.*\\n", "", stdout) |
Sridevi Ramesh | fe52e40 | 2020-02-05 00:15:24 -0600 | [diff] [blame] | 60 | stdout = re.sub('\x00', "", stdout) |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 61 | result = vf.key_value_outbuf_to_dict(stdout) |
| 62 | if 'supported_types' in result: |
| 63 | # 'supported types' begins like this: |
| 64 | # 0(base) 2(platform) 3(bios) |
| 65 | # Parsing it to look like it does in the example above. |
| 66 | supported_types = {'raw': [], 'text': []} |
| 67 | for entry in result['supported_types'].split(" "): |
| 68 | record = entry.split("(") |
| 69 | supported_types['raw'].append(record[0]) |
| 70 | supported_types['text'].append(record[1].rstrip(")")) |
| 71 | result['supported_types'] = supported_types |
Sridevi Ramesh | fe52e40 | 2020-02-05 00:15:24 -0600 | [diff] [blame] | 72 | elif 'date_&_time' in result: |
| 73 | # Date & Time : |
| 74 | # YYYY-MM-DD HH:MM:SS - 2020-02-24 06:44:16 |
Sridevi Ramesh | 1495bc4 | 2020-02-04 03:13:33 -0600 | [diff] [blame] | 75 | return result['yyyy-mm-dd_hh'].split(' - ')[1] |
Sridevi Ramesh | fe52e40 | 2020-02-05 00:15:24 -0600 | [diff] [blame] | 76 | elif 'parsed_response_msg' in result: |
| 77 | dict_data1, dict_data2 = vf.split_dict_on_key('parsed_response_msg', result) |
| 78 | dict_data2.pop('parsed_response_msg') |
| 79 | if 'fru_datastructuretableintegritychecksum' in dict_data2: |
| 80 | dict_data2.pop('fru_datastructuretableintegritychecksum') |
| 81 | return dict_data2 |
Sridevi Ramesh | 1495bc4 | 2020-02-04 03:13:33 -0600 | [diff] [blame] | 82 | |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 83 | return result |
| 84 | |
| 85 | return stdout |