blob: 7df0d51d11f9c8713122e35a83c81fcdc6f0fce5 [file] [log] [blame]
Michael Walsh0bbd8602016-11-22 11:31:49 -06001#!/usr/bin/env python
2
3r"""
4This module is the python counterpart to obmc_boot_test.
5"""
6
Michael Walsh0b93fbf2017-03-02 14:42:41 -06007import os
8import imp
9import time
10import glob
11import random
Michael Walsh0ad0f7f2017-05-04 14:39:58 -050012import re
Michael Walsh0b93fbf2017-03-02 14:42:41 -060013import cPickle as pickle
Michael Walshdc80d672017-05-09 12:58:32 -050014import socket
Michael Walsh0b93fbf2017-03-02 14:42:41 -060015
16from robot.utils import DotDict
17from robot.libraries.BuiltIn import BuiltIn
18
Michael Walsh6741f742017-02-20 16:16:38 -060019from boot_data import *
Michael Walshc9116812017-03-10 14:23:06 -060020import gen_print as gp
Michael Walsh0bbd8602016-11-22 11:31:49 -060021import gen_robot_print as grp
Michael Walsh55302292017-01-10 11:43:02 -060022import gen_robot_plug_in as grpi
Michael Walsh6741f742017-02-20 16:16:38 -060023import gen_robot_valid as grv
24import gen_misc as gm
25import gen_cmd as gc
Michael Walshb5839d02017-04-12 16:11:20 -050026import gen_robot_keyword as grk
Michael Walsh55302292017-01-10 11:43:02 -060027import state as st
Michael Walsh0bbd8602016-11-22 11:31:49 -060028
Michael Walsh0b93fbf2017-03-02 14:42:41 -060029base_path = os.path.dirname(os.path.dirname(
30 imp.find_module("gen_robot_print")[1])) +\
Michael Walshc9116812017-03-10 14:23:06 -060031 os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060032sys.path.append(base_path + "extended/")
33import run_keyword as rk
Michael Walsh0bbd8602016-11-22 11:31:49 -060034
Michael Walshe1e26442017-03-06 17:50:07 -060035# Setting master_pid correctly influences the behavior of plug-ins like
36# DB_Logging
37program_pid = os.getpid()
38master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid)
39
Michael Walshb5839d02017-04-12 16:11:20 -050040# Set up boot data structures.
41boot_table = create_boot_table()
42valid_boot_types = create_valid_boot_list(boot_table)
Michael Walsh0b93fbf2017-03-02 14:42:41 -060043
Michael Walsh6741f742017-02-20 16:16:38 -060044boot_lists = read_boot_lists()
45last_ten = []
Michael Walsh6741f742017-02-20 16:16:38 -060046
47state = st.return_default_state()
48cp_setup_called = 0
49next_boot = ""
50base_tool_dir_path = os.path.normpath(os.environ.get(
51 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep
Michael Walshb5839d02017-04-12 16:11:20 -050052
Michael Walsh6741f742017-02-20 16:16:38 -060053ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep
Michael Walsh6741f742017-02-20 16:16:38 -060054boot_success = 0
Michael Walsh6741f742017-02-20 16:16:38 -060055status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
56if status_dir_path != "":
57 status_dir_path = os.path.normpath(status_dir_path) + os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060058default_power_on = "REST Power On"
59default_power_off = "REST Power Off"
Michael Walsh6741f742017-02-20 16:16:38 -060060boot_count = 0
Michael Walsh0bbd8602016-11-22 11:31:49 -060061
Michael Walsh85678942017-03-27 14:34:22 -050062LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}")
63
64
65###############################################################################
Michael Walsh0ad0f7f2017-05-04 14:39:58 -050066def process_host(host,
67 host_var_name=""):
68
69 r"""
70 Process a host by getting the associated host name and IP address and
71 setting them in global variables.
72
73 If the caller does not pass the host_var_name, this function will try to
74 figure out the name of the variable used by the caller for the host parm.
75 Callers are advised to explicitly specify the host_var_name when calling
76 with an exec command. In such cases, the get_arg_name cannot figure out
77 the host variable name.
78
79 This function will then create similar global variable names by
80 removing "_host" and appending "_host_name" or "_ip" to the host variable
81 name.
82
83 Example:
84
85 If a call is made like this:
86 process_host(openbmc_host)
87
88 Global variables openbmc_host_name and openbmc_ip will be set.
89
90 Description of argument(s):
91 host A host name or IP. The name of the variable used should
92 have a suffix of "_host".
93 host_var_name The name of the variable being used as the host parm.
94 """
95
96 if host_var_name == "":
97 host_var_name = gp.get_arg_name(0, 1, stack_frame_ix=2)
98
99 host_name_var_name = re.sub("host", "host_name", host_var_name)
100 ip_var_name = re.sub("host", "ip", host_var_name)
101 cmd_buf = "global " + host_name_var_name + ", " + ip_var_name + " ; " +\
102 host_name_var_name + ", " + ip_var_name + " = gm.get_host_name_ip('" +\
103 host + "')"
104 exec(cmd_buf)
105
106###############################################################################
107
108
109###############################################################################
Michael Walshb5839d02017-04-12 16:11:20 -0500110def process_pgm_parms():
111
112 r"""
113 Process the program parameters by assigning them all to corresponding
114 globals. Also, set some global values that depend on program parameters.
115 """
116
117 # Program parameter processing.
118 # Assign all program parms to python variables which are global to this
119 # module.
120
121 global parm_list
122 parm_list = BuiltIn().get_variable_value("${parm_list}")
123 # The following subset of parms should be processed as integers.
124 int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only',
125 'boot_fail_threshold', 'quiet', 'test_mode', 'debug']
126 for parm in parm_list:
127 if parm in int_list:
128 sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\
129 "}\", \"0\"))"
130 else:
131 sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")"
132 cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd
133 exec(cmd_buf)
Michael Walsh0ad0f7f2017-05-04 14:39:58 -0500134 if re.match(r".*_host$", parm):
135 cmd_buf = "process_host(" + parm + ", '" + parm + "')"
136 exec(cmd_buf)
137 if re.match(r".*_password$", parm):
138 # Register the value of any parm whose name ends in _password.
139 # This will cause the print functions to replace passwords with
140 # asterisks in the output.
141 cmd_buf = "gp.register_passwords(" + parm + ")"
142 exec(cmd_buf)
Michael Walshb5839d02017-04-12 16:11:20 -0500143
144 global ffdc_dir_path_style
145 global boot_list
146 global boot_stack
147 global boot_results_file_path
148 global boot_results
149 global ffdc_list_file_path
Michael Walshe0cf8d72017-05-17 13:20:46 -0500150 global ffdc_report_list_path
Michael Walshb5839d02017-04-12 16:11:20 -0500151
152 if ffdc_dir_path_style == "":
153 ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0'))
154
155 # Convert these program parms to lists for easier processing..
156 boot_list = filter(None, boot_list.split(":"))
157 boot_stack = filter(None, boot_stack.split(":"))
158
159 boot_results_file_path = "/tmp/" + openbmc_nickname + ":pid_" +\
160 str(master_pid) + ":boot_results"
161
162 if os.path.isfile(boot_results_file_path):
163 # We've been called before in this run so we'll load the saved
164 # boot_results object.
165 boot_results = pickle.load(open(boot_results_file_path, 'rb'))
166 else:
167 boot_results = boot_results(boot_table, boot_pass, boot_fail)
168
169 ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\
170 "/FFDC_FILE_LIST"
Michael Walshe0cf8d72017-05-17 13:20:46 -0500171 ffdc_report_list_path = base_tool_dir_path + openbmc_nickname +\
172 "/FFDC_REPORT_FILE_LIST"
Michael Walshb5839d02017-04-12 16:11:20 -0500173
174###############################################################################
175
176
177###############################################################################
Michael Walsh85678942017-03-27 14:34:22 -0500178def initial_plug_in_setup():
179
180 r"""
181 Initialize all plug-in environment variables which do not change for the
182 duration of the program.
183
184 """
185
186 global LOG_LEVEL
187 BuiltIn().set_log_level("NONE")
188
189 BuiltIn().set_global_variable("${master_pid}", master_pid)
190 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
191 BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path)
192 BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path)
193 BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}",
194 ffdc_list_file_path)
Michael Walshe0cf8d72017-05-17 13:20:46 -0500195 BuiltIn().set_global_variable("${FFDC_REPORT_LIST_PATH}",
196 ffdc_report_list_path)
Michael Walsh85678942017-03-27 14:34:22 -0500197
198 BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}",
199 ffdc_dir_path_style)
200 BuiltIn().set_global_variable("${FFDC_CHECK}",
201 ffdc_check)
202
203 # For each program parameter, set the corresponding AUTOBOOT_ environment
204 # variable value. Also, set an AUTOBOOT_ environment variable for every
205 # element in additional_values.
206 additional_values = ["program_pid", "master_pid", "ffdc_dir_path",
207 "status_dir_path", "base_tool_dir_path",
Michael Walshe0cf8d72017-05-17 13:20:46 -0500208 "ffdc_list_file_path", "ffdc_report_list_path"]
Michael Walsh85678942017-03-27 14:34:22 -0500209
210 plug_in_vars = parm_list + additional_values
211
212 for var_name in plug_in_vars:
213 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
214 var_name = var_name.upper()
215 if var_value is None:
216 var_value = ""
217 os.environ["AUTOBOOT_" + var_name] = str(var_value)
218
219 BuiltIn().set_log_level(LOG_LEVEL)
220
Michael Walsh68a61162017-04-25 11:54:06 -0500221 # Make sure the ffdc list directory exists.
222 ffdc_list_dir_path = os.path.dirname(ffdc_list_file_path) + os.sep
223 if not os.path.exists(ffdc_list_dir_path):
224 os.makedirs(ffdc_list_dir_path)
Michael Walsh85678942017-03-27 14:34:22 -0500225
226###############################################################################
227
Michael Walsh0bbd8602016-11-22 11:31:49 -0600228
229###############################################################################
Michael Walsh0bbd8602016-11-22 11:31:49 -0600230def plug_in_setup():
231
232 r"""
Michael Walsh85678942017-03-27 14:34:22 -0500233 Initialize all changing plug-in environment variables for use by the
234 plug-in programs.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600235 """
236
Michael Walsh85678942017-03-27 14:34:22 -0500237 global LOG_LEVEL
238 global test_really_running
239
240 BuiltIn().set_log_level("NONE")
241
Michael Walsh6741f742017-02-20 16:16:38 -0600242 boot_pass, boot_fail = boot_results.return_total_pass_fail()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600243 if boot_pass > 1:
244 test_really_running = 1
245 else:
246 test_really_running = 0
247
Michael Walsh0bbd8602016-11-22 11:31:49 -0600248 seconds = time.time()
249 loc_time = time.localtime(seconds)
250 time_string = time.strftime("%y%m%d.%H%M%S.", loc_time)
251
Michael Walsh6741f742017-02-20 16:16:38 -0600252 ffdc_prefix = openbmc_nickname + "." + time_string
Michael Walsh0bbd8602016-11-22 11:31:49 -0600253
Michael Walsh6741f742017-02-20 16:16:38 -0600254 BuiltIn().set_global_variable("${test_really_running}",
255 test_really_running)
256 BuiltIn().set_global_variable("${boot_type_desc}", next_boot)
Michael Walsh6741f742017-02-20 16:16:38 -0600257 BuiltIn().set_global_variable("${boot_pass}", boot_pass)
258 BuiltIn().set_global_variable("${boot_fail}", boot_fail)
259 BuiltIn().set_global_variable("${boot_success}", boot_success)
260 BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix)
Michael Walsh4c9a6452016-12-13 16:03:11 -0600261
Michael Walsh0bbd8602016-11-22 11:31:49 -0600262 # For each program parameter, set the corresponding AUTOBOOT_ environment
263 # variable value. Also, set an AUTOBOOT_ environment variable for every
264 # element in additional_values.
265 additional_values = ["boot_type_desc", "boot_success", "boot_pass",
Michael Walsh85678942017-03-27 14:34:22 -0500266 "boot_fail", "test_really_running", "ffdc_prefix"]
Michael Walsh0bbd8602016-11-22 11:31:49 -0600267
Michael Walsh85678942017-03-27 14:34:22 -0500268 plug_in_vars = additional_values
Michael Walsh0bbd8602016-11-22 11:31:49 -0600269
270 for var_name in plug_in_vars:
271 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
272 var_name = var_name.upper()
273 if var_value is None:
274 var_value = ""
Michael Walsh6741f742017-02-20 16:16:38 -0600275 os.environ["AUTOBOOT_" + var_name] = str(var_value)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600276
Michael Walsh0bbd8602016-11-22 11:31:49 -0600277 if debug:
Michael Walsh6741f742017-02-20 16:16:38 -0600278 shell_rc, out_buf = \
279 gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600280
Michael Walsh85678942017-03-27 14:34:22 -0500281 BuiltIn().set_log_level(LOG_LEVEL)
282
Michael Walsh0bbd8602016-11-22 11:31:49 -0600283###############################################################################
284
285
286###############################################################################
Michael Walshe0cf8d72017-05-17 13:20:46 -0500287def pre_boot_plug_in_setup():
288
289 # Clear the ffdc_list_file_path file. Plug-ins may now write to it.
290 try:
291 os.remove(ffdc_list_file_path)
292 except OSError:
293 pass
294
295 # Clear the ffdc_report_list_path file. Plug-ins may now write to it.
296 try:
297 os.remove(ffdc_report_list_path)
298 except OSError:
299 pass
300
301###############################################################################
302
303
304###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600305def setup():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600306
307 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600308 Do general program setup tasks.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600309 """
310
Michael Walsh6741f742017-02-20 16:16:38 -0600311 global cp_setup_called
Michael Walsh0bbd8602016-11-22 11:31:49 -0600312
Michael Walshb5839d02017-04-12 16:11:20 -0500313 gp.qprintn()
314
Michael Walsh83f4bc72017-04-20 16:49:43 -0500315 robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
316 repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/")
317 # If we can't find ssh_pw, then we don't have our repo bin in PATH.
Michael Walshb5839d02017-04-12 16:11:20 -0500318 shell_rc, out_buf = gc.cmd_fnc_u("which ssh_pw", quiet=1, print_output=0,
319 show_err=0)
320 if shell_rc != 0:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500321 os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "")
322 # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH.
323 if robot_pgm_dir_path not in sys.path:
324 sys.path.append(robot_pgm_dir_path)
325 PYTHONPATH = os.environ.get("PYTHONPATH", "")
326 if PYTHONPATH == "":
327 os.environ['PYTHONPATH'] = robot_pgm_dir_path
328 else:
329 os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH
Michael Walsh6741f742017-02-20 16:16:38 -0600330
331 validate_parms()
332
333 grp.rqprint_pgm_header()
334
Michael Walshb5839d02017-04-12 16:11:20 -0500335 grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE")
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500336
Michael Walsh85678942017-03-27 14:34:22 -0500337 initial_plug_in_setup()
338
Michael Walsh6741f742017-02-20 16:16:38 -0600339 plug_in_setup()
340 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
341 call_point='setup')
342 if rc != 0:
343 error_message = "Plug-in setup failed.\n"
344 grp.rprint_error_report(error_message)
345 BuiltIn().fail(error_message)
346 # Setting cp_setup_called lets our Teardown know that it needs to call
347 # the cleanup plug-in call point.
348 cp_setup_called = 1
349
350 # Keyword "FFDC" will fail if TEST_MESSAGE is not set.
351 BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}")
Michael Walsh85678942017-03-27 14:34:22 -0500352 # FFDC_LOG_PATH is used by "FFDC" keyword.
353 BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
Michael Walsh6741f742017-02-20 16:16:38 -0600354
Michael Walshdc80d672017-05-09 12:58:32 -0500355 # Also printed by FFDC.
356 global host_name
357 global host_ip
358 host = socket.gethostname()
359 host_name, host_ip = gm.get_host_name_ip(host)
360
Michael Walshb5839d02017-04-12 16:11:20 -0500361 gp.dprint_var(boot_table, 1)
362 gp.dprint_var(boot_lists)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600363
364###############################################################################
365
366
367###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600368def validate_parms():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600369
370 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600371 Validate all program parameters.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600372 """
373
Michael Walshb5839d02017-04-12 16:11:20 -0500374 process_pgm_parms()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600375
Michael Walshb5839d02017-04-12 16:11:20 -0500376 gp.qprintn()
377
378 global openbmc_model
Michael Walsh6741f742017-02-20 16:16:38 -0600379 grv.rvalid_value("openbmc_host")
380 grv.rvalid_value("openbmc_username")
381 grv.rvalid_value("openbmc_password")
382 if os_host != "":
383 grv.rvalid_value("os_username")
384 grv.rvalid_value("os_password")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600385
Michael Walsh6741f742017-02-20 16:16:38 -0600386 if pdu_host != "":
387 grv.rvalid_value("pdu_username")
388 grv.rvalid_value("pdu_password")
Michael Walsh85678942017-03-27 14:34:22 -0500389 grv.rvalid_integer("pdu_slot_no")
Michael Walsh6741f742017-02-20 16:16:38 -0600390 if openbmc_serial_host != "":
391 grv.rvalid_integer("openbmc_serial_port")
Michael Walshb5839d02017-04-12 16:11:20 -0500392 if openbmc_model == "":
393 status, ret_values =\
394 grk.run_key_u("Get BMC System Model")
395 openbmc_model = ret_values
396 BuiltIn().set_global_variable("${openbmc_model}", openbmc_model)
Michael Walsh6741f742017-02-20 16:16:38 -0600397 grv.rvalid_value("openbmc_model")
Michael Walshb5839d02017-04-12 16:11:20 -0500398 grv.rvalid_integer("max_num_tests")
Michael Walsh6741f742017-02-20 16:16:38 -0600399 grv.rvalid_integer("boot_pass")
400 grv.rvalid_integer("boot_fail")
401
402 plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths)
403 BuiltIn().set_global_variable("${plug_in_packages_list}",
404 plug_in_packages_list)
405
Michael Walshb5839d02017-04-12 16:11:20 -0500406 grv.rvalid_value("stack_mode", valid_values=['normal', 'skip'])
Michael Walsha20da402017-03-31 16:27:45 -0500407 if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only:
Michael Walsh6741f742017-02-20 16:16:38 -0600408 error_message = "You must provide either a value for either the" +\
409 " boot_list or the boot_stack parm.\n"
410 BuiltIn().fail(gp.sprint_error(error_message))
411
412 valid_boot_list(boot_list, valid_boot_types)
413 valid_boot_list(boot_stack, valid_boot_types)
414
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500415 selected_PDU_boots = list(set(boot_list + boot_stack) &
416 set(boot_lists['PDU_reboot']))
417
418 if len(selected_PDU_boots) > 0 and pdu_host == "":
419 error_message = "You have selected the following boots which" +\
420 " require a PDU host but no value for pdu_host:\n"
421 error_message += gp.sprint_var(selected_PDU_boots)
422 error_message += gp.sprint_var(pdu_host, 2)
423 BuiltIn().fail(gp.sprint_error(error_message))
424
Michael Walsh6741f742017-02-20 16:16:38 -0600425 return
Michael Walsh0bbd8602016-11-22 11:31:49 -0600426
427###############################################################################
428
429
430###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600431def my_get_state():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600432
433 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600434 Get the system state plus a little bit of wrapping.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600435 """
436
Michael Walsh6741f742017-02-20 16:16:38 -0600437 global state
438
439 req_states = ['epoch_seconds'] + st.default_req_states
440
Michael Walshb5839d02017-04-12 16:11:20 -0500441 gp.qprint_timen("Getting system state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600442 if test_mode:
443 state['epoch_seconds'] = int(time.time())
444 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500445 state = st.get_state(req_states=req_states, quiet=quiet)
446 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600447
448###############################################################################
449
450
451###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600452def select_boot():
Michael Walsh341c21e2017-01-17 16:25:20 -0600453
454 r"""
455 Select a boot test to be run based on our current state and return the
456 chosen boot type.
457
458 Description of arguments:
Michael Walsh6741f742017-02-20 16:16:38 -0600459 state The state of the machine.
Michael Walsh341c21e2017-01-17 16:25:20 -0600460 """
461
Michael Walsh30dadae2017-02-27 14:25:52 -0600462 global boot_stack
463
Michael Walshb5839d02017-04-12 16:11:20 -0500464 gp.qprint_timen("Selecting a boot test.")
Michael Walsh6741f742017-02-20 16:16:38 -0600465
466 my_get_state()
467
468 stack_popped = 0
469 if len(boot_stack) > 0:
470 stack_popped = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500471 gp.qprint_dashes()
472 gp.qprint_var(boot_stack)
473 gp.qprint_dashes()
474 skip_boot_printed = 0
475 while len(boot_stack) > 0:
476 boot_candidate = boot_stack.pop()
477 if stack_mode == 'normal':
478 break
479 else:
480 if st.compare_states(state, boot_table[boot_candidate]['end']):
481 if not skip_boot_printed:
482 gp.print_var(stack_mode)
483 gp.printn()
484 gp.print_timen("Skipping the following boot tests" +
485 " which are unnecessary since their" +
486 " required end states match the" +
487 " current machine state:")
488 skip_boot_printed = 1
489 gp.print_var(boot_candidate)
490 boot_candidate = ""
491 if boot_candidate == "":
492 gp.qprint_dashes()
493 gp.qprint_var(boot_stack)
494 gp.qprint_dashes()
495 return boot_candidate
Michael Walsh6741f742017-02-20 16:16:38 -0600496 if st.compare_states(state, boot_table[boot_candidate]['start']):
Michael Walshb5839d02017-04-12 16:11:20 -0500497 gp.qprint_timen("The machine state is valid for a '" +
498 boot_candidate + "' boot test.")
499 gp.qprint_dashes()
500 gp.qprint_var(boot_stack)
501 gp.qprint_dashes()
Michael Walsh6741f742017-02-20 16:16:38 -0600502 return boot_candidate
Michael Walsh341c21e2017-01-17 16:25:20 -0600503 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500504 gp.qprint_timen("The machine state does not match the required" +
505 " starting state for a '" + boot_candidate +
506 "' boot test:")
507 gp.print_varx("boot_table[" + boot_candidate + "][start]",
508 boot_table[boot_candidate]['start'], 1)
Michael Walsh6741f742017-02-20 16:16:38 -0600509 boot_stack.append(boot_candidate)
510 popped_boot = boot_candidate
511
512 # Loop through your list selecting a boot_candidates
513 boot_candidates = []
514 for boot_candidate in boot_list:
515 if st.compare_states(state, boot_table[boot_candidate]['start']):
516 if stack_popped:
517 if st.compare_states(boot_table[boot_candidate]['end'],
518 boot_table[popped_boot]['start']):
519 boot_candidates.append(boot_candidate)
520 else:
521 boot_candidates.append(boot_candidate)
522
523 if len(boot_candidates) == 0:
Michael Walshb5839d02017-04-12 16:11:20 -0500524 gp.qprint_timen("The user's boot list contained no boot tests" +
525 " which are valid for the current machine state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600526 boot_candidate = default_power_on
527 if not st.compare_states(state, boot_table[default_power_on]['start']):
528 boot_candidate = default_power_off
529 boot_candidates.append(boot_candidate)
Michael Walshb5839d02017-04-12 16:11:20 -0500530 gp.qprint_timen("Using default '" + boot_candidate +
531 "' boot type to transition to valid state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600532
Michael Walshb5839d02017-04-12 16:11:20 -0500533 gp.dprint_var(boot_candidates)
Michael Walsh6741f742017-02-20 16:16:38 -0600534
535 # Randomly select a boot from the candidate list.
536 boot = random.choice(boot_candidates)
Michael Walsh341c21e2017-01-17 16:25:20 -0600537
538 return boot
Michael Walsh0bbd8602016-11-22 11:31:49 -0600539
540###############################################################################
Michael Walsh55302292017-01-10 11:43:02 -0600541
542
543###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600544def print_last_boots():
545
546 r"""
547 Print the last ten boots done with their time stamps.
548 """
549
550 # indent 0, 90 chars wide, linefeed, char is "="
Michael Walshb5839d02017-04-12 16:11:20 -0500551 gp.qprint_dashes(0, 90)
552 gp.qprintn("Last 10 boots:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600553
554 for boot_entry in last_ten:
555 grp.rqprint(boot_entry)
Michael Walshb5839d02017-04-12 16:11:20 -0500556 gp.qprint_dashes(0, 90)
Michael Walsh341c21e2017-01-17 16:25:20 -0600557
558###############################################################################
559
560
561###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600562def print_defect_report():
563
564 r"""
565 Print a defect report.
566 """
567
Michael Walsh341c21e2017-01-17 16:25:20 -0600568 # At some point I'd like to have the 'Call FFDC Methods' return a list
569 # of files it has collected. In that case, the following "ls" command
570 # would no longer be needed. For now, however, glob shows the files
571 # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
572 # out (so we don't see duplicates in the list).
573
Michael Walshe0cf8d72017-05-17 13:20:46 -0500574 # Get additional header data which may have been created by ffdc plug-ins.
575 # Also, delete the individual header files to cleanup.
576 cmd_buf = "file_list=$(cat " + ffdc_report_list_path + " 2>/dev/null)" +\
577 " ; [ ! -z \"${file_list}\" ] && cat ${file_list}" +\
578 " 2>/dev/null ; rm -rf ${file_list} 2>/dev/null || :"
579 shell_rc, more_header_info = gc.cmd_fnc_u(cmd_buf, print_output=0,
580 show_err=0)
581
Michael Walsh341c21e2017-01-17 16:25:20 -0600582 LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}")
583
Michael Walshe0cf8d72017-05-17 13:20:46 -0500584 output = '\n'.join(sorted(glob.glob(LOG_PREFIX + '*')))
Michael Walsh341c21e2017-01-17 16:25:20 -0600585 try:
Michael Walsh6741f742017-02-20 16:16:38 -0600586 ffdc_list = open(ffdc_list_file_path, 'r')
Michael Walsh341c21e2017-01-17 16:25:20 -0600587 except IOError:
588 ffdc_list = ""
589
Michael Walsh68a61162017-04-25 11:54:06 -0500590 # Open ffdc_file_list for writing. We will write a complete list of
591 # FFDC files to it for possible use by plug-ins like cp_stop_check.
592 ffdc_list_file = open(ffdc_list_file_path, 'w')
593
594 gp.qprintn()
595 # indent=0, width=90, linefeed=1, char="="
596 gp.qprint_dashes(0, 90, 1, "=")
597 gp.qprintn("Copy this data to the defect:\n")
598
Michael Walshe0cf8d72017-05-17 13:20:46 -0500599 if len(more_header_info) > 0:
600 gp.printn(more_header_info)
Michael Walshdc80d672017-05-09 12:58:32 -0500601 gp.qpvars(host_name, host_ip, openbmc_nickname, openbmc_host,
602 openbmc_host_name, openbmc_ip, openbmc_username,
603 openbmc_password, os_host, os_host_name, os_ip, os_username,
604 os_password, pdu_host, pdu_host_name, pdu_ip, pdu_username,
605 pdu_password, pdu_slot_no, openbmc_serial_host,
606 openbmc_serial_host_name, openbmc_serial_ip, openbmc_serial_port)
Michael Walsh68a61162017-04-25 11:54:06 -0500607
608 gp.qprintn()
609
610 print_last_boots()
611 gp.qprintn()
612 gp.qprint_var(state)
613
Michael Walshb5839d02017-04-12 16:11:20 -0500614 gp.qprintn()
615 gp.qprintn("FFDC data files:")
Michael Walsh341c21e2017-01-17 16:25:20 -0600616 if status_file_path != "":
Michael Walshb5839d02017-04-12 16:11:20 -0500617 gp.qprintn(status_file_path)
Michael Walsh68a61162017-04-25 11:54:06 -0500618 ffdc_list_file.write(status_file_path + "\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600619
Michael Walshb5839d02017-04-12 16:11:20 -0500620 gp.qprintn(output)
621 # gp.qprintn(ffdc_list)
622 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600623
Michael Walshb5839d02017-04-12 16:11:20 -0500624 gp.qprint_dashes(0, 90, 1, "=")
Michael Walsh341c21e2017-01-17 16:25:20 -0600625
Michael Walsh68a61162017-04-25 11:54:06 -0500626 ffdc_list_file.write(output + "\n")
627 ffdc_list_file.close()
628
Michael Walsh341c21e2017-01-17 16:25:20 -0600629###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600630
631
632###############################################################################
633def my_ffdc():
634
635 r"""
636 Collect FFDC data.
637 """
638
639 global state
640
641 plug_in_setup()
642 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
643 call_point='ffdc', stop_on_plug_in_failure=1)
644
645 AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
Michael Walsh83f4bc72017-04-20 16:49:43 -0500646 status, ret_values = grk.run_key_u("FFDC ffdc_prefix=" +
647 AUTOBOOT_FFDC_PREFIX +
648 " ffdc_function_list=" +
649 ffdc_function_list, ignore=1)
650 if status != 'PASS':
Michael Walsh3328caf2017-03-21 17:04:08 -0500651 gp.print_error("Call to ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600652
653 my_get_state()
654
655 print_defect_report()
656
657###############################################################################
658
659
660###############################################################################
661def print_test_start_message(boot_keyword):
662
663 r"""
664 Print a message indicating what boot test is about to run.
665
666 Description of arguments:
667 boot_keyword The name of the boot which is to be run
668 (e.g. "BMC Power On").
669 """
670
671 global last_ten
672
673 doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".")
Michael Walshb5839d02017-04-12 16:11:20 -0500674 gp.qprint(doing_msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600675
676 last_ten.append(doing_msg)
677
678 if len(last_ten) > 10:
679 del last_ten[0]
680
681###############################################################################
682
683
684###############################################################################
685def run_boot(boot):
686
687 r"""
688 Run the specified boot.
689
690 Description of arguments:
691 boot The name of the boot test to be performed.
692 """
693
694 global state
695
696 print_test_start_message(boot)
697
698 plug_in_setup()
699 rc, shell_rc, failed_plug_in_name = \
700 grpi.rprocess_plug_in_packages(call_point="pre_boot")
701 if rc != 0:
702 error_message = "Plug-in failed with non-zero return code.\n" +\
703 gp.sprint_var(rc, 1)
704 BuiltIn().fail(gp.sprint_error(error_message))
705
706 if test_mode:
707 # In test mode, we'll pretend the boot worked by assigning its
708 # required end state to the default state value.
Michael Walsh30dadae2017-02-27 14:25:52 -0600709 state = st.strip_anchor_state(boot_table[boot]['end'])
Michael Walsh6741f742017-02-20 16:16:38 -0600710 else:
711 # Assertion: We trust that the state data was made fresh by the
712 # caller.
713
Michael Walshb5839d02017-04-12 16:11:20 -0500714 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600715
716 if boot_table[boot]['method_type'] == "keyword":
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600717 rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
Michael Walshb5839d02017-04-12 16:11:20 -0500718 boot_table[boot]['method'],
719 quiet=quiet)
Michael Walsh6741f742017-02-20 16:16:38 -0600720
721 if boot_table[boot]['bmc_reboot']:
722 st.wait_for_comm_cycle(int(state['epoch_seconds']))
Michael Walsh30dadae2017-02-27 14:25:52 -0600723 plug_in_setup()
724 rc, shell_rc, failed_plug_in_name = \
725 grpi.rprocess_plug_in_packages(call_point="post_reboot")
726 if rc != 0:
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600727 error_message = "Plug-in failed with non-zero return code.\n"
728 error_message += gp.sprint_var(rc, 1)
Michael Walsh30dadae2017-02-27 14:25:52 -0600729 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600730 else:
731 match_state = st.anchor_state(state)
732 del match_state['epoch_seconds']
733 # Wait for the state to change in any way.
734 st.wait_state(match_state, wait_time=state_change_timeout,
735 interval="3 seconds", invert=1)
736
Michael Walshb5839d02017-04-12 16:11:20 -0500737 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600738 if boot_table[boot]['end']['chassis'] == "Off":
739 boot_timeout = power_off_timeout
740 else:
741 boot_timeout = power_on_timeout
742 st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
743 interval="3 seconds")
744
745 plug_in_setup()
746 rc, shell_rc, failed_plug_in_name = \
747 grpi.rprocess_plug_in_packages(call_point="post_boot")
748 if rc != 0:
749 error_message = "Plug-in failed with non-zero return code.\n" +\
750 gp.sprint_var(rc, 1)
751 BuiltIn().fail(gp.sprint_error(error_message))
752
753###############################################################################
754
755
756###############################################################################
757def test_loop_body():
758
759 r"""
760 The main loop body for the loop in main_py.
761
762 Description of arguments:
763 boot_count The iteration number (starts at 1).
764 """
765
766 global boot_count
767 global state
768 global next_boot
769 global boot_success
770
Michael Walshb5839d02017-04-12 16:11:20 -0500771 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600772
773 next_boot = select_boot()
Michael Walshb5839d02017-04-12 16:11:20 -0500774 if next_boot == "":
775 return True
Michael Walsh6741f742017-02-20 16:16:38 -0600776
Michael Walshb5839d02017-04-12 16:11:20 -0500777 boot_count += 1
778 gp.qprint_timen("Starting boot " + str(boot_count) + ".")
Michael Walsh6741f742017-02-20 16:16:38 -0600779
Michael Walshe0cf8d72017-05-17 13:20:46 -0500780 pre_boot_plug_in_setup()
Michael Walsh6741f742017-02-20 16:16:38 -0600781
782 cmd_buf = ["run_boot", next_boot]
783 boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
784 if boot_status == "FAIL":
Michael Walshb5839d02017-04-12 16:11:20 -0500785 gp.qprint(msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600786
Michael Walshb5839d02017-04-12 16:11:20 -0500787 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600788 if boot_status == "PASS":
789 boot_success = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500790 gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.")
Michael Walsh6741f742017-02-20 16:16:38 -0600791 else:
792 boot_success = 0
Michael Walshb5839d02017-04-12 16:11:20 -0500793 gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.")
Michael Walsh6741f742017-02-20 16:16:38 -0600794
795 boot_results.update(next_boot, boot_status)
796
797 plug_in_setup()
798 # NOTE: A post_test_case call point failure is NOT counted as a boot
799 # failure.
800 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
801 call_point='post_test_case', stop_on_plug_in_failure=1)
802
803 plug_in_setup()
804 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
805 call_point='ffdc_check', shell_rc=0x00000200,
806 stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
807 if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500808 status, ret_values = grk.run_key_u("my_ffdc", ignore=1)
809 if status != 'PASS':
Michael Walsh3328caf2017-03-21 17:04:08 -0500810 gp.print_error("Call to my_ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600811
Michael Walshd139f282017-04-04 18:00:23 -0500812 # We need to purge error logs between boots or they build up.
Michael Walshb5839d02017-04-12 16:11:20 -0500813 grk.run_key("Delete Error logs", ignore=1)
Michael Walshd139f282017-04-04 18:00:23 -0500814
Michael Walsh952f9b02017-03-09 13:11:14 -0600815 boot_results.print_report()
Michael Walshb5839d02017-04-12 16:11:20 -0500816 gp.qprint_timen("Finished boot " + str(boot_count) + ".")
Michael Walsh952f9b02017-03-09 13:11:14 -0600817
Michael Walsh6741f742017-02-20 16:16:38 -0600818 plug_in_setup()
819 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
820 call_point='stop_check')
821 if rc != 0:
822 error_message = "Stopping as requested by user.\n"
823 grp.rprint_error_report(error_message)
824 BuiltIn().fail(error_message)
825
Michael Walshd139f282017-04-04 18:00:23 -0500826 # This should help prevent ConnectionErrors.
Michael Walshb5839d02017-04-12 16:11:20 -0500827 grk.run_key_u("Delete All Sessions")
Michael Walshd139f282017-04-04 18:00:23 -0500828
Michael Walsh6741f742017-02-20 16:16:38 -0600829 return True
830
831###############################################################################
832
833
834###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500835def obmc_boot_test_teardown():
Michael Walsh6741f742017-02-20 16:16:38 -0600836
837 r"""
Michael Walshc9116812017-03-10 14:23:06 -0600838 Clean up after the Main keyword.
Michael Walsh6741f742017-02-20 16:16:38 -0600839 """
840
841 if cp_setup_called:
842 plug_in_setup()
843 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
844 call_point='cleanup', stop_on_plug_in_failure=1)
845
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600846 # Save boot_results object to a file in case it is needed again.
Michael Walshb5839d02017-04-12 16:11:20 -0500847 gp.qprint_timen("Saving boot_results to the following path.")
848 gp.qprint_var(boot_results_file_path)
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600849 pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
850 pickle.HIGHEST_PROTOCOL)
851
Michael Walsh6741f742017-02-20 16:16:38 -0600852###############################################################################
853
854
855###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600856def test_teardown():
857
858 r"""
859 Clean up after this test case.
860 """
861
862 gp.qprintn()
863 cmd_buf = ["Print Error",
864 "A keyword timeout occurred ending this program.\n"]
865 BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf)
866
Michael Walshb5839d02017-04-12 16:11:20 -0500867 grp.rqprint_pgm_footer()
868
Michael Walshc9116812017-03-10 14:23:06 -0600869###############################################################################
870
871
872###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500873def obmc_boot_test_py(alt_boot_stack=None):
Michael Walsh6741f742017-02-20 16:16:38 -0600874
875 r"""
876 Do main program processing.
877 """
878
Michael Walshb5839d02017-04-12 16:11:20 -0500879 if alt_boot_stack is not None:
880 BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack)
881
Michael Walsh6741f742017-02-20 16:16:38 -0600882 setup()
883
Michael Walsha20da402017-03-31 16:27:45 -0500884 if ffdc_only:
885 gp.qprint_timen("Caller requested ffdc_only.")
Michael Walshe0cf8d72017-05-17 13:20:46 -0500886 pre_boot_plug_in_setup()
Michael Walsh83f4bc72017-04-20 16:49:43 -0500887 grk.run_key_u("my_ffdc")
Michael Walsh764d2f82017-04-27 16:01:08 -0500888 return
Michael Walsha20da402017-03-31 16:27:45 -0500889
Michael Walsh6741f742017-02-20 16:16:38 -0600890 # Process caller's boot_stack.
891 while (len(boot_stack) > 0):
892 test_loop_body()
893
Michael Walshb5839d02017-04-12 16:11:20 -0500894 gp.qprint_timen("Finished processing stack.")
Michael Walsh30dadae2017-02-27 14:25:52 -0600895
Michael Walsh6741f742017-02-20 16:16:38 -0600896 # Process caller's boot_list.
897 if len(boot_list) > 0:
898 for ix in range(1, max_num_tests + 1):
899 test_loop_body()
900
Michael Walshb5839d02017-04-12 16:11:20 -0500901 gp.qprint_timen("Completed all requested boot tests.")
902
903 boot_pass, boot_fail = boot_results.return_total_pass_fail()
904 if boot_fail > boot_fail_threshold:
905 error_message = "Boot failures exceed the boot failure" +\
906 " threshold:\n" +\
907 gp.sprint_var(boot_fail) +\
908 gp.sprint_var(boot_fail_threshold)
909 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600910
911###############################################################################