George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 2 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 3 | from gen_arg import * |
| 4 | from gen_call_robot import * |
| 5 | from gen_cmd import * |
| 6 | from gen_misc import * |
| 7 | from gen_plug_in_utils import * |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 8 | from gen_print import * |
| 9 | from gen_valid import * |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 10 | from var_funcs import * |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 11 | |
| 12 | # Set exit_on_error for gen_valid functions. |
| 13 | set_exit_on_error(True) |
| 14 | ignore_err = 0 |
| 15 | |
| 16 | |
| 17 | parser = argparse.ArgumentParser( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 18 | usage="%(prog)s [OPTIONS]", |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 19 | description="%(prog)s will calculate the value of num_err_logs and" |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 20 | + " save it as a plug-in value for the benefit of the FFDC plug-in." |
| 21 | + " The FFDC plug-in can use that data to decide whether to collect" |
| 22 | + " FFDC data.", |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 23 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 24 | prefix_chars="-+", |
| 25 | ) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 26 | |
| 27 | # The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we |
| 28 | # want. These stock parms are pre-defined by gen_get_options. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 29 | stock_list = [ |
| 30 | ("test_mode", 0), |
| 31 | ("quiet", get_plug_default("quiet", 0)), |
| 32 | ("debug", get_plug_default("debug", 0)), |
| 33 | ] |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 34 | |
| 35 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 36 | def exit_function(signal_number=0, frame=None): |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 37 | r""" |
| 38 | Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT). |
| 39 | |
| 40 | This function will be called by gen_exit_function(). |
| 41 | """ |
| 42 | |
| 43 | process_robot_output_files() |
| 44 | |
| 45 | |
| 46 | def validate_parms(): |
| 47 | r""" |
| 48 | Validate program parameters, etc. |
| 49 | |
| 50 | This function will be called by gen_setup(). |
| 51 | """ |
| 52 | |
| 53 | get_plug_vars() |
| 54 | |
| 55 | global AUTOSCRIPT_STATUS_FILE_PATH |
| 56 | # AUTOSCRIPT_STATUS_FILE_PATH is set when we're called by autoscript. For this program to work |
| 57 | # correctly, it must be called with autoscript. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 58 | AUTOSCRIPT_STATUS_FILE_PATH = os.environ.get( |
| 59 | "AUTOSCRIPT_STATUS_FILE_PATH", "" |
| 60 | ) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 61 | valid_value(AUTOSCRIPT_STATUS_FILE_PATH) |
| 62 | valid_value(AUTOBOOT_OPENBMC_HOST) |
| 63 | |
| 64 | |
| 65 | def main(): |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 66 | gen_setup() |
| 67 | |
| 68 | print_plug_in_header() |
| 69 | |
| 70 | # Get the number of error logs from the BMC. |
| 71 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 72 | high_sev_elogs_file_path = ( |
| 73 | AUTOBOOT_FFDC_DIR_PATH |
| 74 | + AUTOBOOT_FFDC_PREFIX |
| 75 | + "high_severity_errorlog.json" |
| 76 | ) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 77 | lib_file_path = init_robot_file_path("lib/logging_utils.robot") |
| 78 | lib_file_path += ":" + init_robot_file_path("lib/gen_robot_print.py") |
| 79 | set_mod_global(lib_file_path) |
| 80 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 81 | REDFISH_SUPPORT_TRANS_STATE = int( |
| 82 | os.environ.get("REDFISH_SUPPORT_TRANS_STATE", 0) |
| 83 | ) |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 84 | if not REDFISH_SUPPORT_TRANS_STATE: |
| 85 | try: |
| 86 | from robot.libraries.BuiltIn import BuiltIn |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 87 | |
| 88 | REDFISH_SUPPORT_TRANS_STATE = int( |
| 89 | BuiltIn().get_variable_value( |
| 90 | "${REDFISH_SUPPORT_TRANS_STATE}", default=0 |
| 91 | ) |
| 92 | ) |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 93 | except Exception: |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 94 | pass |
| 95 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 96 | keyword_redfish_strings = [ |
| 97 | ( |
| 98 | "${error_logs}= Get Redfish Event Logs " |
| 99 | " &{filter_low_severity_errlogs}" |
| 100 | ), |
| 101 | "${num_error_logs}= Get Length ${error_logs}", |
| 102 | "Rprint Vars num_error_logs", |
| 103 | ( |
| 104 | "${json_string}= Evaluate json.dumps($error_logs, indent=4) " |
| 105 | " modules=json" |
| 106 | ), |
| 107 | "Append To File " + high_sev_elogs_file_path + " ${json_string}", |
| 108 | ] |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 109 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 110 | keyword_strings = [ |
| 111 | "${error_logs}= Get Error Logs &{filter_low_severity_errlogs}", |
| 112 | "${num_error_logs}= Get Length ${error_logs}", |
| 113 | "Rprint Vars num_error_logs", |
| 114 | ( |
| 115 | "${json_string}= Evaluate json.dumps($error_logs, indent=4) " |
| 116 | " modules=json" |
| 117 | ), |
| 118 | "Append To File " + high_sev_elogs_file_path + " ${json_string}", |
| 119 | ] |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 120 | |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 121 | if REDFISH_SUPPORT_TRANS_STATE: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 122 | keyword_string = " ; ".join(keyword_redfish_strings) |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 123 | else: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 124 | keyword_string = " ; ".join(keyword_strings) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 125 | |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 126 | set_mod_global(keyword_string) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 127 | cmd_buf = create_robot_cmd_string( |
| 128 | "extended/run_keyword.robot", |
| 129 | OPENBMC_HOST, |
| 130 | SSH_PORT, |
| 131 | HTTPS_PORT, |
| 132 | REST_USERNAME, |
| 133 | REST_PASSWORD, |
| 134 | OPENBMC_USERNAME, |
| 135 | OPENBMC_PASSWORD, |
| 136 | keyword_string, |
| 137 | lib_file_path, |
| 138 | quiet, |
| 139 | test_mode, |
| 140 | debug, |
| 141 | outputdir, |
| 142 | output, |
| 143 | log, |
| 144 | report, |
| 145 | ) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 146 | if not robot_cmd_fnc(cmd_buf): |
| 147 | exit(1) |
| 148 | # The output contains the num_error_logs value which we will isolate with egrep. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 149 | rc, out_buf = shell_cmd( |
| 150 | "egrep '^num_error_logs:[ ]' " + AUTOSCRIPT_STATUS_FILE_PATH, |
| 151 | quiet=1, |
| 152 | print_output=0, |
| 153 | ) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 154 | result = key_value_outbuf_to_dict(out_buf) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 155 | num_error_logs = int(result["num_error_logs"]) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 156 | save_plug_in_value(num_error_logs) |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 157 | if num_error_logs > 0: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 158 | qprint_timen( |
| 159 | "Adding the name of our high severity error logs FFDC file " |
| 160 | + "to the appropriate file list." |
| 161 | ) |
| 162 | shell_cmd( |
| 163 | "echo " |
| 164 | + high_sev_elogs_file_path |
| 165 | + " > " |
| 166 | + AUTOBOOT_FFDC_LIST_FILE_PATH |
| 167 | ) |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 168 | else: |
| 169 | os.remove(high_sev_elogs_file_path) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 170 | |
| 171 | |
| 172 | main() |