blob: 59ecf5d0bf308bfc5bba89b6faf2f92b88090dd2 [file] [log] [blame]
Michael Walsh769c2a12016-12-13 15:45:17 -06001#!/usr/bin/env python
2
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
Michael Walsh769c2a12016-12-13 15:45:17 -060010import gen_robot_print as grp
11import gen_valid as gv
Michael Walshe844e9a2017-04-20 16:51:10 -050012import gen_robot_keyword as grk
Michael Walshe4a093d2017-10-30 15:03:18 -050013import state as st
Michael Walsh769c2a12016-12-13 15:45:17 -060014
15from robot.libraries.BuiltIn import BuiltIn
16
17
Michael Walsh769c2a12016-12-13 15:45:17 -060018def ffdc(ffdc_dir_path=None,
Michael Walshe844e9a2017-04-20 16:51:10 -050019 ffdc_prefix=None,
20 ffdc_function_list=""):
Michael Walsh769c2a12016-12-13 15:45:17 -060021 r"""
22 Gather First Failure Data Capture (FFDC).
23
24 This includes:
25 - Set global FFDC_TIME.
26 - Create FFDC work space directory.
27 - Write test info details.
28 - Call BMC methods to write/collect FFDC data.
29
30 Description of arguments:
Michael Walshe844e9a2017-04-20 16:51:10 -050031 ffdc_dir_path The dir path where FFDC data should be put.
32 ffdc_prefix The prefix to be given to each FFDC file name
33 generated.
34 ffdc_function_list A colon-delimited list of all the types of FFDC data
35 you wish to have collected. A blank value means that
36 all possible kinds of FFDC are to be collected. See
37 FFDC_METHOD_CALL object in lib/openbmc_ffdc_list.py
38 for possible choices.
Michael Walsh769c2a12016-12-13 15:45:17 -060039 """
40
Michael Walshe4a093d2017-10-30 15:03:18 -050041 ffdc_file_list = []
42
George Keishing3f7f12c2017-03-02 06:14:41 -060043 # Check if Ping and SSH connection is alive
44 OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}")
George Keishing3f7f12c2017-03-02 06:14:41 -060045
Michael Walsh2bfc48e2018-10-24 15:23:17 -050046 state = st.get_state(req_states=['ping', 'uptime', 'rest'])
Michael Walshe4a093d2017-10-30 15:03:18 -050047 gp.qprint_var(state)
48 if not int(state['ping']):
49 gp.print_error("BMC is not ping-able. Terminating FFDC collection.\n")
50 return ffdc_file_list
51
Michael Walsh2bfc48e2018-10-24 15:23:17 -050052 if not int(state['rest']):
53 gp.print_error("REST commands to the BMC are failing."
54 + " Terminating FFDC collection.\n")
55 return ffdc_file_list
56
Michael Walshe4a093d2017-10-30 15:03:18 -050057 if state['uptime'] == "":
Michael Walsh2bfc48e2018-10-24 15:23:17 -050058 gp.print_error("BMC is not communicating via ssh. Terminating FFDC"
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050059 + " collection.\n")
Michael Walshe4a093d2017-10-30 15:03:18 -050060 return ffdc_file_list
61
62 gp.qprint_timen("Collecting FFDC.")
Michael Walsh769c2a12016-12-13 15:45:17 -060063
Michael Walsh769c2a12016-12-13 15:45:17 -060064 # Get default values for arguments.
65 ffdc_dir_path, ffdc_prefix = set_ffdc_defaults(ffdc_dir_path, ffdc_prefix)
Michael Walshe4a093d2017-10-30 15:03:18 -050066 gp.qprint_var(ffdc_dir_path)
67 gp.qprint_var(ffdc_prefix)
Michael Walsh769c2a12016-12-13 15:45:17 -060068
69 # LOG_PREFIX is used by subordinate functions.
70 LOG_PREFIX = ffdc_dir_path + ffdc_prefix
71 BuiltIn().set_global_variable("${LOG_PREFIX}", LOG_PREFIX)
72
73 cmd_buf = ["Create Directory", ffdc_dir_path]
Michael Walshe4a093d2017-10-30 15:03:18 -050074 grp.rqpissuing_keyword(cmd_buf)
Michael Walsh769c2a12016-12-13 15:45:17 -060075 status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
76 if status != "PASS":
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050077 error_message = grp.sprint_error_report("Create Directory failed"
78 + " with the following"
79 + " error:\n" + output)
Michael Walsh769c2a12016-12-13 15:45:17 -060080 BuiltIn().fail(error_message)
81
82 # FFDC_FILE_PATH is used by Header Message.
83 FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt"
84 BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH)
85
Michael Walshe4a093d2017-10-30 15:03:18 -050086 status, ffdc_file_list = grk.run_key("Header Message")
87 status, ffdc_file_sub_list = \
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050088 grk.run_key_u("Call FFDC Methods ffdc_function_list="
89 + ffdc_function_list)
Michael Walsh769c2a12016-12-13 15:45:17 -060090
Michael Walshe4a093d2017-10-30 15:03:18 -050091 # Combine lists, remove duplicates and sort.
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050092 ffdc_file_list = sorted(set(ffdc_file_list + ffdc_file_sub_list))
Michael Walsh769c2a12016-12-13 15:45:17 -060093
Michael Walshe4a093d2017-10-30 15:03:18 -050094 gp.qprint_timen("Finished collecting FFDC.")
95
96 return ffdc_file_list
Michael Walsh769c2a12016-12-13 15:45:17 -060097
Michael Walsh769c2a12016-12-13 15:45:17 -060098
Michael Walsh769c2a12016-12-13 15:45:17 -060099def set_ffdc_defaults(ffdc_dir_path=None,
100 ffdc_prefix=None):
Michael Walsh769c2a12016-12-13 15:45:17 -0600101 r"""
102 Set a default value for ffdc_dir_path and ffdc_prefix if they don't
103 already have values. Return both values.
104
105 Description of arguments:
106 ffdc_dir_path The dir path where FFDC data should be put.
107 ffdc_prefix The prefix to be given to each FFDC file name generated.
108
109 NOTE: If global variable ffdc_dir_path_style is set to ${1}, this function
110 will create default values in a newer way. Otherwise, its behavior
111 will remain unchanged.
112 """
113
Michael Walshfa9f70f2017-04-21 16:00:18 -0500114 # Note: Several subordinate functions like 'Get Test Dir and Name' and
115 # 'Header Message' expect global variable FFDC_TIME to be set.
116 cmd_buf = ["Get Current Time Stamp"]
117 grp.rdpissuing_keyword(cmd_buf)
118 FFDC_TIME = BuiltIn().run_keyword(*cmd_buf)
119 BuiltIn().set_global_variable("${FFDC_TIME}", FFDC_TIME)
120
Michael Walsha0364ae2017-01-10 11:24:42 -0600121 ffdc_dir_path_style = BuiltIn().get_variable_value(
122 "${ffdc_dir_path_style}")
Michael Walsh769c2a12016-12-13 15:45:17 -0600123
124 if ffdc_dir_path is None:
125 if ffdc_dir_path_style:
126 try:
127 ffdc_dir_path = os.environ['FFDC_DIR_PATH']
128 except KeyError:
129 ffdc_dir_path = os.path.dirname(
130 BuiltIn().get_variable_value("${LOG_FILE}")) + "/"
131 else:
George Keishing58a13f52017-06-21 14:04:42 -0500132 FFDC_LOG_PATH = os.getcwd() + "/logs/"
Michael Walsh769c2a12016-12-13 15:45:17 -0600133 if FFDC_LOG_PATH is None:
134 FFDC_LOG_PATH = ""
135 if FFDC_LOG_PATH == "":
136 FFDC_LOG_PATH = os.path.dirname(
137 BuiltIn().get_variable_value("${LOG_FILE}")) + "/"
138 error_message = gv.svalid_value(FFDC_LOG_PATH,
139 var_name="FFDC_LOG_PATH")
140 if error_message != "":
141 error_message = grp.sprint_error_report(error_message)
142 BuiltIn().fail(error_message)
143 FFDC_LOG_PATH = os.path.normpath(FFDC_LOG_PATH) + os.sep
144
145 cmd_buf = ["Get Test Dir and Name"]
146 grp.rpissuing_keyword(cmd_buf)
147 suitename, testname = BuiltIn().run_keyword(*cmd_buf)
148
149 ffdc_dir_path = FFDC_LOG_PATH + suitename + "/" + testname + "/"
150
151 # Add trailing slash.
152 ffdc_dir_path = os.path.normpath(ffdc_dir_path) + os.sep
153
154 if ffdc_prefix is None:
155 FFDC_TIME = BuiltIn().get_variable_value("${FFDC_TIME}")
156 if ffdc_prefix is None:
157 if ffdc_dir_path_style:
158 OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}")
Michael Walsha0364ae2017-01-10 11:24:42 -0600159 OPENBMC_NICKNAME = BuiltIn().get_variable_value(
160 "${OPENBMC_NICKNAME}", default=OPENBMC_HOST)
161 ffdc_prefix = OPENBMC_NICKNAME + "." + FFDC_TIME[2:8] + "." +\
Michael Walsh769c2a12016-12-13 15:45:17 -0600162 FFDC_TIME[8:14] + "."
163 else:
164 ffdc_prefix = FFDC_TIME + "_"
165
Michael Walshfa9f70f2017-04-21 16:00:18 -0500166 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
167 BuiltIn().set_global_variable("${FFDC_PREFIX}", ffdc_prefix)
168
Michael Walsh769c2a12016-12-13 15:45:17 -0600169 return ffdc_dir_path, ffdc_prefix