blob: 649fd310cca9776326fec59f04d19fac60c078fc [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh369b75c2020-05-05 14:00:53 -05002
Patrick Williams20f38712022-12-08 06:18:26 -06003from gen_arg import *
4from gen_call_robot import *
5from gen_cmd import *
6from gen_misc import *
7from gen_plug_in_utils import *
Michael Walsh369b75c2020-05-05 14:00:53 -05008from gen_print import *
9from gen_valid import *
Michael Walsh369b75c2020-05-05 14:00:53 -050010from var_funcs import *
Michael Walsh369b75c2020-05-05 14:00:53 -050011
12# Set exit_on_error for gen_valid functions.
13set_exit_on_error(True)
14ignore_err = 0
15
16
17parser = argparse.ArgumentParser(
Patrick Williams20f38712022-12-08 06:18:26 -060018 usage="%(prog)s [OPTIONS]",
Michael Walsh369b75c2020-05-05 14:00:53 -050019 description="%(prog)s will calculate the value of num_err_logs and"
Patrick Williamsa57fef42022-12-03 07:00:14 -060020 + " 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 Walsh369b75c2020-05-05 14:00:53 -050023 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Patrick Williams20f38712022-12-08 06:18:26 -060024 prefix_chars="-+",
25)
Michael Walsh369b75c2020-05-05 14:00:53 -050026
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 Williams20f38712022-12-08 06:18:26 -060029stock_list = [
30 ("test_mode", 0),
31 ("quiet", get_plug_default("quiet", 0)),
32 ("debug", get_plug_default("debug", 0)),
33]
Michael Walsh369b75c2020-05-05 14:00:53 -050034
35
Patrick Williams20f38712022-12-08 06:18:26 -060036def exit_function(signal_number=0, frame=None):
Michael Walsh369b75c2020-05-05 14:00:53 -050037 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
46def 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 Williams20f38712022-12-08 06:18:26 -060058 AUTOSCRIPT_STATUS_FILE_PATH = os.environ.get(
59 "AUTOSCRIPT_STATUS_FILE_PATH", ""
60 )
Michael Walsh369b75c2020-05-05 14:00:53 -050061 valid_value(AUTOSCRIPT_STATUS_FILE_PATH)
62 valid_value(AUTOBOOT_OPENBMC_HOST)
63
64
65def main():
Michael Walsh369b75c2020-05-05 14:00:53 -050066 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 Williams20f38712022-12-08 06:18:26 -060072 high_sev_elogs_file_path = (
73 AUTOBOOT_FFDC_DIR_PATH
74 + AUTOBOOT_FFDC_PREFIX
75 + "high_severity_errorlog.json"
76 )
Michael Walsh369b75c2020-05-05 14:00:53 -050077 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 Williams20f38712022-12-08 06:18:26 -060081 REDFISH_SUPPORT_TRANS_STATE = int(
82 os.environ.get("REDFISH_SUPPORT_TRANS_STATE", 0)
83 )
David Shaw27207642021-10-11 16:21:11 -050084 if not REDFISH_SUPPORT_TRANS_STATE:
85 try:
86 from robot.libraries.BuiltIn import BuiltIn
Patrick Williams20f38712022-12-08 06:18:26 -060087
88 REDFISH_SUPPORT_TRANS_STATE = int(
89 BuiltIn().get_variable_value(
90 "${REDFISH_SUPPORT_TRANS_STATE}", default=0
91 )
92 )
Patrick Williamsa57fef42022-12-03 07:00:14 -060093 except Exception:
David Shaw27207642021-10-11 16:21:11 -050094 pass
95
Patrick Williams20f38712022-12-08 06:18:26 -060096 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 Shaw27207642021-10-11 16:21:11 -0500109
Patrick Williams20f38712022-12-08 06:18:26 -0600110 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 Williamsa57fef42022-12-03 07:00:14 -0600120
David Shaw27207642021-10-11 16:21:11 -0500121 if REDFISH_SUPPORT_TRANS_STATE:
Patrick Williams20f38712022-12-08 06:18:26 -0600122 keyword_string = " ; ".join(keyword_redfish_strings)
David Shaw27207642021-10-11 16:21:11 -0500123 else:
Patrick Williams20f38712022-12-08 06:18:26 -0600124 keyword_string = " ; ".join(keyword_strings)
Michael Walsh369b75c2020-05-05 14:00:53 -0500125
michaeld4fbcf92020-06-19 17:30:00 -0500126 set_mod_global(keyword_string)
Patrick Williams20f38712022-12-08 06:18:26 -0600127 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 Walsh369b75c2020-05-05 14:00:53 -0500146 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 Williams20f38712022-12-08 06:18:26 -0600149 rc, out_buf = shell_cmd(
150 "egrep '^num_error_logs:[ ]' " + AUTOSCRIPT_STATUS_FILE_PATH,
151 quiet=1,
152 print_output=0,
153 )
Michael Walsh369b75c2020-05-05 14:00:53 -0500154 result = key_value_outbuf_to_dict(out_buf)
Patrick Williams20f38712022-12-08 06:18:26 -0600155 num_error_logs = int(result["num_error_logs"])
Michael Walsh369b75c2020-05-05 14:00:53 -0500156 save_plug_in_value(num_error_logs)
michaeld4fbcf92020-06-19 17:30:00 -0500157 if num_error_logs > 0:
Patrick Williams20f38712022-12-08 06:18:26 -0600158 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 )
michaeld4fbcf92020-06-19 17:30:00 -0500168 else:
169 os.remove(high_sev_elogs_file_path)
Michael Walsh369b75c2020-05-05 14:00:53 -0500170
171
172main()