blob: f3d43f9f0eec8003362e3ec35ca7354e726c6dc3 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh769c2a12016-12-13 15:45:17 -06002
3r"""
4This module is the python counterpart to openbmc_ffdc.robot..
5"""
6
7import os
8
Michael Walshe4a093d2017-10-30 15:03:18 -05009import gen_print as gp
George Keishinge635ddc2022-12-08 07:38:02 -060010import gen_robot_keyword as grk
Patrick Williams20f38712022-12-08 06:18:26 -060011import gen_valid as gv
Michael Walshe4a093d2017-10-30 15:03:18 -050012import state as st
Michael Walsh769c2a12016-12-13 15:45:17 -060013from robot.libraries.BuiltIn import BuiltIn
14
Patrick Williams20f38712022-12-08 06:18:26 -060015redfish_support_trans_state = int(
16 os.environ.get("REDFISH_SUPPORT_TRANS_STATE", 0)
17) or int(
18 BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0)
19)
Michael Shepose1775172021-02-11 16:59:08 -060020
Michael Walsh769c2a12016-12-13 15:45:17 -060021
Patrick Williams20f38712022-12-08 06:18:26 -060022def ffdc(
23 ffdc_dir_path=None,
24 ffdc_prefix=None,
25 ffdc_function_list="",
26 comm_check=True,
27):
Michael Walsh769c2a12016-12-13 15:45:17 -060028 r"""
29 Gather First Failure Data Capture (FFDC).
30
31 This includes:
32 - Set global FFDC_TIME.
33 - Create FFDC work space directory.
34 - Write test info details.
35 - Call BMC methods to write/collect FFDC data.
36
37 Description of arguments:
Michael Walshda8b3942020-03-23 10:39:52 -050038 ffdc_dir_path The dir path where FFDC data should be put.
39 ffdc_prefix The prefix to be given to each FFDC file name generated.
40 ffdc_function_list A colon-delimited list of all the types of FFDC data you wish to have
41 collected. A blank value means that all possible kinds of FFDC are to be
42 collected. See FFDC_METHOD_CALL object in lib/openbmc_ffdc_list.py for
43 possible choices.
44 comm_check Do a communications check prior to collecting FFDC. If commincation to
45 the BMC can't be established, abort the FFDC collection.
Michael Walsh769c2a12016-12-13 15:45:17 -060046 """
47
Michael Walshe4a093d2017-10-30 15:03:18 -050048 ffdc_file_list = []
49
George Keishing3f7f12c2017-03-02 06:14:41 -060050 # Check if Ping and SSH connection is alive
51 OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}")
George Keishing3f7f12c2017-03-02 06:14:41 -060052
Michael Walshda8b3942020-03-23 10:39:52 -050053 if comm_check:
Michael Shepose1775172021-02-11 16:59:08 -060054 if not redfish_support_trans_state:
Patrick Williams20f38712022-12-08 06:18:26 -060055 interface = "rest"
Michael Shepose1775172021-02-11 16:59:08 -060056 else:
Patrick Williams20f38712022-12-08 06:18:26 -060057 interface = "redfish"
Michael Shepose1775172021-02-11 16:59:08 -060058
Patrick Williams20f38712022-12-08 06:18:26 -060059 state = st.get_state(req_states=["ping", "uptime", interface])
Michael Walshda8b3942020-03-23 10:39:52 -050060 gp.qprint_var(state)
Patrick Williams20f38712022-12-08 06:18:26 -060061 if not int(state["ping"]):
62 gp.print_error(
63 "BMC is not ping-able. Terminating FFDC collection.\n"
64 )
Michael Walshda8b3942020-03-23 10:39:52 -050065 return ffdc_file_list
Michael Walshe4a093d2017-10-30 15:03:18 -050066
Michael Shepose1775172021-02-11 16:59:08 -060067 if not int(state[interface]):
George Keishingb1b6f132022-02-15 01:30:29 -060068 gp.print_error("%s commands to the BMC are failing." % interface)
Michael Walsh2bfc48e2018-10-24 15:23:17 -050069
Patrick Williams20f38712022-12-08 06:18:26 -060070 if state["uptime"] == "":
George Keishingb1b6f132022-02-15 01:30:29 -060071 gp.print_error("BMC is not communicating via ssh.\n")
72
73 # If SSH and Redfish connection doesn't works, abort.
Patrick Williams20f38712022-12-08 06:18:26 -060074 if not int(state[interface]) and state["uptime"] == "":
75 gp.print_error(
76 "BMC is not communicating via ssh or Redfish. Terminating"
George Keishing7899a452023-02-15 02:46:54 -060077 " FFDC" + " collection.\n"
Patrick Williams20f38712022-12-08 06:18:26 -060078 )
Michael Walshda8b3942020-03-23 10:39:52 -050079 return ffdc_file_list
Michael Walshe4a093d2017-10-30 15:03:18 -050080
81 gp.qprint_timen("Collecting FFDC.")
Michael Walsh769c2a12016-12-13 15:45:17 -060082
Michael Walsh769c2a12016-12-13 15:45:17 -060083 # Get default values for arguments.
84 ffdc_dir_path, ffdc_prefix = set_ffdc_defaults(ffdc_dir_path, ffdc_prefix)
Michael Walshe4a093d2017-10-30 15:03:18 -050085 gp.qprint_var(ffdc_dir_path)
86 gp.qprint_var(ffdc_prefix)
Michael Walsh769c2a12016-12-13 15:45:17 -060087
88 # LOG_PREFIX is used by subordinate functions.
89 LOG_PREFIX = ffdc_dir_path + ffdc_prefix
90 BuiltIn().set_global_variable("${LOG_PREFIX}", LOG_PREFIX)
91
92 cmd_buf = ["Create Directory", ffdc_dir_path]
Michael Walshedb5c942019-03-28 12:40:50 -050093 gp.qprint_issuing(cmd_buf)
Michael Walsh769c2a12016-12-13 15:45:17 -060094 status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
95 if status != "PASS":
Patrick Williams20f38712022-12-08 06:18:26 -060096 error_message = gp.sprint_error_report(
97 "Create Directory failed"
98 + " with the following"
99 + " error:\n"
100 + output
101 )
Michael Walsh769c2a12016-12-13 15:45:17 -0600102 BuiltIn().fail(error_message)
103
104 # FFDC_FILE_PATH is used by Header Message.
105 FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt"
106 BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH)
107
Michael Walshfdde2582019-04-18 11:05:11 -0500108 status, ffdc_file_list = grk.run_key_u("Header Message")
Patrick Williams20f38712022-12-08 06:18:26 -0600109 status, ffdc_file_sub_list = grk.run_key_u(
110 "Call FFDC Methods ffdc_function_list=" + ffdc_function_list
111 )
Michael Walsh769c2a12016-12-13 15:45:17 -0600112
Michael Walshe4a093d2017-10-30 15:03:18 -0500113 # Combine lists, remove duplicates and sort.
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -0500114 ffdc_file_list = sorted(set(ffdc_file_list + ffdc_file_sub_list))
Michael Walsh769c2a12016-12-13 15:45:17 -0600115
Michael Walshe4a093d2017-10-30 15:03:18 -0500116 gp.qprint_timen("Finished collecting FFDC.")
117
118 return ffdc_file_list
Michael Walsh769c2a12016-12-13 15:45:17 -0600119
Michael Walsh769c2a12016-12-13 15:45:17 -0600120
Patrick Williams20f38712022-12-08 06:18:26 -0600121def set_ffdc_defaults(ffdc_dir_path=None, ffdc_prefix=None):
Michael Walsh769c2a12016-12-13 15:45:17 -0600122 r"""
123 Set a default value for ffdc_dir_path and ffdc_prefix if they don't
124 already have values. Return both values.
125
126 Description of arguments:
127 ffdc_dir_path The dir path where FFDC data should be put.
128 ffdc_prefix The prefix to be given to each FFDC file name generated.
129
130 NOTE: If global variable ffdc_dir_path_style is set to ${1}, this function
131 will create default values in a newer way. Otherwise, its behavior
132 will remain unchanged.
133 """
134
Michael Walshfa9f70f2017-04-21 16:00:18 -0500135 # Note: Several subordinate functions like 'Get Test Dir and Name' and
136 # 'Header Message' expect global variable FFDC_TIME to be set.
137 cmd_buf = ["Get Current Time Stamp"]
Michael Walshedb5c942019-03-28 12:40:50 -0500138 gp.dprint_issuing(cmd_buf)
Michael Walshfa9f70f2017-04-21 16:00:18 -0500139 FFDC_TIME = BuiltIn().run_keyword(*cmd_buf)
140 BuiltIn().set_global_variable("${FFDC_TIME}", FFDC_TIME)
141
Michael Walsha0364ae2017-01-10 11:24:42 -0600142 ffdc_dir_path_style = BuiltIn().get_variable_value(
Patrick Williams20f38712022-12-08 06:18:26 -0600143 "${ffdc_dir_path_style}"
144 )
Michael Walsh769c2a12016-12-13 15:45:17 -0600145
146 if ffdc_dir_path is None:
147 if ffdc_dir_path_style:
148 try:
Patrick Williams20f38712022-12-08 06:18:26 -0600149 ffdc_dir_path = os.environ["FFDC_DIR_PATH"]
Michael Walsh769c2a12016-12-13 15:45:17 -0600150 except KeyError:
Patrick Williams20f38712022-12-08 06:18:26 -0600151 ffdc_dir_path = (
152 os.path.dirname(
153 BuiltIn().get_variable_value("${LOG_FILE}")
154 )
155 + "/"
156 )
Michael Walsh769c2a12016-12-13 15:45:17 -0600157 else:
George Keishing58a13f52017-06-21 14:04:42 -0500158 FFDC_LOG_PATH = os.getcwd() + "/logs/"
Michael Walsh769c2a12016-12-13 15:45:17 -0600159 if FFDC_LOG_PATH is None:
160 FFDC_LOG_PATH = ""
161 if FFDC_LOG_PATH == "":
Patrick Williams20f38712022-12-08 06:18:26 -0600162 FFDC_LOG_PATH = (
163 os.path.dirname(
164 BuiltIn().get_variable_value("${LOG_FILE}")
165 )
166 + "/"
167 )
168 error_message = gv.valid_value(
169 FFDC_LOG_PATH, var_name="FFDC_LOG_PATH"
170 )
Michael Walsh769c2a12016-12-13 15:45:17 -0600171 if error_message != "":
Michael Walshedb5c942019-03-28 12:40:50 -0500172 error_message = gp.sprint_error_report(error_message)
Michael Walsh769c2a12016-12-13 15:45:17 -0600173 BuiltIn().fail(error_message)
174 FFDC_LOG_PATH = os.path.normpath(FFDC_LOG_PATH) + os.sep
175
176 cmd_buf = ["Get Test Dir and Name"]
Michael Walshedb5c942019-03-28 12:40:50 -0500177 gp.print_issuing(cmd_buf)
Michael Walsh769c2a12016-12-13 15:45:17 -0600178 suitename, testname = BuiltIn().run_keyword(*cmd_buf)
179
180 ffdc_dir_path = FFDC_LOG_PATH + suitename + "/" + testname + "/"
181
182 # Add trailing slash.
183 ffdc_dir_path = os.path.normpath(ffdc_dir_path) + os.sep
184
185 if ffdc_prefix is None:
186 FFDC_TIME = BuiltIn().get_variable_value("${FFDC_TIME}")
187 if ffdc_prefix is None:
188 if ffdc_dir_path_style:
189 OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}")
Michael Walsha0364ae2017-01-10 11:24:42 -0600190 OPENBMC_NICKNAME = BuiltIn().get_variable_value(
Patrick Williams20f38712022-12-08 06:18:26 -0600191 "${OPENBMC_NICKNAME}", default=OPENBMC_HOST
192 )
193 ffdc_prefix = (
194 OPENBMC_NICKNAME
195 + "."
196 + FFDC_TIME[2:8]
197 + "."
198 + FFDC_TIME[8:14]
199 + "."
200 )
Michael Walsh769c2a12016-12-13 15:45:17 -0600201 else:
202 ffdc_prefix = FFDC_TIME + "_"
203
Michael Walshfa9f70f2017-04-21 16:00:18 -0500204 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
205 BuiltIn().set_global_variable("${FFDC_PREFIX}", ffdc_prefix)
206
Michael Walsh769c2a12016-12-13 15:45:17 -0600207 return ffdc_dir_path, ffdc_prefix