Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | This module is the python counterpart to openbmc_ffdc.robot.. |
| 5 | """ |
| 6 | |
| 7 | import os |
| 8 | |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 9 | import gen_print as gp |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 10 | import gen_valid as gv |
Michael Walsh | e844e9a | 2017-04-20 16:51:10 -0500 | [diff] [blame] | 11 | import gen_robot_keyword as grk |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 12 | import state as st |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 13 | |
| 14 | from robot.libraries.BuiltIn import BuiltIn |
| 15 | |
| 16 | |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 17 | def ffdc(ffdc_dir_path=None, |
Michael Walsh | e844e9a | 2017-04-20 16:51:10 -0500 | [diff] [blame] | 18 | ffdc_prefix=None, |
| 19 | ffdc_function_list=""): |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 20 | r""" |
| 21 | Gather First Failure Data Capture (FFDC). |
| 22 | |
| 23 | This includes: |
| 24 | - Set global FFDC_TIME. |
| 25 | - Create FFDC work space directory. |
| 26 | - Write test info details. |
| 27 | - Call BMC methods to write/collect FFDC data. |
| 28 | |
| 29 | Description of arguments: |
Michael Walsh | e844e9a | 2017-04-20 16:51:10 -0500 | [diff] [blame] | 30 | ffdc_dir_path The dir path where FFDC data should be put. |
| 31 | ffdc_prefix The prefix to be given to each FFDC file name |
| 32 | generated. |
| 33 | ffdc_function_list A colon-delimited list of all the types of FFDC data |
| 34 | you wish to have collected. A blank value means that |
| 35 | all possible kinds of FFDC are to be collected. See |
| 36 | FFDC_METHOD_CALL object in lib/openbmc_ffdc_list.py |
| 37 | for possible choices. |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 38 | """ |
| 39 | |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 40 | ffdc_file_list = [] |
| 41 | |
George Keishing | 3f7f12c | 2017-03-02 06:14:41 -0600 | [diff] [blame] | 42 | # Check if Ping and SSH connection is alive |
| 43 | OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}") |
George Keishing | 3f7f12c | 2017-03-02 06:14:41 -0600 | [diff] [blame] | 44 | |
Michael Walsh | 2bfc48e | 2018-10-24 15:23:17 -0500 | [diff] [blame] | 45 | state = st.get_state(req_states=['ping', 'uptime', 'rest']) |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 46 | gp.qprint_var(state) |
| 47 | if not int(state['ping']): |
| 48 | gp.print_error("BMC is not ping-able. Terminating FFDC collection.\n") |
| 49 | return ffdc_file_list |
| 50 | |
Michael Walsh | 2bfc48e | 2018-10-24 15:23:17 -0500 | [diff] [blame] | 51 | if not int(state['rest']): |
| 52 | gp.print_error("REST commands to the BMC are failing." |
| 53 | + " Terminating FFDC collection.\n") |
| 54 | return ffdc_file_list |
| 55 | |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 56 | if state['uptime'] == "": |
Michael Walsh | 2bfc48e | 2018-10-24 15:23:17 -0500 | [diff] [blame] | 57 | gp.print_error("BMC is not communicating via ssh. Terminating FFDC" |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 58 | + " collection.\n") |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 59 | return ffdc_file_list |
| 60 | |
| 61 | gp.qprint_timen("Collecting FFDC.") |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 62 | |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 63 | # Get default values for arguments. |
| 64 | ffdc_dir_path, ffdc_prefix = set_ffdc_defaults(ffdc_dir_path, ffdc_prefix) |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 65 | gp.qprint_var(ffdc_dir_path) |
| 66 | gp.qprint_var(ffdc_prefix) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 67 | |
| 68 | # LOG_PREFIX is used by subordinate functions. |
| 69 | LOG_PREFIX = ffdc_dir_path + ffdc_prefix |
| 70 | BuiltIn().set_global_variable("${LOG_PREFIX}", LOG_PREFIX) |
| 71 | |
| 72 | cmd_buf = ["Create Directory", ffdc_dir_path] |
Michael Walsh | edb5c94 | 2019-03-28 12:40:50 -0500 | [diff] [blame] | 73 | gp.qprint_issuing(cmd_buf) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 74 | status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) |
| 75 | if status != "PASS": |
Michael Walsh | edb5c94 | 2019-03-28 12:40:50 -0500 | [diff] [blame] | 76 | error_message = gp.sprint_error_report("Create Directory failed" |
| 77 | + " with the following" |
| 78 | + " error:\n" + output) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 79 | BuiltIn().fail(error_message) |
| 80 | |
| 81 | # FFDC_FILE_PATH is used by Header Message. |
| 82 | FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt" |
| 83 | BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH) |
| 84 | |
Michael Walsh | fdde258 | 2019-04-18 11:05:11 -0500 | [diff] [blame] | 85 | status, ffdc_file_list = grk.run_key_u("Header Message") |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 86 | status, ffdc_file_sub_list = \ |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 87 | grk.run_key_u("Call FFDC Methods ffdc_function_list=" |
| 88 | + ffdc_function_list) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 89 | |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 90 | # Combine lists, remove duplicates and sort. |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 91 | ffdc_file_list = sorted(set(ffdc_file_list + ffdc_file_sub_list)) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 92 | |
Michael Walsh | e4a093d | 2017-10-30 15:03:18 -0500 | [diff] [blame] | 93 | gp.qprint_timen("Finished collecting FFDC.") |
| 94 | |
| 95 | return ffdc_file_list |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 96 | |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 97 | |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 98 | def set_ffdc_defaults(ffdc_dir_path=None, |
| 99 | ffdc_prefix=None): |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 100 | r""" |
| 101 | Set a default value for ffdc_dir_path and ffdc_prefix if they don't |
| 102 | already have values. Return both values. |
| 103 | |
| 104 | Description of arguments: |
| 105 | ffdc_dir_path The dir path where FFDC data should be put. |
| 106 | ffdc_prefix The prefix to be given to each FFDC file name generated. |
| 107 | |
| 108 | NOTE: If global variable ffdc_dir_path_style is set to ${1}, this function |
| 109 | will create default values in a newer way. Otherwise, its behavior |
| 110 | will remain unchanged. |
| 111 | """ |
| 112 | |
Michael Walsh | fa9f70f | 2017-04-21 16:00:18 -0500 | [diff] [blame] | 113 | # Note: Several subordinate functions like 'Get Test Dir and Name' and |
| 114 | # 'Header Message' expect global variable FFDC_TIME to be set. |
| 115 | cmd_buf = ["Get Current Time Stamp"] |
Michael Walsh | edb5c94 | 2019-03-28 12:40:50 -0500 | [diff] [blame] | 116 | gp.dprint_issuing(cmd_buf) |
Michael Walsh | fa9f70f | 2017-04-21 16:00:18 -0500 | [diff] [blame] | 117 | FFDC_TIME = BuiltIn().run_keyword(*cmd_buf) |
| 118 | BuiltIn().set_global_variable("${FFDC_TIME}", FFDC_TIME) |
| 119 | |
Michael Walsh | a0364ae | 2017-01-10 11:24:42 -0600 | [diff] [blame] | 120 | ffdc_dir_path_style = BuiltIn().get_variable_value( |
| 121 | "${ffdc_dir_path_style}") |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 122 | |
| 123 | if ffdc_dir_path is None: |
| 124 | if ffdc_dir_path_style: |
| 125 | try: |
| 126 | ffdc_dir_path = os.environ['FFDC_DIR_PATH'] |
| 127 | except KeyError: |
| 128 | ffdc_dir_path = os.path.dirname( |
| 129 | BuiltIn().get_variable_value("${LOG_FILE}")) + "/" |
| 130 | else: |
George Keishing | 58a13f5 | 2017-06-21 14:04:42 -0500 | [diff] [blame] | 131 | FFDC_LOG_PATH = os.getcwd() + "/logs/" |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 132 | if FFDC_LOG_PATH is None: |
| 133 | FFDC_LOG_PATH = "" |
| 134 | if FFDC_LOG_PATH == "": |
| 135 | FFDC_LOG_PATH = os.path.dirname( |
| 136 | BuiltIn().get_variable_value("${LOG_FILE}")) + "/" |
| 137 | error_message = gv.svalid_value(FFDC_LOG_PATH, |
| 138 | var_name="FFDC_LOG_PATH") |
| 139 | if error_message != "": |
Michael Walsh | edb5c94 | 2019-03-28 12:40:50 -0500 | [diff] [blame] | 140 | error_message = gp.sprint_error_report(error_message) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 141 | BuiltIn().fail(error_message) |
| 142 | FFDC_LOG_PATH = os.path.normpath(FFDC_LOG_PATH) + os.sep |
| 143 | |
| 144 | cmd_buf = ["Get Test Dir and Name"] |
Michael Walsh | edb5c94 | 2019-03-28 12:40:50 -0500 | [diff] [blame] | 145 | gp.print_issuing(cmd_buf) |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 146 | suitename, testname = BuiltIn().run_keyword(*cmd_buf) |
| 147 | |
| 148 | ffdc_dir_path = FFDC_LOG_PATH + suitename + "/" + testname + "/" |
| 149 | |
| 150 | # Add trailing slash. |
| 151 | ffdc_dir_path = os.path.normpath(ffdc_dir_path) + os.sep |
| 152 | |
| 153 | if ffdc_prefix is None: |
| 154 | FFDC_TIME = BuiltIn().get_variable_value("${FFDC_TIME}") |
| 155 | if ffdc_prefix is None: |
| 156 | if ffdc_dir_path_style: |
| 157 | OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}") |
Michael Walsh | a0364ae | 2017-01-10 11:24:42 -0600 | [diff] [blame] | 158 | OPENBMC_NICKNAME = BuiltIn().get_variable_value( |
| 159 | "${OPENBMC_NICKNAME}", default=OPENBMC_HOST) |
| 160 | ffdc_prefix = OPENBMC_NICKNAME + "." + FFDC_TIME[2:8] + "." +\ |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 161 | FFDC_TIME[8:14] + "." |
| 162 | else: |
| 163 | ffdc_prefix = FFDC_TIME + "_" |
| 164 | |
Michael Walsh | fa9f70f | 2017-04-21 16:00:18 -0500 | [diff] [blame] | 165 | BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path) |
| 166 | BuiltIn().set_global_variable("${FFDC_PREFIX}", ffdc_prefix) |
| 167 | |
Michael Walsh | 769c2a1 | 2016-12-13 15:45:17 -0600 | [diff] [blame] | 168 | return ffdc_dir_path, ffdc_prefix |