blob: 751488d64607a9e8654eaeba4e12922ef2afcff7 [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
14
15from robot.utils import DotDict
16from robot.libraries.BuiltIn import BuiltIn
17
Michael Walsh6741f742017-02-20 16:16:38 -060018from boot_data import *
Michael Walshc9116812017-03-10 14:23:06 -060019import gen_print as gp
Michael Walsh0bbd8602016-11-22 11:31:49 -060020import gen_robot_print as grp
Michael Walsh55302292017-01-10 11:43:02 -060021import gen_robot_plug_in as grpi
Michael Walsh6741f742017-02-20 16:16:38 -060022import gen_robot_valid as grv
23import gen_misc as gm
24import gen_cmd as gc
Michael Walshb5839d02017-04-12 16:11:20 -050025import gen_robot_keyword as grk
Michael Walsh55302292017-01-10 11:43:02 -060026import state as st
Michael Walsh0bbd8602016-11-22 11:31:49 -060027
Michael Walsh0b93fbf2017-03-02 14:42:41 -060028base_path = os.path.dirname(os.path.dirname(
29 imp.find_module("gen_robot_print")[1])) +\
Michael Walshc9116812017-03-10 14:23:06 -060030 os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060031sys.path.append(base_path + "extended/")
32import run_keyword as rk
Michael Walsh0bbd8602016-11-22 11:31:49 -060033
Michael Walshe1e26442017-03-06 17:50:07 -060034# Setting master_pid correctly influences the behavior of plug-ins like
35# DB_Logging
36program_pid = os.getpid()
37master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid)
38
Michael Walshb5839d02017-04-12 16:11:20 -050039# Set up boot data structures.
40boot_table = create_boot_table()
41valid_boot_types = create_valid_boot_list(boot_table)
Michael Walsh0b93fbf2017-03-02 14:42:41 -060042
Michael Walsh6741f742017-02-20 16:16:38 -060043boot_lists = read_boot_lists()
44last_ten = []
Michael Walsh6741f742017-02-20 16:16:38 -060045
46state = st.return_default_state()
47cp_setup_called = 0
48next_boot = ""
49base_tool_dir_path = os.path.normpath(os.environ.get(
50 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep
Michael Walshb5839d02017-04-12 16:11:20 -050051
Michael Walsh6741f742017-02-20 16:16:38 -060052ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep
Michael Walsh6741f742017-02-20 16:16:38 -060053boot_success = 0
Michael Walsh6741f742017-02-20 16:16:38 -060054status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
55if status_dir_path != "":
56 status_dir_path = os.path.normpath(status_dir_path) + os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060057default_power_on = "REST Power On"
58default_power_off = "REST Power Off"
Michael Walsh6741f742017-02-20 16:16:38 -060059boot_count = 0
Michael Walsh0bbd8602016-11-22 11:31:49 -060060
Michael Walsh85678942017-03-27 14:34:22 -050061LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}")
62
63
64###############################################################################
Michael Walsh0ad0f7f2017-05-04 14:39:58 -050065def process_host(host,
66 host_var_name=""):
67
68 r"""
69 Process a host by getting the associated host name and IP address and
70 setting them in global variables.
71
72 If the caller does not pass the host_var_name, this function will try to
73 figure out the name of the variable used by the caller for the host parm.
74 Callers are advised to explicitly specify the host_var_name when calling
75 with an exec command. In such cases, the get_arg_name cannot figure out
76 the host variable name.
77
78 This function will then create similar global variable names by
79 removing "_host" and appending "_host_name" or "_ip" to the host variable
80 name.
81
82 Example:
83
84 If a call is made like this:
85 process_host(openbmc_host)
86
87 Global variables openbmc_host_name and openbmc_ip will be set.
88
89 Description of argument(s):
90 host A host name or IP. The name of the variable used should
91 have a suffix of "_host".
92 host_var_name The name of the variable being used as the host parm.
93 """
94
95 if host_var_name == "":
96 host_var_name = gp.get_arg_name(0, 1, stack_frame_ix=2)
97
98 host_name_var_name = re.sub("host", "host_name", host_var_name)
99 ip_var_name = re.sub("host", "ip", host_var_name)
100 cmd_buf = "global " + host_name_var_name + ", " + ip_var_name + " ; " +\
101 host_name_var_name + ", " + ip_var_name + " = gm.get_host_name_ip('" +\
102 host + "')"
103 exec(cmd_buf)
104
105###############################################################################
106
107
108###############################################################################
Michael Walshb5839d02017-04-12 16:11:20 -0500109def process_pgm_parms():
110
111 r"""
112 Process the program parameters by assigning them all to corresponding
113 globals. Also, set some global values that depend on program parameters.
114 """
115
116 # Program parameter processing.
117 # Assign all program parms to python variables which are global to this
118 # module.
119
120 global parm_list
121 parm_list = BuiltIn().get_variable_value("${parm_list}")
122 # The following subset of parms should be processed as integers.
123 int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only',
124 'boot_fail_threshold', 'quiet', 'test_mode', 'debug']
125 for parm in parm_list:
126 if parm in int_list:
127 sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\
128 "}\", \"0\"))"
129 else:
130 sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")"
131 cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd
132 exec(cmd_buf)
Michael Walsh0ad0f7f2017-05-04 14:39:58 -0500133 if re.match(r".*_host$", parm):
134 cmd_buf = "process_host(" + parm + ", '" + parm + "')"
135 exec(cmd_buf)
136 if re.match(r".*_password$", parm):
137 # Register the value of any parm whose name ends in _password.
138 # This will cause the print functions to replace passwords with
139 # asterisks in the output.
140 cmd_buf = "gp.register_passwords(" + parm + ")"
141 exec(cmd_buf)
Michael Walshb5839d02017-04-12 16:11:20 -0500142
143 global ffdc_dir_path_style
144 global boot_list
145 global boot_stack
146 global boot_results_file_path
147 global boot_results
148 global ffdc_list_file_path
149
150 if ffdc_dir_path_style == "":
151 ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0'))
152
153 # Convert these program parms to lists for easier processing..
154 boot_list = filter(None, boot_list.split(":"))
155 boot_stack = filter(None, boot_stack.split(":"))
156
157 boot_results_file_path = "/tmp/" + openbmc_nickname + ":pid_" +\
158 str(master_pid) + ":boot_results"
159
160 if os.path.isfile(boot_results_file_path):
161 # We've been called before in this run so we'll load the saved
162 # boot_results object.
163 boot_results = pickle.load(open(boot_results_file_path, 'rb'))
164 else:
165 boot_results = boot_results(boot_table, boot_pass, boot_fail)
166
167 ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\
168 "/FFDC_FILE_LIST"
169
170###############################################################################
171
172
173###############################################################################
Michael Walsh85678942017-03-27 14:34:22 -0500174def initial_plug_in_setup():
175
176 r"""
177 Initialize all plug-in environment variables which do not change for the
178 duration of the program.
179
180 """
181
182 global LOG_LEVEL
183 BuiltIn().set_log_level("NONE")
184
185 BuiltIn().set_global_variable("${master_pid}", master_pid)
186 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
187 BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path)
188 BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path)
189 BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}",
190 ffdc_list_file_path)
191
192 BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}",
193 ffdc_dir_path_style)
194 BuiltIn().set_global_variable("${FFDC_CHECK}",
195 ffdc_check)
196
197 # For each program parameter, set the corresponding AUTOBOOT_ environment
198 # variable value. Also, set an AUTOBOOT_ environment variable for every
199 # element in additional_values.
200 additional_values = ["program_pid", "master_pid", "ffdc_dir_path",
201 "status_dir_path", "base_tool_dir_path",
202 "ffdc_list_file_path"]
203
204 plug_in_vars = parm_list + additional_values
205
206 for var_name in plug_in_vars:
207 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
208 var_name = var_name.upper()
209 if var_value is None:
210 var_value = ""
211 os.environ["AUTOBOOT_" + var_name] = str(var_value)
212
213 BuiltIn().set_log_level(LOG_LEVEL)
214
Michael Walsh68a61162017-04-25 11:54:06 -0500215 # Make sure the ffdc list directory exists.
216 ffdc_list_dir_path = os.path.dirname(ffdc_list_file_path) + os.sep
217 if not os.path.exists(ffdc_list_dir_path):
218 os.makedirs(ffdc_list_dir_path)
Michael Walsh85678942017-03-27 14:34:22 -0500219
220###############################################################################
221
Michael Walsh0bbd8602016-11-22 11:31:49 -0600222
223###############################################################################
Michael Walsh0bbd8602016-11-22 11:31:49 -0600224def plug_in_setup():
225
226 r"""
Michael Walsh85678942017-03-27 14:34:22 -0500227 Initialize all changing plug-in environment variables for use by the
228 plug-in programs.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600229 """
230
Michael Walsh85678942017-03-27 14:34:22 -0500231 global LOG_LEVEL
232 global test_really_running
233
234 BuiltIn().set_log_level("NONE")
235
Michael Walsh6741f742017-02-20 16:16:38 -0600236 boot_pass, boot_fail = boot_results.return_total_pass_fail()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600237 if boot_pass > 1:
238 test_really_running = 1
239 else:
240 test_really_running = 0
241
Michael Walsh0bbd8602016-11-22 11:31:49 -0600242 seconds = time.time()
243 loc_time = time.localtime(seconds)
244 time_string = time.strftime("%y%m%d.%H%M%S.", loc_time)
245
Michael Walsh6741f742017-02-20 16:16:38 -0600246 ffdc_prefix = openbmc_nickname + "." + time_string
Michael Walsh0bbd8602016-11-22 11:31:49 -0600247
Michael Walsh6741f742017-02-20 16:16:38 -0600248 BuiltIn().set_global_variable("${test_really_running}",
249 test_really_running)
250 BuiltIn().set_global_variable("${boot_type_desc}", next_boot)
Michael Walsh6741f742017-02-20 16:16:38 -0600251 BuiltIn().set_global_variable("${boot_pass}", boot_pass)
252 BuiltIn().set_global_variable("${boot_fail}", boot_fail)
253 BuiltIn().set_global_variable("${boot_success}", boot_success)
254 BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix)
Michael Walsh4c9a6452016-12-13 16:03:11 -0600255
Michael Walsh0bbd8602016-11-22 11:31:49 -0600256 # For each program parameter, set the corresponding AUTOBOOT_ environment
257 # variable value. Also, set an AUTOBOOT_ environment variable for every
258 # element in additional_values.
259 additional_values = ["boot_type_desc", "boot_success", "boot_pass",
Michael Walsh85678942017-03-27 14:34:22 -0500260 "boot_fail", "test_really_running", "ffdc_prefix"]
Michael Walsh0bbd8602016-11-22 11:31:49 -0600261
Michael Walsh85678942017-03-27 14:34:22 -0500262 plug_in_vars = additional_values
Michael Walsh0bbd8602016-11-22 11:31:49 -0600263
264 for var_name in plug_in_vars:
265 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
266 var_name = var_name.upper()
267 if var_value is None:
268 var_value = ""
Michael Walsh6741f742017-02-20 16:16:38 -0600269 os.environ["AUTOBOOT_" + var_name] = str(var_value)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600270
Michael Walsh0bbd8602016-11-22 11:31:49 -0600271 if debug:
Michael Walsh6741f742017-02-20 16:16:38 -0600272 shell_rc, out_buf = \
273 gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600274
Michael Walsh85678942017-03-27 14:34:22 -0500275 BuiltIn().set_log_level(LOG_LEVEL)
276
Michael Walsh0bbd8602016-11-22 11:31:49 -0600277###############################################################################
278
279
280###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600281def setup():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600282
283 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600284 Do general program setup tasks.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600285 """
286
Michael Walsh6741f742017-02-20 16:16:38 -0600287 global cp_setup_called
Michael Walsh0bbd8602016-11-22 11:31:49 -0600288
Michael Walshb5839d02017-04-12 16:11:20 -0500289 gp.qprintn()
290
Michael Walsh83f4bc72017-04-20 16:49:43 -0500291 robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
292 repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/")
293 # If we can't find ssh_pw, then we don't have our repo bin in PATH.
Michael Walshb5839d02017-04-12 16:11:20 -0500294 shell_rc, out_buf = gc.cmd_fnc_u("which ssh_pw", quiet=1, print_output=0,
295 show_err=0)
296 if shell_rc != 0:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500297 os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "")
298 # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH.
299 if robot_pgm_dir_path not in sys.path:
300 sys.path.append(robot_pgm_dir_path)
301 PYTHONPATH = os.environ.get("PYTHONPATH", "")
302 if PYTHONPATH == "":
303 os.environ['PYTHONPATH'] = robot_pgm_dir_path
304 else:
305 os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH
Michael Walsh6741f742017-02-20 16:16:38 -0600306
307 validate_parms()
308
309 grp.rqprint_pgm_header()
310
Michael Walshb5839d02017-04-12 16:11:20 -0500311 grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE")
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500312
Michael Walsh85678942017-03-27 14:34:22 -0500313 initial_plug_in_setup()
314
Michael Walsh6741f742017-02-20 16:16:38 -0600315 plug_in_setup()
316 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
317 call_point='setup')
318 if rc != 0:
319 error_message = "Plug-in setup failed.\n"
320 grp.rprint_error_report(error_message)
321 BuiltIn().fail(error_message)
322 # Setting cp_setup_called lets our Teardown know that it needs to call
323 # the cleanup plug-in call point.
324 cp_setup_called = 1
325
326 # Keyword "FFDC" will fail if TEST_MESSAGE is not set.
327 BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}")
Michael Walsh85678942017-03-27 14:34:22 -0500328 # FFDC_LOG_PATH is used by "FFDC" keyword.
329 BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
Michael Walsh6741f742017-02-20 16:16:38 -0600330
Michael Walshb5839d02017-04-12 16:11:20 -0500331 gp.dprint_var(boot_table, 1)
332 gp.dprint_var(boot_lists)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600333
334###############################################################################
335
336
337###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600338def validate_parms():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600339
340 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600341 Validate all program parameters.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600342 """
343
Michael Walshb5839d02017-04-12 16:11:20 -0500344 process_pgm_parms()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600345
Michael Walshb5839d02017-04-12 16:11:20 -0500346 gp.qprintn()
347
348 global openbmc_model
Michael Walsh6741f742017-02-20 16:16:38 -0600349 grv.rvalid_value("openbmc_host")
350 grv.rvalid_value("openbmc_username")
351 grv.rvalid_value("openbmc_password")
352 if os_host != "":
353 grv.rvalid_value("os_username")
354 grv.rvalid_value("os_password")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600355
Michael Walsh6741f742017-02-20 16:16:38 -0600356 if pdu_host != "":
357 grv.rvalid_value("pdu_username")
358 grv.rvalid_value("pdu_password")
Michael Walsh85678942017-03-27 14:34:22 -0500359 grv.rvalid_integer("pdu_slot_no")
Michael Walsh6741f742017-02-20 16:16:38 -0600360 if openbmc_serial_host != "":
361 grv.rvalid_integer("openbmc_serial_port")
Michael Walshb5839d02017-04-12 16:11:20 -0500362 if openbmc_model == "":
363 status, ret_values =\
364 grk.run_key_u("Get BMC System Model")
365 openbmc_model = ret_values
366 BuiltIn().set_global_variable("${openbmc_model}", openbmc_model)
Michael Walsh6741f742017-02-20 16:16:38 -0600367 grv.rvalid_value("openbmc_model")
Michael Walshb5839d02017-04-12 16:11:20 -0500368 grv.rvalid_integer("max_num_tests")
Michael Walsh6741f742017-02-20 16:16:38 -0600369 grv.rvalid_integer("boot_pass")
370 grv.rvalid_integer("boot_fail")
371
372 plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths)
373 BuiltIn().set_global_variable("${plug_in_packages_list}",
374 plug_in_packages_list)
375
Michael Walshb5839d02017-04-12 16:11:20 -0500376 grv.rvalid_value("stack_mode", valid_values=['normal', 'skip'])
Michael Walsha20da402017-03-31 16:27:45 -0500377 if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only:
Michael Walsh6741f742017-02-20 16:16:38 -0600378 error_message = "You must provide either a value for either the" +\
379 " boot_list or the boot_stack parm.\n"
380 BuiltIn().fail(gp.sprint_error(error_message))
381
382 valid_boot_list(boot_list, valid_boot_types)
383 valid_boot_list(boot_stack, valid_boot_types)
384
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500385 selected_PDU_boots = list(set(boot_list + boot_stack) &
386 set(boot_lists['PDU_reboot']))
387
388 if len(selected_PDU_boots) > 0 and pdu_host == "":
389 error_message = "You have selected the following boots which" +\
390 " require a PDU host but no value for pdu_host:\n"
391 error_message += gp.sprint_var(selected_PDU_boots)
392 error_message += gp.sprint_var(pdu_host, 2)
393 BuiltIn().fail(gp.sprint_error(error_message))
394
Michael Walsh6741f742017-02-20 16:16:38 -0600395 return
Michael Walsh0bbd8602016-11-22 11:31:49 -0600396
397###############################################################################
398
399
400###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600401def my_get_state():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600402
403 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600404 Get the system state plus a little bit of wrapping.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600405 """
406
Michael Walsh6741f742017-02-20 16:16:38 -0600407 global state
408
409 req_states = ['epoch_seconds'] + st.default_req_states
410
Michael Walshb5839d02017-04-12 16:11:20 -0500411 gp.qprint_timen("Getting system state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600412 if test_mode:
413 state['epoch_seconds'] = int(time.time())
414 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500415 state = st.get_state(req_states=req_states, quiet=quiet)
416 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600417
418###############################################################################
419
420
421###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600422def select_boot():
Michael Walsh341c21e2017-01-17 16:25:20 -0600423
424 r"""
425 Select a boot test to be run based on our current state and return the
426 chosen boot type.
427
428 Description of arguments:
Michael Walsh6741f742017-02-20 16:16:38 -0600429 state The state of the machine.
Michael Walsh341c21e2017-01-17 16:25:20 -0600430 """
431
Michael Walsh30dadae2017-02-27 14:25:52 -0600432 global boot_stack
433
Michael Walshb5839d02017-04-12 16:11:20 -0500434 gp.qprint_timen("Selecting a boot test.")
Michael Walsh6741f742017-02-20 16:16:38 -0600435
436 my_get_state()
437
438 stack_popped = 0
439 if len(boot_stack) > 0:
440 stack_popped = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500441 gp.qprint_dashes()
442 gp.qprint_var(boot_stack)
443 gp.qprint_dashes()
444 skip_boot_printed = 0
445 while len(boot_stack) > 0:
446 boot_candidate = boot_stack.pop()
447 if stack_mode == 'normal':
448 break
449 else:
450 if st.compare_states(state, boot_table[boot_candidate]['end']):
451 if not skip_boot_printed:
452 gp.print_var(stack_mode)
453 gp.printn()
454 gp.print_timen("Skipping the following boot tests" +
455 " which are unnecessary since their" +
456 " required end states match the" +
457 " current machine state:")
458 skip_boot_printed = 1
459 gp.print_var(boot_candidate)
460 boot_candidate = ""
461 if boot_candidate == "":
462 gp.qprint_dashes()
463 gp.qprint_var(boot_stack)
464 gp.qprint_dashes()
465 return boot_candidate
Michael Walsh6741f742017-02-20 16:16:38 -0600466 if st.compare_states(state, boot_table[boot_candidate]['start']):
Michael Walshb5839d02017-04-12 16:11:20 -0500467 gp.qprint_timen("The machine state is valid for a '" +
468 boot_candidate + "' boot test.")
469 gp.qprint_dashes()
470 gp.qprint_var(boot_stack)
471 gp.qprint_dashes()
Michael Walsh6741f742017-02-20 16:16:38 -0600472 return boot_candidate
Michael Walsh341c21e2017-01-17 16:25:20 -0600473 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500474 gp.qprint_timen("The machine state does not match the required" +
475 " starting state for a '" + boot_candidate +
476 "' boot test:")
477 gp.print_varx("boot_table[" + boot_candidate + "][start]",
478 boot_table[boot_candidate]['start'], 1)
Michael Walsh6741f742017-02-20 16:16:38 -0600479 boot_stack.append(boot_candidate)
480 popped_boot = boot_candidate
481
482 # Loop through your list selecting a boot_candidates
483 boot_candidates = []
484 for boot_candidate in boot_list:
485 if st.compare_states(state, boot_table[boot_candidate]['start']):
486 if stack_popped:
487 if st.compare_states(boot_table[boot_candidate]['end'],
488 boot_table[popped_boot]['start']):
489 boot_candidates.append(boot_candidate)
490 else:
491 boot_candidates.append(boot_candidate)
492
493 if len(boot_candidates) == 0:
Michael Walshb5839d02017-04-12 16:11:20 -0500494 gp.qprint_timen("The user's boot list contained no boot tests" +
495 " which are valid for the current machine state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600496 boot_candidate = default_power_on
497 if not st.compare_states(state, boot_table[default_power_on]['start']):
498 boot_candidate = default_power_off
499 boot_candidates.append(boot_candidate)
Michael Walshb5839d02017-04-12 16:11:20 -0500500 gp.qprint_timen("Using default '" + boot_candidate +
501 "' boot type to transition to valid state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600502
Michael Walshb5839d02017-04-12 16:11:20 -0500503 gp.dprint_var(boot_candidates)
Michael Walsh6741f742017-02-20 16:16:38 -0600504
505 # Randomly select a boot from the candidate list.
506 boot = random.choice(boot_candidates)
Michael Walsh341c21e2017-01-17 16:25:20 -0600507
508 return boot
Michael Walsh0bbd8602016-11-22 11:31:49 -0600509
510###############################################################################
Michael Walsh55302292017-01-10 11:43:02 -0600511
512
513###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600514def print_last_boots():
515
516 r"""
517 Print the last ten boots done with their time stamps.
518 """
519
520 # indent 0, 90 chars wide, linefeed, char is "="
Michael Walshb5839d02017-04-12 16:11:20 -0500521 gp.qprint_dashes(0, 90)
522 gp.qprintn("Last 10 boots:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600523
524 for boot_entry in last_ten:
525 grp.rqprint(boot_entry)
Michael Walshb5839d02017-04-12 16:11:20 -0500526 gp.qprint_dashes(0, 90)
Michael Walsh341c21e2017-01-17 16:25:20 -0600527
528###############################################################################
529
530
531###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600532def print_defect_report():
533
534 r"""
535 Print a defect report.
536 """
537
Michael Walsh341c21e2017-01-17 16:25:20 -0600538 # At some point I'd like to have the 'Call FFDC Methods' return a list
539 # of files it has collected. In that case, the following "ls" command
540 # would no longer be needed. For now, however, glob shows the files
541 # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
542 # out (so we don't see duplicates in the list).
543
544 LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}")
545
546 output = '\n'.join(glob.glob(LOG_PREFIX + '*'))
Michael Walsh341c21e2017-01-17 16:25:20 -0600547 try:
Michael Walsh6741f742017-02-20 16:16:38 -0600548 ffdc_list = open(ffdc_list_file_path, 'r')
Michael Walsh341c21e2017-01-17 16:25:20 -0600549 except IOError:
550 ffdc_list = ""
551
Michael Walsh68a61162017-04-25 11:54:06 -0500552 # Open ffdc_file_list for writing. We will write a complete list of
553 # FFDC files to it for possible use by plug-ins like cp_stop_check.
554 ffdc_list_file = open(ffdc_list_file_path, 'w')
555
556 gp.qprintn()
557 # indent=0, width=90, linefeed=1, char="="
558 gp.qprint_dashes(0, 90, 1, "=")
559 gp.qprintn("Copy this data to the defect:\n")
560
Michael Walsh0ad0f7f2017-05-04 14:39:58 -0500561 gp.qpvars(openbmc_nickname, openbmc_host, openbmc_host_name, openbmc_ip,
562 openbmc_username, openbmc_password, os_host, os_host_name,
563 os_ip, os_username, os_password, pdu_host, pdu_host_name,
564 pdu_ip, pdu_username, pdu_password, pdu_slot_no,
565 openbmc_serial_host, openbmc_serial_host_name, openbmc_serial_ip,
566 openbmc_serial_port)
Michael Walsh68a61162017-04-25 11:54:06 -0500567
568 gp.qprintn()
569
570 print_last_boots()
571 gp.qprintn()
572 gp.qprint_var(state)
573
Michael Walshb5839d02017-04-12 16:11:20 -0500574 gp.qprintn()
575 gp.qprintn("FFDC data files:")
Michael Walsh341c21e2017-01-17 16:25:20 -0600576 if status_file_path != "":
Michael Walshb5839d02017-04-12 16:11:20 -0500577 gp.qprintn(status_file_path)
Michael Walsh68a61162017-04-25 11:54:06 -0500578 ffdc_list_file.write(status_file_path + "\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600579
Michael Walshb5839d02017-04-12 16:11:20 -0500580 gp.qprintn(output)
581 # gp.qprintn(ffdc_list)
582 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600583
Michael Walshb5839d02017-04-12 16:11:20 -0500584 gp.qprint_dashes(0, 90, 1, "=")
Michael Walsh341c21e2017-01-17 16:25:20 -0600585
Michael Walsh68a61162017-04-25 11:54:06 -0500586 ffdc_list_file.write(output + "\n")
587 ffdc_list_file.close()
588
Michael Walsh341c21e2017-01-17 16:25:20 -0600589###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600590
591
592###############################################################################
593def my_ffdc():
594
595 r"""
596 Collect FFDC data.
597 """
598
599 global state
600
601 plug_in_setup()
602 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
603 call_point='ffdc', stop_on_plug_in_failure=1)
604
605 AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
Michael Walsh83f4bc72017-04-20 16:49:43 -0500606 status, ret_values = grk.run_key_u("FFDC ffdc_prefix=" +
607 AUTOBOOT_FFDC_PREFIX +
608 " ffdc_function_list=" +
609 ffdc_function_list, ignore=1)
610 if status != 'PASS':
Michael Walsh3328caf2017-03-21 17:04:08 -0500611 gp.print_error("Call to ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600612
613 my_get_state()
614
615 print_defect_report()
616
617###############################################################################
618
619
620###############################################################################
621def print_test_start_message(boot_keyword):
622
623 r"""
624 Print a message indicating what boot test is about to run.
625
626 Description of arguments:
627 boot_keyword The name of the boot which is to be run
628 (e.g. "BMC Power On").
629 """
630
631 global last_ten
632
633 doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".")
Michael Walshb5839d02017-04-12 16:11:20 -0500634 gp.qprint(doing_msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600635
636 last_ten.append(doing_msg)
637
638 if len(last_ten) > 10:
639 del last_ten[0]
640
641###############################################################################
642
643
644###############################################################################
645def run_boot(boot):
646
647 r"""
648 Run the specified boot.
649
650 Description of arguments:
651 boot The name of the boot test to be performed.
652 """
653
654 global state
655
656 print_test_start_message(boot)
657
658 plug_in_setup()
659 rc, shell_rc, failed_plug_in_name = \
660 grpi.rprocess_plug_in_packages(call_point="pre_boot")
661 if rc != 0:
662 error_message = "Plug-in failed with non-zero return code.\n" +\
663 gp.sprint_var(rc, 1)
664 BuiltIn().fail(gp.sprint_error(error_message))
665
666 if test_mode:
667 # In test mode, we'll pretend the boot worked by assigning its
668 # required end state to the default state value.
Michael Walsh30dadae2017-02-27 14:25:52 -0600669 state = st.strip_anchor_state(boot_table[boot]['end'])
Michael Walsh6741f742017-02-20 16:16:38 -0600670 else:
671 # Assertion: We trust that the state data was made fresh by the
672 # caller.
673
Michael Walshb5839d02017-04-12 16:11:20 -0500674 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600675
676 if boot_table[boot]['method_type'] == "keyword":
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600677 rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
Michael Walshb5839d02017-04-12 16:11:20 -0500678 boot_table[boot]['method'],
679 quiet=quiet)
Michael Walsh6741f742017-02-20 16:16:38 -0600680
681 if boot_table[boot]['bmc_reboot']:
682 st.wait_for_comm_cycle(int(state['epoch_seconds']))
Michael Walsh30dadae2017-02-27 14:25:52 -0600683 plug_in_setup()
684 rc, shell_rc, failed_plug_in_name = \
685 grpi.rprocess_plug_in_packages(call_point="post_reboot")
686 if rc != 0:
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600687 error_message = "Plug-in failed with non-zero return code.\n"
688 error_message += gp.sprint_var(rc, 1)
Michael Walsh30dadae2017-02-27 14:25:52 -0600689 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600690 else:
691 match_state = st.anchor_state(state)
692 del match_state['epoch_seconds']
693 # Wait for the state to change in any way.
694 st.wait_state(match_state, wait_time=state_change_timeout,
695 interval="3 seconds", invert=1)
696
Michael Walshb5839d02017-04-12 16:11:20 -0500697 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600698 if boot_table[boot]['end']['chassis'] == "Off":
699 boot_timeout = power_off_timeout
700 else:
701 boot_timeout = power_on_timeout
702 st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
703 interval="3 seconds")
704
705 plug_in_setup()
706 rc, shell_rc, failed_plug_in_name = \
707 grpi.rprocess_plug_in_packages(call_point="post_boot")
708 if rc != 0:
709 error_message = "Plug-in failed with non-zero return code.\n" +\
710 gp.sprint_var(rc, 1)
711 BuiltIn().fail(gp.sprint_error(error_message))
712
713###############################################################################
714
715
716###############################################################################
717def test_loop_body():
718
719 r"""
720 The main loop body for the loop in main_py.
721
722 Description of arguments:
723 boot_count The iteration number (starts at 1).
724 """
725
726 global boot_count
727 global state
728 global next_boot
729 global boot_success
730
Michael Walshb5839d02017-04-12 16:11:20 -0500731 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600732
733 next_boot = select_boot()
Michael Walshb5839d02017-04-12 16:11:20 -0500734 if next_boot == "":
735 return True
Michael Walsh6741f742017-02-20 16:16:38 -0600736
Michael Walshb5839d02017-04-12 16:11:20 -0500737 boot_count += 1
738 gp.qprint_timen("Starting boot " + str(boot_count) + ".")
Michael Walsh6741f742017-02-20 16:16:38 -0600739
740 # Clear the ffdc_list_file_path file. Plug-ins may now write to it.
741 try:
742 os.remove(ffdc_list_file_path)
743 except OSError:
744 pass
745
746 cmd_buf = ["run_boot", next_boot]
747 boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
748 if boot_status == "FAIL":
Michael Walshb5839d02017-04-12 16:11:20 -0500749 gp.qprint(msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600750
Michael Walshb5839d02017-04-12 16:11:20 -0500751 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600752 if boot_status == "PASS":
753 boot_success = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500754 gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.")
Michael Walsh6741f742017-02-20 16:16:38 -0600755 else:
756 boot_success = 0
Michael Walshb5839d02017-04-12 16:11:20 -0500757 gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.")
Michael Walsh6741f742017-02-20 16:16:38 -0600758
759 boot_results.update(next_boot, boot_status)
760
761 plug_in_setup()
762 # NOTE: A post_test_case call point failure is NOT counted as a boot
763 # failure.
764 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
765 call_point='post_test_case', stop_on_plug_in_failure=1)
766
767 plug_in_setup()
768 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
769 call_point='ffdc_check', shell_rc=0x00000200,
770 stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
771 if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500772 status, ret_values = grk.run_key_u("my_ffdc", ignore=1)
773 if status != 'PASS':
Michael Walsh3328caf2017-03-21 17:04:08 -0500774 gp.print_error("Call to my_ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600775
Michael Walshd139f282017-04-04 18:00:23 -0500776 # We need to purge error logs between boots or they build up.
Michael Walshb5839d02017-04-12 16:11:20 -0500777 grk.run_key("Delete Error logs", ignore=1)
Michael Walshd139f282017-04-04 18:00:23 -0500778
Michael Walsh952f9b02017-03-09 13:11:14 -0600779 boot_results.print_report()
Michael Walshb5839d02017-04-12 16:11:20 -0500780 gp.qprint_timen("Finished boot " + str(boot_count) + ".")
Michael Walsh952f9b02017-03-09 13:11:14 -0600781
Michael Walsh6741f742017-02-20 16:16:38 -0600782 plug_in_setup()
783 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
784 call_point='stop_check')
785 if rc != 0:
786 error_message = "Stopping as requested by user.\n"
787 grp.rprint_error_report(error_message)
788 BuiltIn().fail(error_message)
789
Michael Walshd139f282017-04-04 18:00:23 -0500790 # This should help prevent ConnectionErrors.
Michael Walshb5839d02017-04-12 16:11:20 -0500791 grk.run_key_u("Delete All Sessions")
Michael Walshd139f282017-04-04 18:00:23 -0500792
Michael Walsh6741f742017-02-20 16:16:38 -0600793 return True
794
795###############################################################################
796
797
798###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500799def obmc_boot_test_teardown():
Michael Walsh6741f742017-02-20 16:16:38 -0600800
801 r"""
Michael Walshc9116812017-03-10 14:23:06 -0600802 Clean up after the Main keyword.
Michael Walsh6741f742017-02-20 16:16:38 -0600803 """
804
805 if cp_setup_called:
806 plug_in_setup()
807 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
808 call_point='cleanup', stop_on_plug_in_failure=1)
809
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600810 # Save boot_results object to a file in case it is needed again.
Michael Walshb5839d02017-04-12 16:11:20 -0500811 gp.qprint_timen("Saving boot_results to the following path.")
812 gp.qprint_var(boot_results_file_path)
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600813 pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
814 pickle.HIGHEST_PROTOCOL)
815
Michael Walsh6741f742017-02-20 16:16:38 -0600816###############################################################################
817
818
819###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600820def test_teardown():
821
822 r"""
823 Clean up after this test case.
824 """
825
826 gp.qprintn()
827 cmd_buf = ["Print Error",
828 "A keyword timeout occurred ending this program.\n"]
829 BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf)
830
Michael Walshb5839d02017-04-12 16:11:20 -0500831 grp.rqprint_pgm_footer()
832
Michael Walshc9116812017-03-10 14:23:06 -0600833###############################################################################
834
835
836###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500837def obmc_boot_test_py(alt_boot_stack=None):
Michael Walsh6741f742017-02-20 16:16:38 -0600838
839 r"""
840 Do main program processing.
841 """
842
Michael Walshb5839d02017-04-12 16:11:20 -0500843 if alt_boot_stack is not None:
844 BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack)
845
Michael Walsh6741f742017-02-20 16:16:38 -0600846 setup()
847
Michael Walsha20da402017-03-31 16:27:45 -0500848 if ffdc_only:
849 gp.qprint_timen("Caller requested ffdc_only.")
Michael Walsh83f4bc72017-04-20 16:49:43 -0500850 grk.run_key_u("my_ffdc")
Michael Walsh764d2f82017-04-27 16:01:08 -0500851 return
Michael Walsha20da402017-03-31 16:27:45 -0500852
Michael Walsh6741f742017-02-20 16:16:38 -0600853 # Process caller's boot_stack.
854 while (len(boot_stack) > 0):
855 test_loop_body()
856
Michael Walshb5839d02017-04-12 16:11:20 -0500857 gp.qprint_timen("Finished processing stack.")
Michael Walsh30dadae2017-02-27 14:25:52 -0600858
Michael Walsh6741f742017-02-20 16:16:38 -0600859 # Process caller's boot_list.
860 if len(boot_list) > 0:
861 for ix in range(1, max_num_tests + 1):
862 test_loop_body()
863
Michael Walshb5839d02017-04-12 16:11:20 -0500864 gp.qprint_timen("Completed all requested boot tests.")
865
866 boot_pass, boot_fail = boot_results.return_total_pass_fail()
867 if boot_fail > boot_fail_threshold:
868 error_message = "Boot failures exceed the boot failure" +\
869 " threshold:\n" +\
870 gp.sprint_var(boot_fail) +\
871 gp.sprint_var(boot_fail_threshold)
872 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600873
874###############################################################################