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 | |
| 3 | from gen_print import * |
| 4 | from gen_valid import * |
| 5 | from gen_arg import * |
| 6 | from gen_misc import * |
| 7 | from gen_cmd import * |
| 8 | from var_funcs import * |
| 9 | from gen_plug_in_utils import * |
| 10 | from gen_call_robot import * |
| 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( |
| 18 | usage='%(prog)s [OPTIONS]', |
| 19 | description="%(prog)s will calculate the value of num_err_logs and" |
| 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.", |
| 23 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 24 | prefix_chars='-+') |
| 25 | |
| 26 | # The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we |
| 27 | # want. These stock parms are pre-defined by gen_get_options. |
| 28 | stock_list = [("test_mode", 0), |
| 29 | ("quiet", get_plug_default("quiet", 0)), |
| 30 | ("debug", get_plug_default("debug", 0))] |
| 31 | |
| 32 | |
| 33 | def exit_function(signal_number=0, |
| 34 | frame=None): |
| 35 | r""" |
| 36 | Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT). |
| 37 | |
| 38 | This function will be called by gen_exit_function(). |
| 39 | """ |
| 40 | |
| 41 | process_robot_output_files() |
| 42 | |
| 43 | |
| 44 | def validate_parms(): |
| 45 | r""" |
| 46 | Validate program parameters, etc. |
| 47 | |
| 48 | This function will be called by gen_setup(). |
| 49 | """ |
| 50 | |
| 51 | get_plug_vars() |
| 52 | |
| 53 | global AUTOSCRIPT_STATUS_FILE_PATH |
| 54 | # AUTOSCRIPT_STATUS_FILE_PATH is set when we're called by autoscript. For this program to work |
| 55 | # correctly, it must be called with autoscript. |
| 56 | AUTOSCRIPT_STATUS_FILE_PATH = os.environ.get("AUTOSCRIPT_STATUS_FILE_PATH", "") |
| 57 | valid_value(AUTOSCRIPT_STATUS_FILE_PATH) |
| 58 | valid_value(AUTOBOOT_OPENBMC_HOST) |
| 59 | |
| 60 | |
| 61 | def main(): |
| 62 | |
| 63 | gen_setup() |
| 64 | |
| 65 | print_plug_in_header() |
| 66 | |
| 67 | # Get the number of error logs from the BMC. |
| 68 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 69 | high_sev_elogs_file_path = AUTOBOOT_FFDC_DIR_PATH + AUTOBOOT_FFDC_PREFIX + "high_severity_errorlog.json" |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 70 | lib_file_path = init_robot_file_path("lib/logging_utils.robot") |
| 71 | lib_file_path += ":" + init_robot_file_path("lib/gen_robot_print.py") |
| 72 | set_mod_global(lib_file_path) |
| 73 | |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 74 | REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) |
| 75 | if not REDFISH_SUPPORT_TRANS_STATE: |
| 76 | try: |
| 77 | from robot.libraries.BuiltIn import BuiltIn |
| 78 | REDFISH_SUPPORT_TRANS_STATE = int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0)) |
| 79 | except: |
| 80 | pass |
| 81 | |
| 82 | keyword_redfish_strings = \ |
| 83 | [ |
| 84 | "${error_logs}= Get Redfish Event Logs &{filter_low_severity_errlogs}", |
| 85 | "${num_error_logs}= Get Length ${error_logs}", |
| 86 | "Rprint Vars num_error_logs", |
| 87 | "${json_string}= Evaluate json.dumps($error_logs, indent=4) modules=json", |
| 88 | "Append To File " + high_sev_elogs_file_path + " ${json_string}" |
| 89 | ] |
| 90 | |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 91 | keyword_strings = \ |
| 92 | [ |
| 93 | "${error_logs}= Get Error Logs &{filter_low_severity_errlogs}", |
| 94 | "${num_error_logs}= Get Length ${error_logs}", |
| 95 | "Rprint Vars num_error_logs", |
| 96 | "${json_string}= Evaluate json.dumps($error_logs, indent=4) modules=json", |
| 97 | "Append To File " + high_sev_elogs_file_path + " ${json_string}" |
| 98 | ] |
David Shaw | 2720764 | 2021-10-11 16:21:11 -0500 | [diff] [blame] | 99 | |
| 100 | if REDFISH_SUPPORT_TRANS_STATE: |
| 101 | keyword_string = ' ; '.join(keyword_redfish_strings) |
| 102 | else: |
| 103 | keyword_string = ' ; '.join(keyword_strings) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 104 | |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 105 | set_mod_global(keyword_string) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 106 | cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, |
Michael Shepos | d54307f | 2021-01-11 11:08:21 -0600 | [diff] [blame] | 107 | REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD, |
| 108 | keyword_string, lib_file_path, quiet, |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 109 | test_mode, debug, outputdir, output, log, report) |
| 110 | if not robot_cmd_fnc(cmd_buf): |
| 111 | exit(1) |
| 112 | # The output contains the num_error_logs value which we will isolate with egrep. |
| 113 | rc, out_buf = shell_cmd("egrep '^num_error_logs:[ ]' " + AUTOSCRIPT_STATUS_FILE_PATH, quiet=1, |
| 114 | print_output=0) |
| 115 | result = key_value_outbuf_to_dict(out_buf) |
| 116 | num_error_logs = int(result['num_error_logs']) |
| 117 | save_plug_in_value(num_error_logs) |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 118 | if num_error_logs > 0: |
David Shaw | dd62f97 | 2021-11-12 15:22:02 -0600 | [diff] [blame] | 119 | qprint_timen("Adding the name of our high severity error logs FFDC file to the appropriate file list.") |
michael | d4fbcf9 | 2020-06-19 17:30:00 -0500 | [diff] [blame] | 120 | shell_cmd("echo " + high_sev_elogs_file_path + " > " + AUTOBOOT_FFDC_LIST_FILE_PATH) |
| 121 | else: |
| 122 | os.remove(high_sev_elogs_file_path) |
Michael Walsh | 369b75c | 2020-05-05 14:00:53 -0500 | [diff] [blame] | 123 | |
| 124 | |
| 125 | main() |