blob: 578e7eba2baa3778dab0ae57d0ab14efee66c6bc [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 Walshff340002017-08-29 11:18:27 -050028import var_stack as vs
Michael Walsh0bbd8602016-11-22 11:31:49 -060029
Michael Walsh0b93fbf2017-03-02 14:42:41 -060030base_path = os.path.dirname(os.path.dirname(
31 imp.find_module("gen_robot_print")[1])) +\
Michael Walshc9116812017-03-10 14:23:06 -060032 os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060033sys.path.append(base_path + "extended/")
34import run_keyword as rk
Michael Walsh0bbd8602016-11-22 11:31:49 -060035
Michael Walshe1e26442017-03-06 17:50:07 -060036# Setting master_pid correctly influences the behavior of plug-ins like
37# DB_Logging
38program_pid = os.getpid()
39master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid)
Michael Walsh903e0b22017-09-19 17:00:33 -050040pgm_name = re.sub('\.py$', '', os.path.basename(__file__))
Michael Walshe1e26442017-03-06 17:50:07 -060041
Michael Walshb5839d02017-04-12 16:11:20 -050042# Set up boot data structures.
43boot_table = create_boot_table()
44valid_boot_types = create_valid_boot_list(boot_table)
Michael Walsh0b93fbf2017-03-02 14:42:41 -060045
Michael Walsh6741f742017-02-20 16:16:38 -060046boot_lists = read_boot_lists()
47last_ten = []
Michael Walsh6741f742017-02-20 16:16:38 -060048
49state = st.return_default_state()
50cp_setup_called = 0
51next_boot = ""
52base_tool_dir_path = os.path.normpath(os.environ.get(
53 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep
Michael Walshb5839d02017-04-12 16:11:20 -050054
Michael Walsh6741f742017-02-20 16:16:38 -060055ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep
Michael Walsh6741f742017-02-20 16:16:38 -060056boot_success = 0
Michael Walsh6741f742017-02-20 16:16:38 -060057status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
58if status_dir_path != "":
59 status_dir_path = os.path.normpath(status_dir_path) + os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060060default_power_on = "REST Power On"
61default_power_off = "REST Power Off"
Michael Walsh6741f742017-02-20 16:16:38 -060062boot_count = 0
Michael Walsh0bbd8602016-11-22 11:31:49 -060063
Michael Walsh85678942017-03-27 14:34:22 -050064LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}")
Michael Walshe1974b92017-08-03 13:39:51 -050065ffdc_prefix = ""
Sunil M325eb542017-08-10 07:09:43 -050066boot_start_time = ""
67boot_end_time = ""
Michael Walshff340002017-08-29 11:18:27 -050068save_stack = vs.var_stack('save_stack')
69main_func_parm_list = ['boot_stack', 'stack_mode', 'quiet']
Michael Walsh85678942017-03-27 14:34:22 -050070
71
72###############################################################################
Michael Walsh0ad0f7f2017-05-04 14:39:58 -050073def process_host(host,
74 host_var_name=""):
75
76 r"""
77 Process a host by getting the associated host name and IP address and
78 setting them in global variables.
79
80 If the caller does not pass the host_var_name, this function will try to
81 figure out the name of the variable used by the caller for the host parm.
82 Callers are advised to explicitly specify the host_var_name when calling
83 with an exec command. In such cases, the get_arg_name cannot figure out
84 the host variable name.
85
86 This function will then create similar global variable names by
87 removing "_host" and appending "_host_name" or "_ip" to the host variable
88 name.
89
90 Example:
91
92 If a call is made like this:
93 process_host(openbmc_host)
94
95 Global variables openbmc_host_name and openbmc_ip will be set.
96
97 Description of argument(s):
98 host A host name or IP. The name of the variable used should
99 have a suffix of "_host".
100 host_var_name The name of the variable being used as the host parm.
101 """
102
103 if host_var_name == "":
104 host_var_name = gp.get_arg_name(0, 1, stack_frame_ix=2)
105
106 host_name_var_name = re.sub("host", "host_name", host_var_name)
107 ip_var_name = re.sub("host", "ip", host_var_name)
108 cmd_buf = "global " + host_name_var_name + ", " + ip_var_name + " ; " +\
109 host_name_var_name + ", " + ip_var_name + " = gm.get_host_name_ip('" +\
110 host + "')"
111 exec(cmd_buf)
112
113###############################################################################
114
115
116###############################################################################
Michael Walshb5839d02017-04-12 16:11:20 -0500117def process_pgm_parms():
118
119 r"""
120 Process the program parameters by assigning them all to corresponding
121 globals. Also, set some global values that depend on program parameters.
122 """
123
124 # Program parameter processing.
125 # Assign all program parms to python variables which are global to this
126 # module.
127
128 global parm_list
129 parm_list = BuiltIn().get_variable_value("${parm_list}")
130 # The following subset of parms should be processed as integers.
131 int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only',
132 'boot_fail_threshold', 'quiet', 'test_mode', 'debug']
133 for parm in parm_list:
134 if parm in int_list:
135 sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\
136 "}\", \"0\"))"
137 else:
138 sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")"
139 cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd
Michael Walshff340002017-08-29 11:18:27 -0500140 gp.dpissuing(cmd_buf)
Michael Walshb5839d02017-04-12 16:11:20 -0500141 exec(cmd_buf)
Michael Walsh0ad0f7f2017-05-04 14:39:58 -0500142 if re.match(r".*_host$", parm):
143 cmd_buf = "process_host(" + parm + ", '" + parm + "')"
144 exec(cmd_buf)
145 if re.match(r".*_password$", parm):
146 # Register the value of any parm whose name ends in _password.
147 # This will cause the print functions to replace passwords with
148 # asterisks in the output.
149 cmd_buf = "gp.register_passwords(" + parm + ")"
150 exec(cmd_buf)
Michael Walshb5839d02017-04-12 16:11:20 -0500151
152 global ffdc_dir_path_style
153 global boot_list
154 global boot_stack
155 global boot_results_file_path
156 global boot_results
157 global ffdc_list_file_path
Michael Walshe0cf8d72017-05-17 13:20:46 -0500158 global ffdc_report_list_path
Michael Walsh600876d2017-05-30 17:58:58 -0500159 global ffdc_summary_list_path
Michael Walshb5839d02017-04-12 16:11:20 -0500160
161 if ffdc_dir_path_style == "":
162 ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0'))
163
164 # Convert these program parms to lists for easier processing..
165 boot_list = filter(None, boot_list.split(":"))
166 boot_stack = filter(None, boot_stack.split(":"))
167
Michael Walsh903e0b22017-09-19 17:00:33 -0500168 cleanup_boot_results_file()
169 boot_results_file_path = create_boot_results_file_path(pgm_name,
170 openbmc_nickname,
171 master_pid)
Michael Walshb5839d02017-04-12 16:11:20 -0500172
173 if os.path.isfile(boot_results_file_path):
174 # We've been called before in this run so we'll load the saved
175 # boot_results object.
176 boot_results = pickle.load(open(boot_results_file_path, 'rb'))
177 else:
178 boot_results = boot_results(boot_table, boot_pass, boot_fail)
179
180 ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\
181 "/FFDC_FILE_LIST"
Michael Walshe0cf8d72017-05-17 13:20:46 -0500182 ffdc_report_list_path = base_tool_dir_path + openbmc_nickname +\
183 "/FFDC_REPORT_FILE_LIST"
Michael Walshb5839d02017-04-12 16:11:20 -0500184
Michael Walsh600876d2017-05-30 17:58:58 -0500185 ffdc_summary_list_path = base_tool_dir_path + openbmc_nickname +\
186 "/FFDC_SUMMARY_FILE_LIST"
187
Michael Walshb5839d02017-04-12 16:11:20 -0500188###############################################################################
189
190
191###############################################################################
Michael Walsh85678942017-03-27 14:34:22 -0500192def initial_plug_in_setup():
193
194 r"""
195 Initialize all plug-in environment variables which do not change for the
196 duration of the program.
197
198 """
199
200 global LOG_LEVEL
201 BuiltIn().set_log_level("NONE")
202
203 BuiltIn().set_global_variable("${master_pid}", master_pid)
204 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
205 BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path)
206 BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path)
207 BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}",
208 ffdc_list_file_path)
Michael Walshe0cf8d72017-05-17 13:20:46 -0500209 BuiltIn().set_global_variable("${FFDC_REPORT_LIST_PATH}",
210 ffdc_report_list_path)
Michael Walsh600876d2017-05-30 17:58:58 -0500211 BuiltIn().set_global_variable("${FFDC_SUMMARY_LIST_PATH}",
212 ffdc_summary_list_path)
Michael Walsh85678942017-03-27 14:34:22 -0500213
214 BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}",
215 ffdc_dir_path_style)
216 BuiltIn().set_global_variable("${FFDC_CHECK}",
217 ffdc_check)
218
219 # For each program parameter, set the corresponding AUTOBOOT_ environment
220 # variable value. Also, set an AUTOBOOT_ environment variable for every
221 # element in additional_values.
222 additional_values = ["program_pid", "master_pid", "ffdc_dir_path",
223 "status_dir_path", "base_tool_dir_path",
Michael Walsh600876d2017-05-30 17:58:58 -0500224 "ffdc_list_file_path", "ffdc_report_list_path",
225 "ffdc_summary_list_path"]
Michael Walsh85678942017-03-27 14:34:22 -0500226
227 plug_in_vars = parm_list + additional_values
228
229 for var_name in plug_in_vars:
230 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
231 var_name = var_name.upper()
232 if var_value is None:
233 var_value = ""
234 os.environ["AUTOBOOT_" + var_name] = str(var_value)
235
236 BuiltIn().set_log_level(LOG_LEVEL)
237
Michael Walsh68a61162017-04-25 11:54:06 -0500238 # Make sure the ffdc list directory exists.
239 ffdc_list_dir_path = os.path.dirname(ffdc_list_file_path) + os.sep
240 if not os.path.exists(ffdc_list_dir_path):
241 os.makedirs(ffdc_list_dir_path)
Michael Walsh85678942017-03-27 14:34:22 -0500242
243###############################################################################
244
Michael Walsh0bbd8602016-11-22 11:31:49 -0600245
246###############################################################################
Michael Walsh0bbd8602016-11-22 11:31:49 -0600247def plug_in_setup():
248
249 r"""
Michael Walsh85678942017-03-27 14:34:22 -0500250 Initialize all changing plug-in environment variables for use by the
251 plug-in programs.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600252 """
253
Michael Walsh85678942017-03-27 14:34:22 -0500254 global LOG_LEVEL
255 global test_really_running
256
257 BuiltIn().set_log_level("NONE")
258
Michael Walsh6741f742017-02-20 16:16:38 -0600259 boot_pass, boot_fail = boot_results.return_total_pass_fail()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600260 if boot_pass > 1:
261 test_really_running = 1
262 else:
263 test_really_running = 0
264
Michael Walsh6741f742017-02-20 16:16:38 -0600265 BuiltIn().set_global_variable("${test_really_running}",
266 test_really_running)
267 BuiltIn().set_global_variable("${boot_type_desc}", next_boot)
Michael Walsh6741f742017-02-20 16:16:38 -0600268 BuiltIn().set_global_variable("${boot_pass}", boot_pass)
269 BuiltIn().set_global_variable("${boot_fail}", boot_fail)
270 BuiltIn().set_global_variable("${boot_success}", boot_success)
271 BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix)
Sunil M325eb542017-08-10 07:09:43 -0500272 BuiltIn().set_global_variable("${boot_start_time}", boot_start_time)
273 BuiltIn().set_global_variable("${boot_end_time}", boot_end_time)
Michael Walsh4c9a6452016-12-13 16:03:11 -0600274
Michael Walsh0bbd8602016-11-22 11:31:49 -0600275 # For each program parameter, set the corresponding AUTOBOOT_ environment
276 # variable value. Also, set an AUTOBOOT_ environment variable for every
277 # element in additional_values.
278 additional_values = ["boot_type_desc", "boot_success", "boot_pass",
Sunil M325eb542017-08-10 07:09:43 -0500279 "boot_fail", "test_really_running", "ffdc_prefix",
280 "boot_start_time", "boot_end_time"]
Michael Walsh0bbd8602016-11-22 11:31:49 -0600281
Michael Walsh85678942017-03-27 14:34:22 -0500282 plug_in_vars = additional_values
Michael Walsh0bbd8602016-11-22 11:31:49 -0600283
284 for var_name in plug_in_vars:
285 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
286 var_name = var_name.upper()
287 if var_value is None:
288 var_value = ""
Michael Walsh6741f742017-02-20 16:16:38 -0600289 os.environ["AUTOBOOT_" + var_name] = str(var_value)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600290
Michael Walsh0bbd8602016-11-22 11:31:49 -0600291 if debug:
Michael Walsh6741f742017-02-20 16:16:38 -0600292 shell_rc, out_buf = \
293 gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600294
Michael Walsh85678942017-03-27 14:34:22 -0500295 BuiltIn().set_log_level(LOG_LEVEL)
296
Michael Walsh0bbd8602016-11-22 11:31:49 -0600297###############################################################################
298
299
300###############################################################################
Michael Walshe0cf8d72017-05-17 13:20:46 -0500301def pre_boot_plug_in_setup():
302
303 # Clear the ffdc_list_file_path file. Plug-ins may now write to it.
304 try:
305 os.remove(ffdc_list_file_path)
306 except OSError:
307 pass
308
309 # Clear the ffdc_report_list_path file. Plug-ins may now write to it.
310 try:
311 os.remove(ffdc_report_list_path)
312 except OSError:
313 pass
314
Michael Walsh600876d2017-05-30 17:58:58 -0500315 # Clear the ffdc_summary_list_path file. Plug-ins may now write to it.
316 try:
317 os.remove(ffdc_summary_list_path)
318 except OSError:
319 pass
320
Michael Walshe1974b92017-08-03 13:39:51 -0500321 global ffdc_prefix
322
323 seconds = time.time()
324 loc_time = time.localtime(seconds)
325 time_string = time.strftime("%y%m%d.%H%M%S.", loc_time)
326
327 ffdc_prefix = openbmc_nickname + "." + time_string
328
Michael Walshe0cf8d72017-05-17 13:20:46 -0500329###############################################################################
330
331
332###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600333def setup():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600334
335 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600336 Do general program setup tasks.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600337 """
338
Michael Walsh6741f742017-02-20 16:16:38 -0600339 global cp_setup_called
Michael Walsh0bbd8602016-11-22 11:31:49 -0600340
Michael Walshb5839d02017-04-12 16:11:20 -0500341 gp.qprintn()
342
Michael Walsh83f4bc72017-04-20 16:49:43 -0500343 robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
344 repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/")
Michael Walshd061c042017-05-23 14:46:57 -0500345 # If we can't find process_plug_in_packages.py, ssh_pw or
346 # validate_plug_ins.py, then we don't have our repo bin in PATH.
347 shell_rc, out_buf = gc.cmd_fnc_u("which process_plug_in_packages.py" +
348 " ssh_pw validate_plug_ins.py", quiet=1,
349 print_output=0, show_err=0)
Michael Walshb5839d02017-04-12 16:11:20 -0500350 if shell_rc != 0:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500351 os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "")
352 # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH.
353 if robot_pgm_dir_path not in sys.path:
354 sys.path.append(robot_pgm_dir_path)
355 PYTHONPATH = os.environ.get("PYTHONPATH", "")
356 if PYTHONPATH == "":
357 os.environ['PYTHONPATH'] = robot_pgm_dir_path
358 else:
359 os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH
Michael Walsh6741f742017-02-20 16:16:38 -0600360
361 validate_parms()
362
363 grp.rqprint_pgm_header()
364
Michael Walshfdc5ced2017-08-17 13:15:15 -0500365 grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE")
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500366
Michael Walsh85678942017-03-27 14:34:22 -0500367 initial_plug_in_setup()
368
Michael Walsh6741f742017-02-20 16:16:38 -0600369 plug_in_setup()
370 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
371 call_point='setup')
372 if rc != 0:
373 error_message = "Plug-in setup failed.\n"
374 grp.rprint_error_report(error_message)
375 BuiltIn().fail(error_message)
376 # Setting cp_setup_called lets our Teardown know that it needs to call
377 # the cleanup plug-in call point.
378 cp_setup_called = 1
379
380 # Keyword "FFDC" will fail if TEST_MESSAGE is not set.
381 BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}")
Michael Walsh85678942017-03-27 14:34:22 -0500382 # FFDC_LOG_PATH is used by "FFDC" keyword.
383 BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
Michael Walsh6741f742017-02-20 16:16:38 -0600384
Michael Walshdc80d672017-05-09 12:58:32 -0500385 # Also printed by FFDC.
386 global host_name
387 global host_ip
388 host = socket.gethostname()
389 host_name, host_ip = gm.get_host_name_ip(host)
390
Michael Walshb5839d02017-04-12 16:11:20 -0500391 gp.dprint_var(boot_table, 1)
392 gp.dprint_var(boot_lists)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600393
394###############################################################################
395
396
397###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600398def validate_parms():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600399
400 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600401 Validate all program parameters.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600402 """
403
Michael Walshb5839d02017-04-12 16:11:20 -0500404 process_pgm_parms()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600405
Michael Walshb5839d02017-04-12 16:11:20 -0500406 gp.qprintn()
407
408 global openbmc_model
Michael Walsh6741f742017-02-20 16:16:38 -0600409 grv.rvalid_value("openbmc_host")
410 grv.rvalid_value("openbmc_username")
411 grv.rvalid_value("openbmc_password")
412 if os_host != "":
413 grv.rvalid_value("os_username")
414 grv.rvalid_value("os_password")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600415
Michael Walsh6741f742017-02-20 16:16:38 -0600416 if pdu_host != "":
417 grv.rvalid_value("pdu_username")
418 grv.rvalid_value("pdu_password")
Michael Walsh85678942017-03-27 14:34:22 -0500419 grv.rvalid_integer("pdu_slot_no")
Michael Walsh6741f742017-02-20 16:16:38 -0600420 if openbmc_serial_host != "":
421 grv.rvalid_integer("openbmc_serial_port")
Michael Walshb5839d02017-04-12 16:11:20 -0500422 if openbmc_model == "":
423 status, ret_values =\
424 grk.run_key_u("Get BMC System Model")
425 openbmc_model = ret_values
426 BuiltIn().set_global_variable("${openbmc_model}", openbmc_model)
Michael Walsh6741f742017-02-20 16:16:38 -0600427 grv.rvalid_value("openbmc_model")
Michael Walshb5839d02017-04-12 16:11:20 -0500428 grv.rvalid_integer("max_num_tests")
Michael Walsh6741f742017-02-20 16:16:38 -0600429 grv.rvalid_integer("boot_pass")
430 grv.rvalid_integer("boot_fail")
431
432 plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths)
433 BuiltIn().set_global_variable("${plug_in_packages_list}",
434 plug_in_packages_list)
435
Michael Walshb5839d02017-04-12 16:11:20 -0500436 grv.rvalid_value("stack_mode", valid_values=['normal', 'skip'])
Michael Walsha20da402017-03-31 16:27:45 -0500437 if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only:
Michael Walsh6741f742017-02-20 16:16:38 -0600438 error_message = "You must provide either a value for either the" +\
439 " boot_list or the boot_stack parm.\n"
440 BuiltIn().fail(gp.sprint_error(error_message))
441
442 valid_boot_list(boot_list, valid_boot_types)
443 valid_boot_list(boot_stack, valid_boot_types)
444
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500445 selected_PDU_boots = list(set(boot_list + boot_stack) &
446 set(boot_lists['PDU_reboot']))
447
448 if len(selected_PDU_boots) > 0 and pdu_host == "":
449 error_message = "You have selected the following boots which" +\
450 " require a PDU host but no value for pdu_host:\n"
451 error_message += gp.sprint_var(selected_PDU_boots)
452 error_message += gp.sprint_var(pdu_host, 2)
453 BuiltIn().fail(gp.sprint_error(error_message))
454
Michael Walsh6741f742017-02-20 16:16:38 -0600455 return
Michael Walsh0bbd8602016-11-22 11:31:49 -0600456
457###############################################################################
458
459
460###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600461def my_get_state():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600462
463 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600464 Get the system state plus a little bit of wrapping.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600465 """
466
Michael Walsh6741f742017-02-20 16:16:38 -0600467 global state
468
469 req_states = ['epoch_seconds'] + st.default_req_states
470
Michael Walshb5839d02017-04-12 16:11:20 -0500471 gp.qprint_timen("Getting system state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600472 if test_mode:
473 state['epoch_seconds'] = int(time.time())
474 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500475 state = st.get_state(req_states=req_states, quiet=quiet)
476 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600477
478###############################################################################
479
480
481###############################################################################
Michael Walsh45ca6e42017-09-14 17:29:12 -0500482def valid_state():
483
484 r"""
485 Verify that our state dictionary contains no blank values. If we don't get
486 valid state data, we cannot continue to work.
487 """
488
489 if st.compare_states(state, st.invalid_state_match, 'or'):
490 error_message = "The state dictionary contains blank fields which" +\
491 " is illegal.\n" + gp.sprint_var(state)
492 BuiltIn().fail(gp.sprint_error(error_message))
493
494###############################################################################
495
496
497###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600498def select_boot():
Michael Walsh341c21e2017-01-17 16:25:20 -0600499
500 r"""
501 Select a boot test to be run based on our current state and return the
502 chosen boot type.
503
504 Description of arguments:
Michael Walsh6741f742017-02-20 16:16:38 -0600505 state The state of the machine.
Michael Walsh341c21e2017-01-17 16:25:20 -0600506 """
507
Michael Walsh30dadae2017-02-27 14:25:52 -0600508 global boot_stack
509
Michael Walshb5839d02017-04-12 16:11:20 -0500510 gp.qprint_timen("Selecting a boot test.")
Michael Walsh6741f742017-02-20 16:16:38 -0600511
512 my_get_state()
Michael Walsh45ca6e42017-09-14 17:29:12 -0500513 valid_state()
Michael Walsh6741f742017-02-20 16:16:38 -0600514
515 stack_popped = 0
516 if len(boot_stack) > 0:
517 stack_popped = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500518 gp.qprint_dashes()
519 gp.qprint_var(boot_stack)
520 gp.qprint_dashes()
521 skip_boot_printed = 0
522 while len(boot_stack) > 0:
523 boot_candidate = boot_stack.pop()
524 if stack_mode == 'normal':
525 break
526 else:
527 if st.compare_states(state, boot_table[boot_candidate]['end']):
528 if not skip_boot_printed:
Michael Walshff340002017-08-29 11:18:27 -0500529 gp.qprint_var(stack_mode)
530 gp.qprintn()
531 gp.qprint_timen("Skipping the following boot tests" +
532 " which are unnecessary since their" +
533 " required end states match the" +
534 " current machine state:")
Michael Walshb5839d02017-04-12 16:11:20 -0500535 skip_boot_printed = 1
Michael Walshff340002017-08-29 11:18:27 -0500536 gp.qprint_var(boot_candidate)
Michael Walshb5839d02017-04-12 16:11:20 -0500537 boot_candidate = ""
538 if boot_candidate == "":
539 gp.qprint_dashes()
540 gp.qprint_var(boot_stack)
541 gp.qprint_dashes()
542 return boot_candidate
Michael Walsh6741f742017-02-20 16:16:38 -0600543 if st.compare_states(state, boot_table[boot_candidate]['start']):
Michael Walshb5839d02017-04-12 16:11:20 -0500544 gp.qprint_timen("The machine state is valid for a '" +
545 boot_candidate + "' boot test.")
546 gp.qprint_dashes()
547 gp.qprint_var(boot_stack)
548 gp.qprint_dashes()
Michael Walsh6741f742017-02-20 16:16:38 -0600549 return boot_candidate
Michael Walsh341c21e2017-01-17 16:25:20 -0600550 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500551 gp.qprint_timen("The machine state does not match the required" +
552 " starting state for a '" + boot_candidate +
553 "' boot test:")
Michael Walshff340002017-08-29 11:18:27 -0500554 gp.qprint_varx("boot_table[" + boot_candidate + "][start]",
555 boot_table[boot_candidate]['start'], 1)
Michael Walsh6741f742017-02-20 16:16:38 -0600556 boot_stack.append(boot_candidate)
557 popped_boot = boot_candidate
558
559 # Loop through your list selecting a boot_candidates
560 boot_candidates = []
561 for boot_candidate in boot_list:
562 if st.compare_states(state, boot_table[boot_candidate]['start']):
563 if stack_popped:
564 if st.compare_states(boot_table[boot_candidate]['end'],
565 boot_table[popped_boot]['start']):
566 boot_candidates.append(boot_candidate)
567 else:
568 boot_candidates.append(boot_candidate)
569
570 if len(boot_candidates) == 0:
Michael Walshb5839d02017-04-12 16:11:20 -0500571 gp.qprint_timen("The user's boot list contained no boot tests" +
572 " which are valid for the current machine state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600573 boot_candidate = default_power_on
574 if not st.compare_states(state, boot_table[default_power_on]['start']):
575 boot_candidate = default_power_off
576 boot_candidates.append(boot_candidate)
Michael Walshb5839d02017-04-12 16:11:20 -0500577 gp.qprint_timen("Using default '" + boot_candidate +
578 "' boot type to transition to valid state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600579
Michael Walshb5839d02017-04-12 16:11:20 -0500580 gp.dprint_var(boot_candidates)
Michael Walsh6741f742017-02-20 16:16:38 -0600581
582 # Randomly select a boot from the candidate list.
583 boot = random.choice(boot_candidates)
Michael Walsh341c21e2017-01-17 16:25:20 -0600584
585 return boot
Michael Walsh0bbd8602016-11-22 11:31:49 -0600586
587###############################################################################
Michael Walsh55302292017-01-10 11:43:02 -0600588
589
590###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600591def print_last_boots():
592
593 r"""
594 Print the last ten boots done with their time stamps.
595 """
596
597 # indent 0, 90 chars wide, linefeed, char is "="
Michael Walshb5839d02017-04-12 16:11:20 -0500598 gp.qprint_dashes(0, 90)
599 gp.qprintn("Last 10 boots:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600600
601 for boot_entry in last_ten:
602 grp.rqprint(boot_entry)
Michael Walshb5839d02017-04-12 16:11:20 -0500603 gp.qprint_dashes(0, 90)
Michael Walsh341c21e2017-01-17 16:25:20 -0600604
605###############################################################################
606
607
608###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600609def print_defect_report():
610
611 r"""
612 Print a defect report.
613 """
614
Michael Walsh600876d2017-05-30 17:58:58 -0500615 # Making deliberate choice to NOT run plug_in_setup(). We don't want
616 # ffdc_prefix updated.
617 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
618 call_point='ffdc_report', stop_on_plug_in_failure=0)
619
Michael Walsh341c21e2017-01-17 16:25:20 -0600620 # At some point I'd like to have the 'Call FFDC Methods' return a list
621 # of files it has collected. In that case, the following "ls" command
622 # would no longer be needed. For now, however, glob shows the files
623 # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
624 # out (so we don't see duplicates in the list).
625
Michael Walshe0cf8d72017-05-17 13:20:46 -0500626 # Get additional header data which may have been created by ffdc plug-ins.
627 # Also, delete the individual header files to cleanup.
628 cmd_buf = "file_list=$(cat " + ffdc_report_list_path + " 2>/dev/null)" +\
629 " ; [ ! -z \"${file_list}\" ] && cat ${file_list}" +\
630 " 2>/dev/null ; rm -rf ${file_list} 2>/dev/null || :"
631 shell_rc, more_header_info = gc.cmd_fnc_u(cmd_buf, print_output=0,
632 show_err=0)
633
Michael Walsh600876d2017-05-30 17:58:58 -0500634 # Get additional header data which may have been created by ffdc plug-ins.
635 # Also, delete the individual header files to cleanup.
636 cmd_buf = "file_list=$(cat " + ffdc_summary_list_path + " 2>/dev/null)" +\
637 " ; [ ! -z \"${file_list}\" ] && cat ${file_list}" +\
638 " 2>/dev/null ; rm -rf ${file_list} 2>/dev/null || :"
639 shell_rc, ffdc_summary_info = gc.cmd_fnc_u(cmd_buf, print_output=0,
640 show_err=0)
641
Michael Walsh341c21e2017-01-17 16:25:20 -0600642 LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}")
643
Michael Walshe0cf8d72017-05-17 13:20:46 -0500644 output = '\n'.join(sorted(glob.glob(LOG_PREFIX + '*')))
Michael Walsh341c21e2017-01-17 16:25:20 -0600645 try:
Michael Walsh6741f742017-02-20 16:16:38 -0600646 ffdc_list = open(ffdc_list_file_path, 'r')
Michael Walsh341c21e2017-01-17 16:25:20 -0600647 except IOError:
648 ffdc_list = ""
649
Michael Walsh68a61162017-04-25 11:54:06 -0500650 # Open ffdc_file_list for writing. We will write a complete list of
651 # FFDC files to it for possible use by plug-ins like cp_stop_check.
652 ffdc_list_file = open(ffdc_list_file_path, 'w')
653
654 gp.qprintn()
655 # indent=0, width=90, linefeed=1, char="="
656 gp.qprint_dashes(0, 90, 1, "=")
657 gp.qprintn("Copy this data to the defect:\n")
658
Michael Walshe0cf8d72017-05-17 13:20:46 -0500659 if len(more_header_info) > 0:
Michael Walshff340002017-08-29 11:18:27 -0500660 gp.qprintn(more_header_info)
Michael Walshdc80d672017-05-09 12:58:32 -0500661 gp.qpvars(host_name, host_ip, openbmc_nickname, openbmc_host,
662 openbmc_host_name, openbmc_ip, openbmc_username,
663 openbmc_password, os_host, os_host_name, os_ip, os_username,
664 os_password, pdu_host, pdu_host_name, pdu_ip, pdu_username,
665 pdu_password, pdu_slot_no, openbmc_serial_host,
666 openbmc_serial_host_name, openbmc_serial_ip, openbmc_serial_port)
Michael Walsh68a61162017-04-25 11:54:06 -0500667
668 gp.qprintn()
669
670 print_last_boots()
671 gp.qprintn()
672 gp.qprint_var(state)
673
Michael Walshb5839d02017-04-12 16:11:20 -0500674 gp.qprintn()
675 gp.qprintn("FFDC data files:")
Michael Walsh341c21e2017-01-17 16:25:20 -0600676 if status_file_path != "":
Michael Walshb5839d02017-04-12 16:11:20 -0500677 gp.qprintn(status_file_path)
Michael Walsh68a61162017-04-25 11:54:06 -0500678 ffdc_list_file.write(status_file_path + "\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600679
Michael Walshb5839d02017-04-12 16:11:20 -0500680 gp.qprintn(output)
681 # gp.qprintn(ffdc_list)
682 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600683
Michael Walsh600876d2017-05-30 17:58:58 -0500684 if len(ffdc_summary_info) > 0:
Michael Walshff340002017-08-29 11:18:27 -0500685 gp.qprintn(ffdc_summary_info)
Michael Walsh600876d2017-05-30 17:58:58 -0500686
Michael Walshb5839d02017-04-12 16:11:20 -0500687 gp.qprint_dashes(0, 90, 1, "=")
Michael Walsh341c21e2017-01-17 16:25:20 -0600688
Michael Walsh68a61162017-04-25 11:54:06 -0500689 ffdc_list_file.write(output + "\n")
690 ffdc_list_file.close()
691
Michael Walsh341c21e2017-01-17 16:25:20 -0600692###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600693
694
695###############################################################################
696def my_ffdc():
697
698 r"""
699 Collect FFDC data.
700 """
701
702 global state
703
704 plug_in_setup()
705 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
Michael Walsh600876d2017-05-30 17:58:58 -0500706 call_point='ffdc', stop_on_plug_in_failure=0)
Michael Walsh6741f742017-02-20 16:16:38 -0600707
708 AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
Michael Walsh83f4bc72017-04-20 16:49:43 -0500709 status, ret_values = grk.run_key_u("FFDC ffdc_prefix=" +
710 AUTOBOOT_FFDC_PREFIX +
711 " ffdc_function_list=" +
712 ffdc_function_list, ignore=1)
713 if status != 'PASS':
Michael Walshff340002017-08-29 11:18:27 -0500714 gp.qprint_error("Call to ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600715
716 my_get_state()
717
718 print_defect_report()
719
720###############################################################################
721
722
723###############################################################################
724def print_test_start_message(boot_keyword):
725
726 r"""
727 Print a message indicating what boot test is about to run.
728
729 Description of arguments:
730 boot_keyword The name of the boot which is to be run
731 (e.g. "BMC Power On").
732 """
733
734 global last_ten
Sunil M325eb542017-08-10 07:09:43 -0500735 global boot_start_time
Michael Walsh6741f742017-02-20 16:16:38 -0600736
737 doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".")
Sunil M325eb542017-08-10 07:09:43 -0500738
739 # Set boot_start_time for use by plug-ins.
740 boot_start_time = doing_msg[1:33]
741 gp.qprint_var(boot_start_time)
742
Michael Walshb5839d02017-04-12 16:11:20 -0500743 gp.qprint(doing_msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600744
745 last_ten.append(doing_msg)
746
747 if len(last_ten) > 10:
748 del last_ten[0]
749
750###############################################################################
751
752
753###############################################################################
754def run_boot(boot):
755
756 r"""
757 Run the specified boot.
758
759 Description of arguments:
760 boot The name of the boot test to be performed.
761 """
762
763 global state
764
765 print_test_start_message(boot)
766
767 plug_in_setup()
768 rc, shell_rc, failed_plug_in_name = \
769 grpi.rprocess_plug_in_packages(call_point="pre_boot")
770 if rc != 0:
771 error_message = "Plug-in failed with non-zero return code.\n" +\
772 gp.sprint_var(rc, 1)
773 BuiltIn().fail(gp.sprint_error(error_message))
774
775 if test_mode:
776 # In test mode, we'll pretend the boot worked by assigning its
777 # required end state to the default state value.
Michael Walsh30dadae2017-02-27 14:25:52 -0600778 state = st.strip_anchor_state(boot_table[boot]['end'])
Michael Walsh6741f742017-02-20 16:16:38 -0600779 else:
780 # Assertion: We trust that the state data was made fresh by the
781 # caller.
782
Michael Walshb5839d02017-04-12 16:11:20 -0500783 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600784
785 if boot_table[boot]['method_type'] == "keyword":
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600786 rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
Michael Walshb5839d02017-04-12 16:11:20 -0500787 boot_table[boot]['method'],
788 quiet=quiet)
Michael Walsh6741f742017-02-20 16:16:38 -0600789
790 if boot_table[boot]['bmc_reboot']:
791 st.wait_for_comm_cycle(int(state['epoch_seconds']))
Michael Walsh30dadae2017-02-27 14:25:52 -0600792 plug_in_setup()
793 rc, shell_rc, failed_plug_in_name = \
794 grpi.rprocess_plug_in_packages(call_point="post_reboot")
795 if rc != 0:
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600796 error_message = "Plug-in failed with non-zero return code.\n"
797 error_message += gp.sprint_var(rc, 1)
Michael Walsh30dadae2017-02-27 14:25:52 -0600798 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600799 else:
800 match_state = st.anchor_state(state)
801 del match_state['epoch_seconds']
802 # Wait for the state to change in any way.
803 st.wait_state(match_state, wait_time=state_change_timeout,
Michael Walsh600876d2017-05-30 17:58:58 -0500804 interval="10 seconds", invert=1)
Michael Walsh6741f742017-02-20 16:16:38 -0600805
Michael Walshb5839d02017-04-12 16:11:20 -0500806 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600807 if boot_table[boot]['end']['chassis'] == "Off":
808 boot_timeout = power_off_timeout
809 else:
810 boot_timeout = power_on_timeout
811 st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
Michael Walsh600876d2017-05-30 17:58:58 -0500812 interval="10 seconds")
Michael Walsh6741f742017-02-20 16:16:38 -0600813
814 plug_in_setup()
815 rc, shell_rc, failed_plug_in_name = \
816 grpi.rprocess_plug_in_packages(call_point="post_boot")
817 if rc != 0:
818 error_message = "Plug-in failed with non-zero return code.\n" +\
819 gp.sprint_var(rc, 1)
820 BuiltIn().fail(gp.sprint_error(error_message))
821
822###############################################################################
823
824
825###############################################################################
826def test_loop_body():
827
828 r"""
829 The main loop body for the loop in main_py.
830
831 Description of arguments:
832 boot_count The iteration number (starts at 1).
833 """
834
835 global boot_count
836 global state
837 global next_boot
838 global boot_success
Sunil M325eb542017-08-10 07:09:43 -0500839 global boot_end_time
Michael Walsh6741f742017-02-20 16:16:38 -0600840
Michael Walshb5839d02017-04-12 16:11:20 -0500841 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600842
843 next_boot = select_boot()
Michael Walshb5839d02017-04-12 16:11:20 -0500844 if next_boot == "":
845 return True
Michael Walsh6741f742017-02-20 16:16:38 -0600846
Michael Walshb5839d02017-04-12 16:11:20 -0500847 boot_count += 1
848 gp.qprint_timen("Starting boot " + str(boot_count) + ".")
Michael Walsh6741f742017-02-20 16:16:38 -0600849
Michael Walshe0cf8d72017-05-17 13:20:46 -0500850 pre_boot_plug_in_setup()
Michael Walsh6741f742017-02-20 16:16:38 -0600851
852 cmd_buf = ["run_boot", next_boot]
853 boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
854 if boot_status == "FAIL":
Michael Walshb5839d02017-04-12 16:11:20 -0500855 gp.qprint(msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600856
Michael Walshb5839d02017-04-12 16:11:20 -0500857 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600858 if boot_status == "PASS":
859 boot_success = 1
Michael Walshff340002017-08-29 11:18:27 -0500860 completion_msg = gp.sprint_timen("BOOT_SUCCESS: \"" + next_boot +
861 "\" succeeded.")
Michael Walsh6741f742017-02-20 16:16:38 -0600862 else:
863 boot_success = 0
Michael Walshff340002017-08-29 11:18:27 -0500864 completion_msg = gp.sprint_timen("BOOT_FAILED: \"" + next_boot +
865 "\" failed.")
Sunil M325eb542017-08-10 07:09:43 -0500866
867 # Set boot_end_time for use by plug-ins.
868 boot_end_time = completion_msg[1:33]
869 gp.qprint_var(boot_end_time)
870
871 gp.qprint(completion_msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600872
873 boot_results.update(next_boot, boot_status)
874
875 plug_in_setup()
876 # NOTE: A post_test_case call point failure is NOT counted as a boot
877 # failure.
878 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
Michael Walsh600876d2017-05-30 17:58:58 -0500879 call_point='post_test_case', stop_on_plug_in_failure=0)
Michael Walsh6741f742017-02-20 16:16:38 -0600880
881 plug_in_setup()
882 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
883 call_point='ffdc_check', shell_rc=0x00000200,
884 stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
885 if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500886 status, ret_values = grk.run_key_u("my_ffdc", ignore=1)
887 if status != 'PASS':
Michael Walshff340002017-08-29 11:18:27 -0500888 gp.qprint_error("Call to my_ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600889
Michael Walshd139f282017-04-04 18:00:23 -0500890 # We need to purge error logs between boots or they build up.
Michael Walshb5839d02017-04-12 16:11:20 -0500891 grk.run_key("Delete Error logs", ignore=1)
Michael Walshd139f282017-04-04 18:00:23 -0500892
Michael Walsh952f9b02017-03-09 13:11:14 -0600893 boot_results.print_report()
Michael Walshb5839d02017-04-12 16:11:20 -0500894 gp.qprint_timen("Finished boot " + str(boot_count) + ".")
Michael Walsh952f9b02017-03-09 13:11:14 -0600895
Michael Walsh6741f742017-02-20 16:16:38 -0600896 plug_in_setup()
897 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
898 call_point='stop_check')
899 if rc != 0:
900 error_message = "Stopping as requested by user.\n"
901 grp.rprint_error_report(error_message)
902 BuiltIn().fail(error_message)
903
Michael Walshd139f282017-04-04 18:00:23 -0500904 # This should help prevent ConnectionErrors.
Michael Walsh0960b382017-06-22 16:23:37 -0500905 grk.run_key_u("Close All Connections")
Michael Walshd139f282017-04-04 18:00:23 -0500906
Michael Walsh6741f742017-02-20 16:16:38 -0600907 return True
908
909###############################################################################
910
911
912###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500913def obmc_boot_test_teardown():
Michael Walsh6741f742017-02-20 16:16:38 -0600914
915 r"""
Michael Walshc9116812017-03-10 14:23:06 -0600916 Clean up after the Main keyword.
Michael Walsh6741f742017-02-20 16:16:38 -0600917 """
918
919 if cp_setup_called:
920 plug_in_setup()
921 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
Michael Walsh600876d2017-05-30 17:58:58 -0500922 call_point='cleanup', stop_on_plug_in_failure=0)
Michael Walsh6741f742017-02-20 16:16:38 -0600923
Michael Walsh600876d2017-05-30 17:58:58 -0500924 if 'boot_results_file_path' in globals():
925 # Save boot_results object to a file in case it is needed again.
926 gp.qprint_timen("Saving boot_results to the following path.")
927 gp.qprint_var(boot_results_file_path)
928 pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
929 pickle.HIGHEST_PROTOCOL)
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600930
Michael Walshff340002017-08-29 11:18:27 -0500931 global save_stack
932 # Restore any global values saved on the save_stack.
933 for parm_name in main_func_parm_list:
934 # Get the parm_value if it was saved on the stack.
935 try:
936 parm_value = save_stack.pop(parm_name)
937 except:
938 # If it was not saved, no further action is required.
939 continue
940
941 # Restore the saved value.
942 cmd_buf = "BuiltIn().set_global_variable(\"${" + parm_name +\
943 "}\", parm_value)"
944 gp.dpissuing(cmd_buf)
945 exec(cmd_buf)
946
947 gp.dprintn(save_stack.sprint_obj())
948
Michael Walsh6741f742017-02-20 16:16:38 -0600949###############################################################################
950
951
952###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600953def test_teardown():
954
955 r"""
956 Clean up after this test case.
957 """
958
959 gp.qprintn()
960 cmd_buf = ["Print Error",
961 "A keyword timeout occurred ending this program.\n"]
962 BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf)
963
Michael Walshb5839d02017-04-12 16:11:20 -0500964 grp.rqprint_pgm_footer()
965
Michael Walshc9116812017-03-10 14:23:06 -0600966###############################################################################
967
968
969###############################################################################
Michael Walshff340002017-08-29 11:18:27 -0500970def obmc_boot_test_py(loc_boot_stack=None,
971 loc_stack_mode=None,
972 loc_quiet=None):
Michael Walsh6741f742017-02-20 16:16:38 -0600973
974 r"""
975 Do main program processing.
976 """
977
Michael Walshff340002017-08-29 11:18:27 -0500978 global save_stack
979
980 # Process function parms.
981 for parm_name in main_func_parm_list:
982 # Get parm's value.
983 cmd_buf = "parm_value = loc_" + parm_name
984 exec(cmd_buf)
985 gp.dpvar(parm_name)
986 gp.dpvar(parm_value)
987
988 if parm_value is None:
989 # Parm was not specified by the calling function so set it to its
990 # corresponding global value.
991 cmd_buf = "loc_" + parm_name + " = BuiltIn().get_variable_value" +\
992 "(\"${" + parm_name + "}\")"
993 gp.dpissuing(cmd_buf)
994 exec(cmd_buf)
995 else:
996 # Save the global value on a stack.
997 cmd_buf = "save_stack.push(BuiltIn().get_variable_value(\"${" +\
998 parm_name + "}\"), \"" + parm_name + "\")"
999 gp.dpissuing(cmd_buf)
1000 exec(cmd_buf)
1001
1002 # Set the global value to the passed value.
1003 cmd_buf = "BuiltIn().set_global_variable(\"${" + parm_name +\
1004 "}\", loc_" + parm_name + ")"
1005 gp.dpissuing(cmd_buf)
1006 exec(cmd_buf)
1007
1008 gp.dprintn(save_stack.sprint_obj())
Michael Walshb5839d02017-04-12 16:11:20 -05001009
Michael Walsh6741f742017-02-20 16:16:38 -06001010 setup()
1011
Michael Walshcd9fbfd2017-09-19 12:00:08 -05001012 init_boot_pass, init_boot_fail = boot_results.return_total_pass_fail()
1013
Michael Walsha20da402017-03-31 16:27:45 -05001014 if ffdc_only:
1015 gp.qprint_timen("Caller requested ffdc_only.")
Michael Walshe0cf8d72017-05-17 13:20:46 -05001016 pre_boot_plug_in_setup()
Michael Walsh83f4bc72017-04-20 16:49:43 -05001017 grk.run_key_u("my_ffdc")
Michael Walsh764d2f82017-04-27 16:01:08 -05001018 return
Michael Walsha20da402017-03-31 16:27:45 -05001019
Michael Walsh6741f742017-02-20 16:16:38 -06001020 # Process caller's boot_stack.
1021 while (len(boot_stack) > 0):
1022 test_loop_body()
1023
Michael Walshb5839d02017-04-12 16:11:20 -05001024 gp.qprint_timen("Finished processing stack.")
Michael Walsh30dadae2017-02-27 14:25:52 -06001025
Michael Walsh6741f742017-02-20 16:16:38 -06001026 # Process caller's boot_list.
1027 if len(boot_list) > 0:
1028 for ix in range(1, max_num_tests + 1):
1029 test_loop_body()
1030
Michael Walshb5839d02017-04-12 16:11:20 -05001031 gp.qprint_timen("Completed all requested boot tests.")
1032
1033 boot_pass, boot_fail = boot_results.return_total_pass_fail()
Michael Walshcd9fbfd2017-09-19 12:00:08 -05001034 new_fail = boot_fail - init_boot_fail
1035 if new_fail > boot_fail_threshold:
Michael Walshb5839d02017-04-12 16:11:20 -05001036 error_message = "Boot failures exceed the boot failure" +\
1037 " threshold:\n" +\
Michael Walshcd9fbfd2017-09-19 12:00:08 -05001038 gp.sprint_var(new_fail) +\
Michael Walshb5839d02017-04-12 16:11:20 -05001039 gp.sprint_var(boot_fail_threshold)
1040 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -06001041
1042###############################################################################